Manages a rectangle and allows geometric operations to be performed on it. More...
Public Member Functions | |
| Rectangle () throw () | |
| Creates a rectangle of zero size. | |
| Rectangle (const Rectangle &other) throw () | |
| Creates a copy of another rectangle. | |
| Rectangle (const ValueType initialX, const ValueType initialY, const ValueType width, const ValueType height) throw () | |
| Creates a rectangle with a given position and size. | |
| Rectangle (const ValueType width, const ValueType height) throw () | |
| Creates a rectangle with a given size, and a position of (0, 0). | |
| Rectangle (const Point< ValueType > &corner1, const Point< ValueType > &corner2) throw () | |
| Creates a Rectangle from the positions of two opposite corners. | |
| Rectangle & | operator= (const Rectangle &other) throw () |
| ~Rectangle () throw () | |
| Destructor. | |
| bool | isEmpty () const throw () |
| Returns true if the rectangle's width and height are both zero or less. | |
| ValueType | getX () const throw () |
| Returns the x co-ordinate of the rectangle's left-hand-side. | |
| ValueType | getY () const throw () |
| Returns the y co-ordinate of the rectangle's top edge. | |
| ValueType | getWidth () const throw () |
| Returns the width of the rectangle. | |
| ValueType | getHeight () const throw () |
| Returns the height of the rectangle. | |
| ValueType | getRight () const throw () |
| Returns the x co-ordinate of the rectangle's right-hand-side. | |
| ValueType | getBottom () const throw () |
| Returns the y co-ordinate of the rectangle's bottom edge. | |
| ValueType | getCentreX () const throw () |
| Returns the x co-ordinate of the rectangle's centre. | |
| ValueType | getCentreY () const throw () |
| Returns the y co-ordinate of the rectangle's centre. | |
| const Point< ValueType > | getCentre () const throw () |
| Returns the centre point of the rectangle. | |
| ValueType | getAspectRatio (const bool widthOverHeight=true) const throw () |
| Returns the aspect ratio of the rectangle's width / height. | |
| const Point< ValueType > | getPosition () const throw () |
| Returns the rectangle's top-left position as a Point. | |
| void | setPosition (const Point< ValueType > &newPos) throw () |
| Changes the position of the rectangle's top-left corner (leaving its size unchanged). | |
| void | setPosition (const ValueType newX, const ValueType newY) throw () |
| Changes the position of the rectangle's top-left corner (leaving its size unchanged). | |
| const Rectangle | withPosition (const Point< ValueType > &newPos) const throw () |
| Returns a rectangle with the same size as this one, but a new position. | |
| void | setSize (const ValueType newWidth, const ValueType newHeight) throw () |
| Changes the rectangle's size, leaving the position of its top-left corner unchanged. | |
| const Rectangle | withSize (const ValueType newWidth, const ValueType newHeight) const throw () |
| Returns a rectangle with the same position as this one, but a new size. | |
| void | setBounds (const ValueType newX, const ValueType newY, const ValueType newWidth, const ValueType newHeight) throw () |
| Changes all the rectangle's co-ordinates. | |
| void | setWidth (const ValueType newWidth) throw () |
| Changes the rectangle's width. | |
| void | setHeight (const ValueType newHeight) throw () |
| Changes the rectangle's height. | |
| void | setLeft (const ValueType newLeft) throw () |
| Moves the x position, adjusting the width so that the right-hand edge remains in the same place. | |
| void | setTop (const ValueType newTop) throw () |
| Moves the y position, adjusting the height so that the bottom edge remains in the same place. | |
| void | setRight (const ValueType newRight) throw () |
| Adjusts the width so that the right-hand edge of the rectangle has this new value. | |
| void | setBottom (const ValueType newBottom) throw () |
| Adjusts the height so that the bottom edge of the rectangle has this new value. | |
| void | translate (const ValueType deltaX, const ValueType deltaY) throw () |
| Moves the rectangle's position by adding amount to its x and y co-ordinates. | |
| const Rectangle | translated (const ValueType deltaX, const ValueType deltaY) const throw () |
| Returns a rectangle which is the same as this one moved by a given amount. | |
| const Rectangle | operator+ (const Point< ValueType > &deltaPosition) const throw () |
| Returns a rectangle which is the same as this one moved by a given amount. | |
| const Rectangle | operator- (const Point< ValueType > &deltaPosition) const throw () |
| Returns a rectangle which is the same as this one moved by a given amount. | |
| void | expand (const ValueType deltaX, const ValueType deltaY) throw () |
| Expands the rectangle by a given amount. | |
| const Rectangle | expanded (const ValueType deltaX, const ValueType deltaY) const throw () |
| Returns a rectangle that is larger than this one by a given amount. | |
| void | reduce (const ValueType deltaX, const ValueType deltaY) throw () |
| Shrinks the rectangle by a given amount. | |
| const Rectangle | reduced (const ValueType deltaX, const ValueType deltaY) const throw () |
| Returns a rectangle that is smaller than this one by a given amount. | |
| bool | operator== (const Rectangle &other) const throw () |
| Returns true if the two rectangles are identical. | |
| bool | operator!= (const Rectangle &other) const throw () |
| Returns true if the two rectangles are not identical. | |
| bool | contains (const ValueType xCoord, const ValueType yCoord) const throw () |
| Returns true if this co-ordinate is inside the rectangle. | |
| bool | contains (const Point< ValueType > &point) const throw () |
| Returns true if this co-ordinate is inside the rectangle. | |
| bool | contains (const Rectangle &other) const throw () |
| Returns true if this other rectangle is completely inside this one. | |
| const Point< ValueType > | getConstrainedPoint (const Point< ValueType > &point) const throw () |
| Returns the nearest point to the specified point that lies within this rectangle. | |
| bool | intersects (const Rectangle &other) const throw () |
| Returns true if any part of another rectangle overlaps this one. | |
| const Rectangle | getIntersection (const Rectangle &other) const throw () |
| Returns the region that is the overlap between this and another rectangle. | |
| bool | intersectRectangle (ValueType &otherX, ValueType &otherY, ValueType &otherW, ValueType &otherH) const throw () |
| Clips a rectangle so that it lies only within this one. | |
| const Rectangle | getUnion (const Rectangle &other) const throw () |
| Returns the smallest rectangle that contains both this one and the one passed-in. | |
| bool | enlargeIfAdjacent (const Rectangle &other) throw () |
| If this rectangle merged with another one results in a simple rectangle, this will set this rectangle to the result, and return true. | |
| bool | reduceIfPartlyContainedIn (const Rectangle &other) throw () |
| If after removing another rectangle from this one the result is a simple rectangle, this will set this object's bounds to be the result, and return true. | |
| const Rectangle< ValueType > | transformed (const AffineTransform &transform) const throw () |
| Returns the smallest rectangle that can contain the shape created by applying a transform to this rectangle. | |
| const Rectangle< int > | getSmallestIntegerContainer () const throw () |
| Returns the smallest integer-aligned rectangle that completely contains this one. | |
| const Rectangle< float > | toFloat () const throw () |
| Casts this rectangle to a Rectangle<float>. | |
| const String | toString () const |
| Creates a string describing this rectangle. | |
Static Public Member Functions | |
| static bool | intersectRectangles (ValueType &x1, ValueType &y1, ValueType &w1, ValueType &h1, const ValueType x2, const ValueType y2, const ValueType w2, const ValueType h2) throw () |
| Static utility to intersect two sets of rectangular co-ordinates. | |
| static const Rectangle | fromString (const String &stringVersion) |
| Parses a string containing a rectangle's details. | |
Manages a rectangle and allows geometric operations to be performed on it.
Creates a rectangle of zero size.
The default co-ordinates will be (0, 0, 0, 0).
Referenced by Rectangle< int >::expanded(), Rectangle< int >::fromString(), Rectangle< int >::getIntersection(), Rectangle< int >::getUnion(), Rectangle< int >::operator+(), Rectangle< int >::operator-(), Rectangle< int >::transformed(), Rectangle< int >::translated(), Rectangle< int >::withPosition(), and Rectangle< int >::withSize().
| Rectangle< ValueType >::Rectangle | ( | const Rectangle< ValueType > & | other | ) | throw () |
Creates a copy of another rectangle.
| Rectangle< ValueType >::Rectangle | ( | const ValueType | initialX, | |
| const ValueType | initialY, | |||
| const ValueType | width, | |||
| const ValueType | height | |||
| ) | throw () |
Creates a rectangle with a given position and size.
| Rectangle< ValueType >::Rectangle | ( | const ValueType | width, | |
| const ValueType | height | |||
| ) | throw () |
Creates a rectangle with a given size, and a position of (0, 0).
| Rectangle< ValueType >::Rectangle | ( | const Point< ValueType > & | corner1, | |
| const Point< ValueType > & | corner2 | |||
| ) | throw () |
Creates a Rectangle from the positions of two opposite corners.
| Rectangle& Rectangle< ValueType >::operator= | ( | const Rectangle< ValueType > & | other | ) | throw () |
| bool Rectangle< ValueType >::isEmpty | ( | ) | const throw () |
Returns true if the rectangle's width and height are both zero or less.
| ValueType Rectangle< ValueType >::getX | ( | ) | const throw () |
Returns the x co-ordinate of the rectangle's left-hand-side.
| ValueType Rectangle< ValueType >::getY | ( | ) | const throw () |
Returns the y co-ordinate of the rectangle's top edge.
| ValueType Rectangle< ValueType >::getWidth | ( | ) | const throw () |
Returns the width of the rectangle.
| ValueType Rectangle< ValueType >::getHeight | ( | ) | const throw () |
Returns the height of the rectangle.
| ValueType Rectangle< ValueType >::getRight | ( | ) | const throw () |
Returns the x co-ordinate of the rectangle's right-hand-side.
Referenced by Rectangle< int >::enlargeIfAdjacent().
| ValueType Rectangle< ValueType >::getBottom | ( | ) | const throw () |
Returns the y co-ordinate of the rectangle's bottom edge.
Referenced by Rectangle< int >::enlargeIfAdjacent().
| ValueType Rectangle< ValueType >::getCentreX | ( | ) | const throw () |
Returns the x co-ordinate of the rectangle's centre.
| ValueType Rectangle< ValueType >::getCentreY | ( | ) | const throw () |
Returns the y co-ordinate of the rectangle's centre.
| const Point<ValueType> Rectangle< ValueType >::getCentre | ( | ) | const throw () |
Returns the centre point of the rectangle.
| ValueType Rectangle< ValueType >::getAspectRatio | ( | const bool | widthOverHeight = true |
) | const throw () |
Returns the aspect ratio of the rectangle's width / height.
If widthOverHeight is true, it returns width / height; if widthOverHeight is false, it returns height / width.
| const Point<ValueType> Rectangle< ValueType >::getPosition | ( | ) | const throw () |
Returns the rectangle's top-left position as a Point.
| void Rectangle< ValueType >::setPosition | ( | const Point< ValueType > & | newPos | ) | throw () |
Changes the position of the rectangle's top-left corner (leaving its size unchanged).
| void Rectangle< ValueType >::setPosition | ( | const ValueType | newX, | |
| const ValueType | newY | |||
| ) | throw () |
Changes the position of the rectangle's top-left corner (leaving its size unchanged).
| const Rectangle Rectangle< ValueType >::withPosition | ( | const Point< ValueType > & | newPos | ) | const throw () |
Returns a rectangle with the same size as this one, but a new position.
| void Rectangle< ValueType >::setSize | ( | const ValueType | newWidth, | |
| const ValueType | newHeight | |||
| ) | throw () |
Changes the rectangle's size, leaving the position of its top-left corner unchanged.
| const Rectangle Rectangle< ValueType >::withSize | ( | const ValueType | newWidth, | |
| const ValueType | newHeight | |||
| ) | const throw () |
Returns a rectangle with the same position as this one, but a new size.
| void Rectangle< ValueType >::setBounds | ( | const ValueType | newX, | |
| const ValueType | newY, | |||
| const ValueType | newWidth, | |||
| const ValueType | newHeight | |||
| ) | throw () |
Changes all the rectangle's co-ordinates.
Referenced by Rectangle< int >::expand().
| void Rectangle< ValueType >::setWidth | ( | const ValueType | newWidth | ) | throw () |
Changes the rectangle's width.
| void Rectangle< ValueType >::setHeight | ( | const ValueType | newHeight | ) | throw () |
Changes the rectangle's height.
| void Rectangle< ValueType >::setLeft | ( | const ValueType | newLeft | ) | throw () |
Moves the x position, adjusting the width so that the right-hand edge remains in the same place.
If the x is moved to be on the right of the current right-hand edge, the width will be set to zero.
| void Rectangle< ValueType >::setTop | ( | const ValueType | newTop | ) | throw () |
Moves the y position, adjusting the height so that the bottom edge remains in the same place.
If the y is moved to be below the current bottom edge, the height will be set to zero.
| void Rectangle< ValueType >::setRight | ( | const ValueType | newRight | ) | throw () |
Adjusts the width so that the right-hand edge of the rectangle has this new value.
If the new right is below the current X value, the X will be pushed down to match it.
| void Rectangle< ValueType >::setBottom | ( | const ValueType | newBottom | ) | throw () |
Adjusts the height so that the bottom edge of the rectangle has this new value.
If the new bottom is lower than the current Y value, the Y will be pushed down to match it.
| void Rectangle< ValueType >::translate | ( | const ValueType | deltaX, | |
| const ValueType | deltaY | |||
| ) | throw () |
Moves the rectangle's position by adding amount to its x and y co-ordinates.
| const Rectangle Rectangle< ValueType >::translated | ( | const ValueType | deltaX, | |
| const ValueType | deltaY | |||
| ) | const throw () |
Returns a rectangle which is the same as this one moved by a given amount.
| const Rectangle Rectangle< ValueType >::operator+ | ( | const Point< ValueType > & | deltaPosition | ) | const throw () |
Returns a rectangle which is the same as this one moved by a given amount.
| const Rectangle Rectangle< ValueType >::operator- | ( | const Point< ValueType > & | deltaPosition | ) | const throw () |
Returns a rectangle which is the same as this one moved by a given amount.
| void Rectangle< ValueType >::expand | ( | const ValueType | deltaX, | |
| const ValueType | deltaY | |||
| ) | throw () |
Expands the rectangle by a given amount.
Effectively, its new size is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2).
Referenced by Rectangle< int >::reduce().
| const Rectangle Rectangle< ValueType >::expanded | ( | const ValueType | deltaX, | |
| const ValueType | deltaY | |||
| ) | const throw () |
Returns a rectangle that is larger than this one by a given amount.
Effectively, the rectangle returned is (x - deltaX, y - deltaY, w + deltaX * 2, h + deltaY * 2).
Referenced by Rectangle< int >::reduced().
| void Rectangle< ValueType >::reduce | ( | const ValueType | deltaX, | |
| const ValueType | deltaY | |||
| ) | throw () |
| bool Rectangle< ValueType >::operator== | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns true if the two rectangles are identical.
| bool Rectangle< ValueType >::operator!= | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns true if the two rectangles are not identical.
| bool Rectangle< ValueType >::contains | ( | const ValueType | xCoord, | |
| const ValueType | yCoord | |||
| ) | const throw () |
Returns true if this co-ordinate is inside the rectangle.
| bool Rectangle< ValueType >::contains | ( | const Point< ValueType > & | point | ) | const throw () |
Returns true if this co-ordinate is inside the rectangle.
| bool Rectangle< ValueType >::contains | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns true if this other rectangle is completely inside this one.
| const Point<ValueType> Rectangle< ValueType >::getConstrainedPoint | ( | const Point< ValueType > & | point | ) | const throw () |
Returns the nearest point to the specified point that lies within this rectangle.
| bool Rectangle< ValueType >::intersects | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns true if any part of another rectangle overlaps this one.
| const Rectangle Rectangle< ValueType >::getIntersection | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns the region that is the overlap between this and another rectangle.
If the two rectangles don't overlap, the rectangle returned will be empty.
| bool Rectangle< ValueType >::intersectRectangle | ( | ValueType & | otherX, | |
| ValueType & | otherY, | |||
| ValueType & | otherW, | |||
| ValueType & | otherH | |||
| ) | const throw () |
Clips a rectangle so that it lies only within this one.
This is a non-static version of intersectRectangles().
Returns false if the two regions didn't overlap.
| const Rectangle Rectangle< ValueType >::getUnion | ( | const Rectangle< ValueType > & | other | ) | const throw () |
Returns the smallest rectangle that contains both this one and the one passed-in.
| bool Rectangle< ValueType >::enlargeIfAdjacent | ( | const Rectangle< ValueType > & | other | ) | throw () |
If this rectangle merged with another one results in a simple rectangle, this will set this rectangle to the result, and return true.
Returns false and does nothing to this rectangle if the two rectangles don't overlap, or if they form a complex region.
| bool Rectangle< ValueType >::reduceIfPartlyContainedIn | ( | const Rectangle< ValueType > & | other | ) | throw () |
If after removing another rectangle from this one the result is a simple rectangle, this will set this object's bounds to be the result, and return true.
Returns false and does nothing to this rectangle if the two rectangles don't overlap, or if removing the other one would form a complex region.
| const Rectangle<ValueType> Rectangle< ValueType >::transformed | ( | const AffineTransform & | transform | ) | const throw () |
Returns the smallest rectangle that can contain the shape created by applying a transform to this rectangle.
This should only be used on floating point rectangles.
| const Rectangle<int> Rectangle< ValueType >::getSmallestIntegerContainer | ( | ) | const throw () |
Returns the smallest integer-aligned rectangle that completely contains this one.
This is only relevent for floating-point rectangles, of course.
| const Rectangle<float> Rectangle< ValueType >::toFloat | ( | ) | const throw () |
Casts this rectangle to a Rectangle<float>.
Obviously this is mainly useful for rectangles that use integer types.
| static bool Rectangle< ValueType >::intersectRectangles | ( | ValueType & | x1, | |
| ValueType & | y1, | |||
| ValueType & | w1, | |||
| ValueType & | h1, | |||
| const ValueType | x2, | |||
| const ValueType | y2, | |||
| const ValueType | w2, | |||
| const ValueType | h2 | |||
| ) | throw () [static] |
Static utility to intersect two sets of rectangular co-ordinates.
Returns false if the two regions didn't overlap.
Creates a string describing this rectangle.
The string will be of the form "x y width height", e.g. "100 100 400 200".
Coupled with the fromString() method, this is very handy for things like storing rectangles (particularly component positions) in XML attributes.
| static const Rectangle Rectangle< ValueType >::fromString | ( | const String & | stringVersion | ) | [static] |
Parses a string containing a rectangle's details.
The string should contain 4 integer tokens, in the form "x y width height". They can be comma or whitespace separated.
This method is intended to go with the toString() method, to form an easy way of saving/loading rectangles as strings.
1.6.3