ofDoc > types > ofRectangle

ofRectanglefile

ofRectangleclass

A class representing a 2D rectangle.

ofRectangle is a simple container for describing the position and size of a 2D rectangle. 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:

ofRectangle myRect(0, 0, 100, 100);

or

ofRectangle myRect(100, 100, -100, -100);

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 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 is in it the "standard" form.

Warning
While ofRectangle takes ofPoint (a typedef for ofVec3f, a 3D vector), all ofRectangle operations are 2D only, ignoring the z-component.

Constructor

Setters

set ()
setX ()
setY ()

Transformation

scale ()
scaleTo ()

Alignment

alignTo ()

Intersection

inside ()

Standardization

Getters

getArea ()
isEmpty ()
getMin ()
getMax ()
getMinX ()
getMaxX ()
getMinY ()
getMaxY ()
getLeft ()
getTop ()
getX ()
getY ()

Operators

isZero ()

Properties

position variable
x variable
y variable
width variable
height variable