Description

ofRectangle is a simple container for describing the position and size of a 2D rectangle. The ofRectangle class provides a data structure and a collection of useful helper methods for manipulating rectangles.

Since the width and height variables can be negative, the x/y-position is not guaranteed to represent the upper right hand corner. For example, two visually identical rectangles can be represented in the following ways:

While both representations will yield the same visual results in all openFrameworks renderers, the results of some method operations that modify x, y, width and height (such as scaling) produce mathematically correct, but visually different results for each of the above representations.

To avoid this ambiguity, users should prefer "standardized" rectangles. "Standardized" rectangles are rectangles whose width >= 0 and height >= 0. The ofRectangle::standardize() method can be used to ensure that the origin is in the "standard" form.

Documentation from code comments

Aligns the position of the ofRectangle to that of the passed-in
ofRectangle. Takes two ofAlignHorz constants and two ofAlignVert
constants.

Will align the chosen anchors in the ofRectangle with the chosen
anchors in the passed-in ofRectangle.

Parameters:
targetRect The target ofRectangle to align this rectangle to.
targetHorzAnchor The vertical alignment anchor for the target rectangle.
targetVertAnchor The horizontal alignment anchor for the target rectangle.
thisHorzAnchor The horizontal alignment anchor for this rectangle.
thisVertAnchor The vertical alignment anchor for this rectangle.

float ofRectangle::getMinY()

Documentation from code comments

float ofRectangle::getPerimeter()

Example:

// Create a rectangle that is 100 units wide and 200 units tall
ofRectangle myRect(0,0,100,200);
// Get the perimeter of that rectangle
float perimeterValue = myRect.getPerimeter();
// perimeterValue will be 600.0.

OF_ASPECT_RATIO_IGNORE : Sets the Subject rectangle's width and height to match those of the Target.
OF_ASPECT_RATIO_KEEP : Resizes the Subject rectangle to completely fit within the Target rectangle.
OF_ASPECT_RATIO_KEEP_BY_EXPANDING : Resizes the Subject rectangle to completely enclose the Target rectangle.

ofAlignHorz Options:

OF_ALIGN_HORZ_IGNORE : Does not perform any horizontal alignment.
OF_ALIGN_HORZ_LEFT : Uses the left edge of the rectangle to horizontally anchor the alignment.
OF_ALIGN_HORZ_RIGHT : Uses the right edge of the rectangle to horizontally anchor the alignment.
OF_ALIGN_HORZ_CENTER : Uses the center of the rectangle to horizontally anchor the alignment.

ofAlignVert Options:

OF_ALIGN_VERT_IGNORE : Does not perform any vertical alignment.
OF_ALIGN_VERT_TOP : Uses the upper edge of the rectangle to vertically anchor the alignment.
OF_ALIGN_VERT_BOTTOM : Uses the bottom edge of the rectangle to vertically anchor the alignment.
OF_ALIGN_VERT_CENTER : Uses the center of the rectangle to vertically anchor the alignment.

For a working example of how to use ofAspectRatioMode, ofAlignVert, and ofAlignHorz, see the graphics/rectangleAlignmentAndScaling/ example within the examples directory.

Documentation from code comments

Scales the ofRectangle to match the target ofRectangle. It will use the
ofAspectRatioMode to scale the ofRectangle and will use the use the
alignment anchor parameters to position the rectangle.

This is a convenience method when both the target and subject rectangles
are using the same alignment anchors. For a more complete explanation,
see void scaleTo(const ofRectangle& targetRect, ofAspectRatioMode
subjectAspectRatioMode, ofAlignHorz modelHorzAnchor, ofAlignVert
modelVertAnchor, ofAlignHorz subjectHorzAnchor, ofAlignVert
subjectVertAnchor);

For a working example of how to use ofAspectRatioMode, ofAlignVert, and
ofAlignHorz, see the graphics/rectangleAlignmentAndScaling/ example
within the examples directory.

void ofRectangle::setY(float py)

Documentation from code comments

void ofRectangle::standardize()

ofRectangle is a simple container for describing the position
and size of 2D rectangles. Like many rectangle data structures
found in other frameworks and graphics libraries, member
width and height variables can take negative values.
Additionally, x / y position and width / height are publicly
accessible, resulting in great programming freedom.
Consequently, two visually identical rectangles can be
represented in the following ways:

While both representations will yield the same visual
results in all openFrameworks renderers, the results of
some method operations that modify x / y / width / height
(such as scaling) produce mathematically correct, but
visually different results for each of the above
representations.