PIRL  PIRL++

Public Member Functions

PIRL::Rectangle Struct Reference

A Rectangle is a position with a size. More...

#include <Dimensions.hh>

Inheritance diagram for PIRL::Rectangle:
Inheritance graph
[legend]
Collaboration diagram for PIRL::Rectangle:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Rectangle ()
 Constructs an empty Rectangle.
 Rectangle (const Coordinate_Type x, const Coordinate_Type y, const Dimensions_Type width=0, const Dimensions_Type height=0)
 Constructs a Rectangle from an x,y position and width,height size.
 Rectangle (const Point_2D &position, const Size_2D &size)
 Constructs a Rectangle from a position and a size.
 Rectangle (const Size_2D &size)
 Constructs a Rectangle from a size at position 0,0.
 Rectangle (const Rectangle &rectangle)
 Constructs a Rectangle as a copy of another Rectangle.
Rectangleposition (const Coordinate_Type &x, const Coordinate_Type &y)
 Set the position of this Rectangle.
Rectangleposition (const Point_2D &point)
 Set the position of this Rectangle.
Rectangleoperator= (const Point_2D &point)
 Assign the position of the Rectangle from a Point_2D.
Point_2D position () const
 Get the Rectangle position.
 operator Point_2D () const
 Convert the Rectangle to its corresponding Point_2D.
Rectanglesize (const Dimensions_Type &width, const Dimensions_Type &height)
 Set the size of this Rectangle.
Rectanglesize (const Size_2D &size)
 Set the size of this Rectangle.
Rectangleoperator= (const Size_2D &size)
 Assign the size of the Rectangle from a Size_2D.
Size_2D size () const
 Get the Rectangle size.
 operator Size_2D () const
 Convert the Rectangle to its corresponding Size_2D.
Rectangleoperator= (const Rectangle &rectangle)
 Assign the position and size of another Rectangle to this Rectangle.
bool operator== (const Rectangle &rectangle) const
 Test if this Rectangle is equal to another Rectangle.
bool operator!= (const Rectangle &rectangle) const
 Test if this Rectangle is not equal to another Rectangle.
 operator bool ()
 Test for all zero dimension values.
Rectangleoperator+= (const Point_2D &offset)
 Add an offset.
Rectangleoperator+= (const Size_2D &size)
 Add a size amount.
Rectangleoperator+= (const Rectangle &rectangle)
 Add another Rectangle's point coordinate offset and size amount.
Rectangleoperator-= (const Point_2D &offset)
 Subtract an offset.
Rectangleoperator-= (const Size_2D &size)
 Subtract a size amount.
Rectangleoperator-= (const Rectangle &rectangle)
 Subtract another Rectangle's point coordinate offset and size amount.
Rectangleoperator*= (double factor)
 Multiply by a factor.
Rectangleoperator/= (double factor)
 Divide by a factor.
Rectangleoperator&= (const Rectangle &rectangle)
 Take the intersection with another Rectangle.
Rectangleoperator|= (const Rectangle &rectangle)
 Take the union with another Rectangle.

Detailed Description

A Rectangle is a position with a size.

The Rectangle's position is based in a Point_2D being at the upper left corner of the Rectangle, and its size is based in a Size_2D with the X-axis Width increasing to the right and the Y-axis Height increasing downward (raster order).

Author:
Bradford Castalia, UA/PIRL
Version:
Revision:
1.27
See also:
Point_2D
Size_2D

Constructor & Destructor Documentation

PIRL::Rectangle::Rectangle (  )

Constructs an empty Rectangle.

The position is 0,0 and the size is 0,0.

PIRL::Rectangle::Rectangle ( const Coordinate_Type  x,
const Coordinate_Type  y,
const Dimensions_Type  width = 0,
const Dimensions_Type  height = 0 
)

Constructs a Rectangle from an x,y position and width,height size.

Parameters:
xThe horizontal (x-axis) position.
yThe vertical (y-axis) position.
widthThe Width of the Rectangle.
heightThe Height of the Rectangle.
PIRL::Rectangle::Rectangle ( const Point_2D position,
const Size_2D size 
)

Constructs a Rectangle from a position and a size.

Parameters:
positionA Point_2D.
sizeA Size_2D.
PIRL::Rectangle::Rectangle ( const Size_2D size )

Constructs a Rectangle from a size at position 0,0.

Parameters:
sizeA Size_2D.
PIRL::Rectangle::Rectangle ( const Rectangle rectangle )

