Rectangle< ValueType > Class Template Reference

Manages a rectangle and allows geometric operations to be performed on it. More...

List of all members.

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.
Rectangleoperator= (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.

Detailed Description

template<typename ValueType>
class Rectangle< ValueType >

Manages a rectangle and allows geometric operations to be performed on it.

See also:
RectangleList, Path, Line, Point

Constructor & Destructor Documentation

template<typename ValueType>
Rectangle< ValueType >::Rectangle (  )  throw ()
template<typename ValueType>
Rectangle< ValueType >::Rectangle ( const Rectangle< ValueType > &  other  )  throw ()

Creates a copy of another rectangle.

template<typename ValueType>
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.

template<typename ValueType>
Rectangle< ValueType >::Rectangle ( const ValueType  width,
const ValueType  height 
) throw ()

Creates a rectangle with a given size, and a position of (0, 0).

template<typename ValueType>
Rectangle< ValueType >::Rectangle ( const Point< ValueType > &  corner1,
const Point< ValueType > &  corner2 
) throw ()

Creates a Rectangle from the positions of two opposite corners.

template<typename ValueType>
Rectangle< ValueType >::~Rectangle (  )  throw ()

Destructor.


Member Function Documentation

template<typename ValueType>
Rectangle& Rectangle< ValueType >::operator= ( const Rectangle< ValueType > &  other  )  throw ()
template<typename ValueType>
bool Rectangle< ValueType >::isEmpty (  )  const throw ()

Returns true if the rectangle's width and height are both zero or less.

template<typename ValueType>
ValueType Rectangle< ValueType >::getX (  )  const throw ()

Returns the x co-ordinate of the rectangle's left-hand-side.

template<typename ValueType>
ValueType Rectangle< ValueType >::getY (  )  const throw ()

Returns the y co-ordinate of the rectangle's top edge.

template<typename ValueType>
ValueType Rectangle< ValueType >::getWidth (  )  const throw ()

Returns the width of the rectangle.

template<typename ValueType>
ValueType Rectangle< ValueType >::getHeight (  )  const throw ()

Returns the height of the rectangle.

template<typename ValueType>
ValueType Rectangle< ValueType >::getRight (  )  const throw ()

Returns the x co-ordinate of the rectangle's right-hand-side.

Referenced by Rectangle< int >::enlargeIfAdjacent().

template<typename ValueType>
ValueType Rectangle< ValueType >::getBottom (  )  const throw ()

Returns the y co-ordinate of the rectangle's bottom edge.

Referenced by Rectangle< int >::enlargeIfAdjacent().

template<typename ValueType>
ValueType Rectangle< ValueType >::getCentreX (  )  const throw ()

Returns the x co-ordinate of the rectangle's centre.

template<typename ValueType>
ValueType Rectangle< ValueType >::getCentreY (  )  const throw ()

Returns the y co-ordinate of the rectangle's centre.

template<typename ValueType>
const Point<ValueType> Rectangle< ValueType >::getCentre (  )  const throw ()

Returns the centre point of the rectangle.

template<typename ValueType>
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.

template<typename ValueType>
const Point<ValueType> Rectangle< ValueType >::getPosition (  )  const throw ()

Returns the rectangle's top-left position as a Point.

template<typename ValueType>
void Rectangle< ValueType >::setPosition ( const Point< ValueType > &  newPos  )  throw ()

Changes the position of the rectangle's top-left corner (leaving its size unchanged).

template<typename ValueType>
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).

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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().

template<typename ValueType>
void Rectangle< ValueType >::setWidth ( const ValueType  newWidth  )  throw ()

Changes the rectangle's width.

template<typename ValueType>
void Rectangle< ValueType >::setHeight ( const ValueType  newHeight  )  throw ()

Changes the rectangle's height.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

See also:
getRight
template<typename ValueType>
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.

See also:
getBottom
template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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).

See also:
expanded, reduce, reduced

Referenced by Rectangle< int >::reduce().

template<typename ValueType>
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).

See also:
expand, reduce, reduced

Referenced by Rectangle< int >::reduced().

template<typename ValueType>
void Rectangle< ValueType >::reduce ( const ValueType  deltaX,
const ValueType  deltaY 
) throw ()

Shrinks the rectangle by a given amount.

Effectively, its new size is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2).

See also:
reduced, expand, expanded
template<typename ValueType>
const Rectangle Rectangle< ValueType >::reduced ( const ValueType  deltaX,
const ValueType  deltaY 
) const throw ()

Returns a rectangle that is smaller than this one by a given amount.

Effectively, the rectangle returned is (x + deltaX, y + deltaY, w - deltaX * 2, h - deltaY * 2).

See also:
reduce, expand, expanded
template<typename ValueType>
bool Rectangle< ValueType >::operator== ( const Rectangle< ValueType > &  other  )  const throw ()

Returns true if the two rectangles are identical.

template<typename ValueType>
bool Rectangle< ValueType >::operator!= ( const Rectangle< ValueType > &  other  )  const throw ()

Returns true if the two rectangles are not identical.

template<typename ValueType>
bool Rectangle< ValueType >::contains ( const ValueType  xCoord,
const ValueType  yCoord 
) const throw ()

Returns true if this co-ordinate is inside the rectangle.

template<typename ValueType>
bool Rectangle< ValueType >::contains ( const Point< ValueType > &  point  )  const throw ()

Returns true if this co-ordinate is inside the rectangle.

template<typename ValueType>
bool Rectangle< ValueType >::contains ( const Rectangle< ValueType > &  other  )  const throw ()

Returns true if this other rectangle is completely inside this one.

template<typename ValueType>
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.

template<typename ValueType>
bool Rectangle< ValueType >::intersects ( const Rectangle< ValueType > &  other  )  const throw ()

Returns true if any part of another rectangle overlaps this one.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

template<typename ValueType>
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.

See also:
toFloat()
template<typename ValueType>
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.

See also:
getSmallestIntegerContainer
template<typename ValueType>
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.

See also:
intersectRectangle
template<typename ValueType>
const String Rectangle< ValueType >::toString (  )  const

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.

See also:
fromString
template<typename ValueType>
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.

See also:
toString

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Apr 26 11:42:16 2010 for JUCE by  doxygen 1.6.3