Constructs a Rectangle as a copy of another Rectangle.

Parameters:
rectangleA Rectangle to be copied.

Member Function Documentation

Rectangle& PIRL::Rectangle::position ( const Coordinate_Type x,
const Coordinate_Type y 
) [inline]

Set the position of this Rectangle.

Parameters:
xThe horizontal (x-axis) position of the Rectangle.
yThe vertical (y-axis) position of the Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

References position().

Rectangle& PIRL::Rectangle::position ( const Point_2D point ) [inline]

Set the position of this Rectangle.

Parameters:
pointA Point_2D whose dimensions are to be assigned to this Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

References position().

Rectangle& PIRL::Rectangle::operator= ( const Point_2D point ) [inline]

Assign the position of the Rectangle from a Point_2D.

Parameters:
pointA Point_2D for the position of the Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

Referenced by operator=().

Point_2D PIRL::Rectangle::position (  ) const [inline]

Get the Rectangle position.

Returns:
A Point_2D with the Rectangle position. N.B.: Changing this Point_2D will not change the position of the Rectangle.

References PIRL::Point_2D::Point_2D(), PIRL::Point_2D::X, and PIRL::Point_2D::Y.

Referenced by operator Point_2D(), PIRL::Cube::position(), and position().

PIRL::Rectangle::operator Point_2D (  ) const [inline]

Convert the Rectangle to its corresponding Point_2D.

Returns:
A Point_2D with the Rectangle position.

References position().

Rectangle& PIRL::Rectangle::size ( const Dimensions_Type width,
const Dimensions_Type height 
) [inline]

Set the size of this Rectangle.

Parameters:
widthThe Width of the Rectangle.
heightThe Height of the Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Size_2D.

Reimplemented in PIRL::Cube.

References size().

Rectangle& PIRL::Rectangle::size ( const Size_2D size ) [inline]

Set the size of this Rectangle.

Parameters:
sizeA Size_2D to have its dimensions assigned to this Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Size_2D.

Reimplemented in PIRL::Cube.

References size().

Rectangle& PIRL::Rectangle::operator= ( const Size_2D size ) [inline]

Assign the size of the Rectangle from a Size_2D.

Parameters:
sizeA Size_2D for the size of the Rectangle.
Returns:
This Rectangle.

Reimplemented from PIRL::Size_2D.

Reimplemented in PIRL::Cube.

References operator=().

Size_2D PIRL::Rectangle::size (  ) const [inline]

Get the Rectangle size.

Returns:
A Size_2D with the Rectangle size. N.B.: Changing this size will not change the size of the Rectangle.

References PIRL::Size_2D::Height, PIRL::Size_2D::Size_2D(), and PIRL::Size_2D::Width.

Referenced by operator Size_2D(), PIRL::Cube::size(), and size().

PIRL::Rectangle::operator Size_2D (  ) const [inline]

Convert the Rectangle to its corresponding Size_2D.

Returns:
A Size_2D with the Rectangle size.

References size().

Rectangle& PIRL::Rectangle::operator= ( const Rectangle rectangle ) [inline]

Assign the position and size of another Rectangle to this Rectangle.

Parameters:
rectangleA Rectangle whose position and size are to be assigned to this Rectangle.
Returns:
This Rectangle.

Reimplemented in PIRL::Cube.

References PIRL::Size_2D::Height, PIRL::Size_2D::Width, PIRL::Point_2D::X, and PIRL::Point_2D::Y.

bool PIRL::Rectangle::operator== ( const Rectangle rectangle ) const [inline]

Test if this Rectangle is equal to another Rectangle.

The two Rectangles are equal if both their position and size dimensions are equal.

Parameters:
rectangleThe Rectangle to which this Rectangle is to be compared.
Returns:
true if the two Rectangles are equal; false otherwise.
bool PIRL::Rectangle::operator!= ( const Rectangle rectangle ) const [inline]

Test if this Rectangle is not equal to another Rectangle.

The two Rectangles are not equal if either their position or size dimensions are not equal.

Parameters:
rectangleThe Rectangle to which this Rectangle is to be compared.
Returns:
true if the two Rectangles are not equal; false otherwise.
PIRL::Rectangle::operator bool (  ) [inline]

Test for all zero dimension values.

Returns:
true if any dimension value is non-zero; false otherwise.

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

Rectangle& PIRL::Rectangle::operator+= ( const Point_2D offset ) [inline]

Add an offset.

Parameters:
offsetA Point_2D that provides the offset values.
Returns:
This Rectangle with its values offset.

Reimplemented from PIRL::Point_2D.

Referenced by operator+=().

Rectangle& PIRL::Rectangle::operator+= ( const Size_2D size ) [inline]

Add a size amount.

Parameters:
sizeA Size_2D that provides the amount values.
Returns:
This Rectangle with the amount added to its size values.

Reimplemented from PIRL::Size_2D.

References operator+=().

Rectangle& PIRL::Rectangle::operator+= ( const Rectangle rectangle ) [inline]

Add another Rectangle's point coordinate offset and size amount.

Parameters:
rectangleA Rectangle.
Returns:
This Rectangle with its point coordinate offset by the other Rectangle's point coordinate values, and the other Rectangle's size amount added to its size dimensions.

References operator+=().

Rectangle& PIRL::Rectangle::operator-= ( const Point_2D offset ) [inline]

Subtract an offset.

Parameters:
offsetA Point_2D that provides the offset values.
Returns:
This Rectangle with its values offset.

Reimplemented from PIRL::Point_2D.

Referenced by operator-=().

Rectangle& PIRL::Rectangle::operator-= ( const Size_2D size ) [inline]

Subtract a size amount.

N.B.: If the size Dimensions_Type values are an unsigned type (as they are by default) and a size amount to be subtracted is greater than the corresponding dimension value, the result will be zero.

Parameters:
sizeA Size_2D that provides the amount values.
Returns:
This Rectangle with the amount subtracted to its values.

Reimplemented from PIRL::Size_2D.

References operator-=().

Rectangle& PIRL::Rectangle::operator-= ( const Rectangle rectangle ) [inline]

Subtract another Rectangle's point coordinate offset and size amount.

Parameters:
rectangleA Rectangle.
Returns:
This Rectangle with its point coordinate offset by the other Rectangle's point coordinate values, and the other Rectangle's size amount subtracted from its size dimensions.

References operator-=().

Rectangle& PIRL::Rectangle::operator*= ( double  factor ) [inline]

Multiply by a factor.

The new size values will be rounded to the nearest Dimensions_Types.

Parameters:
factorA factor by which to multiply the Size_2D dimensions.
Returns:
This Rectangle with its values changed.
Exceptions:
invalid_argumentIf the factor is negative and the size values Dimensions_Type are an unsigned type (as they are by default).

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

Rectangle& PIRL::Rectangle::operator/= ( double  factor ) [inline]

Divide by a factor.

The new size dimensions will be rounded to the nearest Dimensions_Type values.

N.B.: Divide by zero is handled as a special case. If the coordinate value was zero it will remain zero. If the Dimensions_Type has an infinity value (determined by numeric_types) that is used, or its negative if the coordinate value is negative. Otherwise, if the Dimensions_Type is signed the type's max value is used, or the min value if the coordinate value is negative; for an unsigned value the max value is used.

Parameters:
factorA factor by which to divide the Size_2D dimensions.
Returns:
This Rectangle with its values changed.
Exceptions:
invalid_argumentIf the factor is negative and the size values Dimensions_Type are an unsigned type (as they are by default).

Reimplemented from PIRL::Point_2D.

Reimplemented in PIRL::Cube.

Referenced by PIRL::Cube::operator/=().

Rectangle & PIRL::Rectangle::operator&= ( const Rectangle rectangle )

Take the intersection with another Rectangle.

The intersection of two Rectangles is the overlapping area of both.

Parameters:
rectangleThe Rectangle to intersect with this Rectangle.
Returns:
This Rectangle with its position and size set to the intersection with the other Rectangle. If the Rectangles do not intersect this will result in a Rectangle with no area (Width and Height both zero) but the position will be unchanged.

References PIRL::Size_2D::Height, PIRL::Size_2D::Width, PIRL::Point_2D::X, and PIRL::Point_2D::Y.

Referenced by PIRL::Cube::operator&=().

Rectangle & PIRL::Rectangle::operator|= ( const Rectangle rectangle )

Take the union with another Rectangle.

The union of two Rectangles is the bounding area of both.

Parameters:
rectangleThe Rectangle to unite with this Rectangle.
Returns:
This Rectangle with its position and size set to the union - i.e. the bounding box - with the other Rectangle.

References PIRL::Size_2D::Height, PIRL::Size_2D::Width, PIRL::Point_2D::X, and PIRL::Point_2D::Y.

Referenced by PIRL::Cube::operator|=().


The documentation for this struct was generated from the following files: