reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofRectangle Class Reference

A class representing a 2D rectangle. More...

#include <ofRectangle.h>

Public Member Functions

Constructor
 ofRectangle ()
 Construct a rectangle with zero width and zero height at 0, 0.
 
 ofRectangle (float px, float py, float w, float h)
 Construct a rectangle using position and size.
 
 ofRectangle (const glm::vec3 &p, float w, float h)
 Construct a rectangle from a point and dimensions.
 
 ofRectangle (const glm::vec2 &p, float w, float h)
 
 ofRectangle (const ofRectangle &rect)
 Construct a rectangle by copying another rectangle.
 
 ofRectangle (const glm::vec3 &p0, const glm::vec3 &p1)
 Construct a rectangle by defining two corners.
 
 ofRectangle (const glm::vec2 &p0, const glm::vec2 &p1)
 
virtual ~ofRectangle ()
 Destroy the rectangle.
 
Setters
void set (float px, float py, float w, float h)
 Set the position and size of the rectangle.
 
void set (const glm::vec3 &p, float w, float h)
 Set the position and size of the rectangle.
 
void set (const glm::vec2 &p, float w, float h)
 
void set (const ofRectangle &rect)
 Set the position and size by copying them from anohter rectangle.
 
void set (const glm::vec3 &p0, const glm::vec3 &p1)
 Set the position and size of the rectangle using corners.
 
void set (const glm::vec2 &p0, const glm::vec2 &p1)
 
void setX (float px)
 Set the x-position of the rectangle.
 
void setY (float py)
 Set the y-position of the rectangle.
 
void setWidth (float w)
 Set the width of the rectangle.
 
void setHeight (float h)
 Set the height of the rectangle.
 
void setPosition (float px, float py)
 Set the position of the rectangle.
 
void setPosition (const glm::vec3 &p)
 Set the position of the rectangle.
 
void setSize (float w, float h)
 Set the size of the rectangle.
 
void setFromCenter (float px, float py, float w, float h)
 Set position and size of the rectangle from the center.
 
void setFromCenter (const glm::vec3 &p, float w, float h)
 Set position and size of the rectangle from the center.
 
void setFromCenter (const glm::vec2 &p, float w, float h)
 
Transformation
void translate (float dx, float dy)
 Translate the rectangle's position by an x and y amount.
 
void translate (const glm::vec3 &dp)
 Translate the rectangle's position by an x and y amount.
 
void translate (const glm::vec2 &dp)
 
void translateX (float dx)
 Translate the x-position of the rectangle.
 
void translateY (float dy)
 Translate the y-position of the rectangle.
 
void scale (float s)
 Scale the rectangle.
 
void scale (float sX, float sY)
 Scale the rectangle.
 
void scale (const glm::vec3 &s)
 Scale the rectangle.
 
void scale (const glm::vec2 &s)
 
void scaleWidth (float sX)
 Scale the width of the rectangle.
 
void scaleHeight (float sY)
 Scale the height of the rectangle.
 
void scaleFromCenter (float s)
 Scales both the width and height the ofRectangle from its center.
 
void scaleFromCenter (float sX, float sY)
 Scales both the width and height the ofRectangle from its center.
 
void scaleFromCenter (const glm::vec3 &s)
 Scales both the width and height the ofRectangle from its center.
 
void scaleFromCenter (const glm::vec2 &s)
 
void scaleTo (const ofRectangle &targetRect, ofScaleMode scaleMode=OF_SCALEMODE_FIT)
 Scale the rectanle using a target ofRectangle and ofScaleMode.
 
void scaleTo (const ofRectangle &targetRect, ofAspectRatioMode subjectAspectRatioMode, ofAlignHorz sharedHorzAnchor=OF_ALIGN_HORZ_CENTER, ofAlignVert sharedVertAnchor=OF_ALIGN_VERT_CENTER)
 Scale the rectangle using a target ofRectangle and parameters.
 
void scaleTo (const ofRectangle &targetRect, ofAspectRatioMode subjectAspectRatioMode, ofAlignHorz modelHorzAnchor, ofAlignVert modelVertAnchor, ofAlignHorz subjectHorzAnchor, ofAlignVert subjectVertAnchor)
 Scale the rectangle using a target ofRectangle and parameters.
 
Alignment
void alignToHorz (const float &targetX, ofAlignHorz thisHorzAnchor=OF_ALIGN_HORZ_CENTER)
 Horizontally align a rectangle using a position and anchor edge.
 
void alignToHorz (const ofRectangle &targetRect, ofAlignHorz sharedAnchor=OF_ALIGN_HORZ_CENTER)
 Horizontally align two rectangles to another using one anchor for both.
 
void alignToHorz (const ofRectangle &targetRect, ofAlignHorz targetHorzAnchor, ofAlignHorz thisHorzAnchor)
 Horizontally align two rectangles to another using two anchors.
 
void alignToVert (const float &targetY, ofAlignVert sharedAnchor=OF_ALIGN_VERT_CENTER)
 Vertically align a rectangle using a position and anchor edge.
 
void alignToVert (const ofRectangle &targetRect, ofAlignVert sharedAnchor=OF_ALIGN_VERT_CENTER)
 Vertically align two rectangles to another using one anchor for both.
 
void alignToVert (const ofRectangle &targetRect, ofAlignVert targetVertAnchor, ofAlignVert thisVertAnchor)
 Vertically align two rectangles to another using two anchors.
 
void alignTo (const glm::vec3 &targetPoint, ofAlignHorz thisHorzAnchor=OF_ALIGN_HORZ_CENTER, ofAlignVert thisVertAnchor=OF_ALIGN_VERT_CENTER)
 Align this ofRectangle to an glm::vec3 in both x- and y dimentions.
 
void alignTo (const glm::vec2 &targetPoint, ofAlignHorz thisHorzAnchor=OF_ALIGN_HORZ_CENTER, ofAlignVert thisVertAnchor=OF_ALIGN_VERT_CENTER)
 
void alignTo (const ofRectangle &targetRect, ofAlignHorz sharedHorzAnchor=OF_ALIGN_HORZ_CENTER, ofAlignVert sharedVertAnchor=OF_ALIGN_VERT_CENTER)
 Align this ofRectangle to an glm::vec3 in both x- and y dimentions using a shared anchor.
 
void alignTo (const ofRectangle &targetRect, ofAlignHorz targetHorzAnchor, ofAlignVert targetVertAnchor, ofAlignHorz thisHorzAnchor, ofAlignVert thisVertAnchor)
 Vertically align this ofRectangle to another target ofRectangle.
 
Intersection
bool inside (float px, float py) const
 Determines if the coordinates (x, y) are within the ofRectangle.
 
bool inside (const glm::vec3 &p) const
 Determines if the glm::vec3 is within the ofRectangle.
 
bool inside (const glm::vec2 &p) const
 
bool inside (const ofRectangle &rect) const
 Determines if another ofRectangle is completely within the ofRectangle.
 
bool inside (const glm::vec3 &p0, const glm::vec3 &p1) const
 Determines if both of the passed glm::vec3s are within the ofRectangle or not.
 
bool inside (const glm::vec2 &p0, const glm::vec2 &p1) const
 
bool intersects (const ofRectangle &rect) const
 Determines if another rectangle intersects with this rectangle.
 
bool intersects (const glm::vec3 &p0, const glm::vec3 &p1) const
 Determines if a line segment intersects with the ofRectangle.
 
bool intersects (const glm::vec2 &p0, const glm::vec2 &p1) const
 
void growToInclude (float px, float py)
 Grow the ofRectangle to include the given (x, y) coordinates.
 
void growToInclude (const glm::vec3 &p)
 Grow the ofRectangle to include the given point.
 
void growToInclude (const glm::vec2 &p)
 
void growToInclude (const ofRectangle &rect)
 Grow the ofRectangle to include the given ofRectangle.
 
void growToInclude (const glm::vec3 &p0, const glm::vec3 &p1)
 Grow the ofRectangle to include the given line segment.
 
void growToInclude (const glm::vec2 &p0, const glm::vec2 &p1)
 
ofRectangle getIntersection (const ofRectangle &rect) const
 Get the intersecting area between this rectangle and another.
 
ofRectangle getUnion (const ofRectangle &rect) const
 Get the union area between this rectangle and anohter.
 
Standardization
void standardize ()
 Standardize the rectangle.
 
ofRectangle getStandardized () const
 Get the standardized representation of this rectangle.
 
bool isStandardized () const
 Returns true if this ofRectangle is standardized.
 
Getters
float getArea () const
 Get the area of the ofRectangle.
 
float getPerimeter () const
 Gets the perimeter of the ofRectangle.
 
float getAspectRatio () const
 Gets the ratio of width to height of the ofRectangle.
 
bool isEmpty () const
 Determines if the ofRectangle's area is zero.
 
glm::vec3 getMin () const
 Get the minimum x and y coordinates of the ofRectangle as glm::vec3.
 
glm::vec3 getMax () const
 Get the maximum x and y coordinates of the ofRectangle as glm::vec3.
 
float getMinX () const
 Get the smallest x position of the ofRectangle as float.
 
float getMaxX () const
 Get the largest x position of the ofRectangle as float.
 
float getMinY () const
 Get the smallest y position of the ofRectangle as float.
 
float getMaxY () const
 Get the largest y position of the ofRectangle as float.
 
float getLeft () const
 Gets the x position of the left edge of the ofRectangle as float.
 
float getRight () const
 Gets the x position of the right edge of the ofRectangle as float.
 
float getTop () const
 Gets the y position of the top edge of the ofRectangle as float.
 
float getBottom () const
 Gets the y position of the bottom edge of the ofRectangle as float.
 
glm::vec3 getTopLeft () const
 Get the top-left coordinates of the ofRectangle as glm::vec3.
 
glm::vec3 getTopRight () const
 Get the top-right coordinates of the ofRectangle as glm::vec3.
 
glm::vec3 getBottomLeft () const
 Get the bottom-left coordinates of the ofRectangle as glm::vec3.
 
glm::vec3 getBottomRight () const
 Get the bottom-right coordinates of the ofRectangle as glm::vec3.
 
float getHorzAnchor (ofAlignHorz anchor) const
 A convenience method that returns the value of one of the horizontal edges of the ofRectangle using the ofAlignHorz enum.
 
float getVertAnchor (ofAlignVert anchor) const
 A convenience method that returns the value of one of the vertical edges of the ofRectangle using the ofAlignVert enum.
 
const glm::vec3 & getPosition () const
 Get the ofRectangle's position.
 
 OF_DEPRECATED_MSG ("Use getPosition() instead.", glm::vec3 &getPositionRef())
 
glm::vec3 getCenter () const
 Get the coordiantes of the ofRectangle's center as glm::vec3.
 
float getX () const
 Gets the x position of the ofRectangle as float.
 
float getY () const
 Gets the y position of the ofRectangle as float.
 
float getWidth () const
 Gets the width of the ofRectangle as float.
 
float getHeight () const
 Gets the height of the ofRectangle as float.
 
glm::vec2 map (const glm::vec2 &coeff) const
 Maps a normalized coordinate into this rectangle.
 
ofRectangle map (const ofRectangle &coeff) const
 Maps a normalized coordinate into this rectangle.
 
glm::vec2 mapClamp (const glm::vec2 &coeff) const
 Maps a normalized coordinate into this rectangle, clamping if out of bounds.
 
ofRectangle mapClamp (const ofRectangle &coeff) const
 Maps a normalized rectangle to this rectangle, clamping if out of bounds.
 
Operators
ofRectangleoperator= (const ofRectangle &rect)
 Assignment operator.
 
ofRectangle operator+ (const glm::vec3 &p)
 Returns a new ofRectangle where the x and y positions of the rectangle are offset by the (x, y) coordinates of the glm::vec3.
 
ofRectangle operator+ (const glm::vec2 &p)
 
ofRectangle operator- (const glm::vec3 &p)
 Returns a new ofRectangle where the x and y-positions of the rectangle are offset by the (x, y) coordinates of the glm::vec3.
 
ofRectangle operator- (const glm::vec2 &p)
 
bool operator== (const ofRectangle &rect) const
 If both ofRectangles have the same x, y, width, and height, they are considered equal.
 
bool operator!= (const ofRectangle &rect) const
 If the two ofRectangles differ in x, y, width, or height, they are considered unequal.
 
bool isZero () const
 

Public Attributes

Properties
glm::vec3 position {}
 The (x,y) position of the ofRectangle as an glm::vec3.
 
float & x
 The x position of the ofRectangle.
 
float & y
 The y position of the ofRectangle.
 
float width
 The width of the ofRectangle.
 
float height
 The height of the ofRectangle.
 

Detailed Description

A class representing a 2D rectangle.

ofRectangle is a simple container for describing the position and size of a 2D rectangle. The ofRectangle::standardize() method can be used to ensure that the origin is in the "standard" form.

Warning
While ofRectangle takes glm::vec3 all ofRectangle operations are 2D only, ignoring the z-component.

Constructor & Destructor Documentation

◆ ofRectangle() [1/7]

ofRectangle::ofRectangle ( )

Construct a rectangle with zero width and zero height at 0, 0.

◆ ofRectangle() [2/7]

ofRectangle::ofRectangle ( float  px,
float  py,
float  w,
float  h 
)

Construct a rectangle using position and size.

To produce consistent results, users are encouraged to initialize rectangles in the standardized form with width >=0 and height >= 0.

Parameters
pxThe x-position of the rectangle.
pyThe y-position of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.

◆ ofRectangle() [3/7]

ofRectangle::ofRectangle ( const glm::vec3 &  p,
float  w,
float  h 
)

Construct a rectangle from a point and dimensions.

To produce consistent results, users are encouraged to initialize rectangles in the standardized form with width >=0 and height >= 0.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
pThe glm::vec3 representing the position of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.

◆ ofRectangle() [4/7]

ofRectangle::ofRectangle ( const glm::vec2 &  p,
float  w,
float  h 
)

◆ ofRectangle() [5/7]

ofRectangle::ofRectangle ( const ofRectangle rect)

Construct a rectangle by copying another rectangle.

Parameters
rectThe rectangle to copy.

◆ ofRectangle() [6/7]

ofRectangle::ofRectangle ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
)

Construct a rectangle by defining two corners.

Warning
The z-components of the passed glm::vec3s are ignored.
Parameters
p0An glm::vec3 representing the upper left hand corner.
p1An glm::vec3 representing the lower right hand corner.

◆ ofRectangle() [7/7]

ofRectangle::ofRectangle ( const glm::vec2 &  p0,
const glm::vec2 &  p1 
)

◆ ~ofRectangle()

ofRectangle::~ofRectangle ( )
virtual

Destroy the rectangle.

Member Function Documentation

◆ alignTo() [1/4]

void ofRectangle::alignTo ( const glm::vec2 &  targetPoint,
ofAlignHorz  thisHorzAnchor = OF_ALIGN_HORZ_CENTER,
ofAlignVert  thisVertAnchor = OF_ALIGN_VERT_CENTER 
)

◆ alignTo() [2/4]

void ofRectangle::alignTo ( const glm::vec3 &  targetPoint,
ofAlignHorz  thisHorzAnchor = OF_ALIGN_HORZ_CENTER,
ofAlignVert  thisVertAnchor = OF_ALIGN_VERT_CENTER 
)

Align this ofRectangle to an glm::vec3 in both x- and y dimentions.

Aligns the position of the ofRectangle to the given point using an ofAlignHorz constant and an ofAlignVert constant. If neither constant is passed in, this will align the center of the rectangle.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
targetPointThe target glm::vec3 to align to.
thisHorzAnchorThe horizontal alignment anchor.
thisVertAnchorThe vertical alignment anchor.

◆ alignTo() [3/4]

void ofRectangle::alignTo ( const ofRectangle targetRect,
ofAlignHorz  sharedHorzAnchor = OF_ALIGN_HORZ_CENTER,
ofAlignVert  sharedVertAnchor = OF_ALIGN_VERT_CENTER 
)

Align this ofRectangle to an glm::vec3 in both x- and y dimentions using a shared anchor.

Aligns the position of the ofRectangle to that of the passed-in ofRectangle. Can take an ofAlignHorz constant and an ofAlignVert constant.

If neither constant is passed in, this will align the centers of the rectangles.

If constants are passed in, it will use those constants for both rectangles.

Parameters
targetRectThe target ofRectangle to align this rectangle to.
sharedHorzAnchorThe alignment anchor for both rectangles.
sharedVertAnchorThe alignment anchor for both rectangles.

◆ alignTo() [4/4]

void ofRectangle::alignTo ( const ofRectangle targetRect,
ofAlignHorz  targetHorzAnchor,
ofAlignVert  targetVertAnchor,
ofAlignHorz  thisHorzAnchor,
ofAlignVert  thisVertAnchor 
)

Vertically align this ofRectangle to another target ofRectangle.

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
targetRectThe target ofRectangle to align this rectangle to.
targetHorzAnchorThe vertical alignment anchor for the target rectangle.
targetVertAnchorThe horizontal alignment anchor for the target rectangle.
thisHorzAnchorThe horizontal alignment anchor for this rectangle.
thisVertAnchorThe vertical alignment anchor for this rectangle.

◆ alignToHorz() [1/3]

void ofRectangle::alignToHorz ( const float &  targetX,
ofAlignHorz  thisHorzAnchor = OF_ALIGN_HORZ_CENTER 
)

Horizontally align a rectangle using a position and anchor edge.

Aligns the horizontal position of the ofRectangle to the given x- position using an ofAlignHorz constant as anchor. If a constant is not passed in this will align the center of the rectangle.

Parameters
targetXThe x-position to align this rectangle to.
thisHorzAnchorThe edge of this rectangle to align.

◆ alignToHorz() [2/3]

void ofRectangle::alignToHorz ( const ofRectangle targetRect,
ofAlignHorz  sharedAnchor = OF_ALIGN_HORZ_CENTER 
)

Horizontally align two rectangles to another using one anchor for both.

Aligns the horizontal position of the ofRectangle to that of the passed-in ofRectangle using an ofAlignHorz constant as anchor.

If a constant is not passed in, this will align the horizontal centers of the rectangles.

If a constant is passed in, it will use that constant for both rectangles.

Parameters
targetRectThe target rectangle to align this rectangle to.
sharedAnchorThe common edge of the rectangles to align.

◆ alignToHorz() [3/3]

void ofRectangle::alignToHorz ( const ofRectangle targetRect,
ofAlignHorz  targetHorzAnchor,
ofAlignHorz  thisHorzAnchor 
)

Horizontally align two rectangles to another using two anchors.

Aligns the horizontal position of the ofRectangle to that of the passed-in ofRectangle. Takes two ofAlignHorz constants as anchors.

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

Parameters
targetRectThe target rectangle to align this rectangle to.
targetHorzAnchorThe edge of the other rectangle to align.
thisHorzAnchorThe edge of this rectangle to align.

◆ alignToVert() [1/3]

void ofRectangle::alignToVert ( const float &  targetY,
ofAlignVert  sharedAnchor = OF_ALIGN_VERT_CENTER 
)

Vertically align a rectangle using a position and anchor edge.

Aligns the vertical position of the ofRectangle to the given y- position using an ofAlignVert constant as anchor. If a constant is not passed in this will align the center of the rectangle.

Parameters
targetYThe target y-position to align this rectangle to.
sharedAnchorThe alignment position of this ofRectangle to use.

◆ alignToVert() [2/3]

void ofRectangle::alignToVert ( const ofRectangle targetRect,
ofAlignVert  sharedAnchor = OF_ALIGN_VERT_CENTER 
)

Vertically align two rectangles to another using one anchor for both.

Aligns the vertical position of the ofRectangle to that of the passed-in ofRectangle using an ofAlignVert constant as anchor.

If a constant is not passed in, this will align the vertical centers of the rectangles.

If a constant is passed in, it will use that constant for both rectangles.

Parameters
targetRectThe target ofRectangle to align this rectangle to.
sharedAnchorThe alignment position for both rectangles to use.

◆ alignToVert() [3/3]

void ofRectangle::alignToVert ( const ofRectangle targetRect,
ofAlignVert  targetVertAnchor,
ofAlignVert  thisVertAnchor 
)

Vertically align two rectangles to another using two anchors.

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

Parameters
targetRectThe target ofRectangle to align this rectangle to.
targetVertAnchorThe alignment anchor for this rectangle.
thisVertAnchorThe alignment anchor for the other rectangle.

◆ getArea()

float ofRectangle::getArea ( ) const

Get the area of the ofRectangle.

This is the product of the width and height of the recatngle.

Returns
The area of the rectangle as float.

◆ getAspectRatio()

float ofRectangle::getAspectRatio ( ) const

Gets the ratio of width to height of the ofRectangle.

Returns
The aspect ratio of the rectangle.

◆ getBottom()

float ofRectangle::getBottom ( ) const

Gets the y position of the bottom edge of the ofRectangle as float.

See also
getMaxY()
Returns
The y position of the bottom edge of the rectangle.

◆ getBottomLeft()

glm::vec3 ofRectangle::getBottomLeft ( ) const

Get the bottom-left coordinates of the ofRectangle as glm::vec3.

Returns
The bottom-left coordinates of the rectangle.

◆ getBottomRight()

glm::vec3 ofRectangle::getBottomRight ( ) const

Get the bottom-right coordinates of the ofRectangle as glm::vec3.

See also
getMax()
Returns
The bottom-right coordinates of the rectangle.

◆ getCenter()

glm::vec3 ofRectangle::getCenter ( ) const

Get the coordiantes of the ofRectangle's center as glm::vec3.

Warning
The z component of the returned glm::vec3 will always be 0.
Returns
The x and y coordinates of the center of the rectangle (z = 0).

◆ getHeight()

float ofRectangle::getHeight ( ) const

Gets the height of the ofRectangle as float.

Returns
The height of the rectangle.

◆ getHorzAnchor()

float ofRectangle::getHorzAnchor ( ofAlignHorz  anchor) const

A convenience method that returns the value of one of the horizontal edges of the ofRectangle using the ofAlignHorz enum.

Parameters
anchorThe anchor position to query.
Returns
the value of the referenced anchor position.

◆ getIntersection()

ofRectangle ofRectangle::getIntersection ( const ofRectangle rect) const

Get the intersecting area between this rectangle and another.

This method will attempt to return the area of overlap between this rectangle and the passed rectangle.

If the two rectangles do not overlap, it will return an "empty" rectangle located (0, 0) with 0 width and 0 height.

If the two rectangles only share an edge this will return a rectangle positioned on that edge:

If the shared edge is vertical, the rectangle will have zero width, otherwise it will have zero height.

Parameters
rectThe rectangle to intersect.
Returns
A new ofRectangle representing the intersecting area or an empty rectangle (0, 0, 0, 0) if there is no intersection.

◆ getLeft()

float ofRectangle::getLeft ( ) const

Gets the x position of the left edge of the ofRectangle as float.

See also
getMinX()
Returns
The x position of the left edge of the rectangle.

◆ getMax()

glm::vec3 ofRectangle::getMax ( ) const

Get the maximum x and y coordinates of the ofRectangle as glm::vec3.

Returns
The maximum x and y coordinates of the rectangle.

◆ getMaxX()

float ofRectangle::getMaxX ( ) const

Get the largest x position of the ofRectangle as float.

Returns
The largest x position of the rectangle.

◆ getMaxY()

float ofRectangle::getMaxY ( ) const

Get the largest y position of the ofRectangle as float.

Returns
The largest y position of the rectangle.

◆ getMin()

glm::vec3 ofRectangle::getMin ( ) const

Get the minimum x and y coordinates of the ofRectangle as glm::vec3.

Returns
The minimum x and y coordinates of the rectangle.

◆ getMinX()

float ofRectangle::getMinX ( ) const

Get the smallest x position of the ofRectangle as float.

Returns
The smallest xposition of the rectangle.

◆ getMinY()

float ofRectangle::getMinY ( ) const

Get the smallest y position of the ofRectangle as float.

Returns
The smallest y position of the rectangle.

◆ getPerimeter()

float ofRectangle::getPerimeter ( ) const

Gets the perimeter of the ofRectangle.

This is the sum of the lengths of the sides.

Returns
The perimeter of the rectangle as float.

◆ getPosition()

const glm::vec3 & ofRectangle::getPosition ( ) const

Get the ofRectangle's position.

Warning
The z component of the returned glm::vec3 is undefined.
Returns
The rectangle's position.

◆ getRight()

float ofRectangle::getRight ( ) const

Gets the x position of the right edge of the ofRectangle as float.

See also
getMaxX()
Returns
The y position of the right edge of the rectangle.

◆ getStandardized()

ofRectangle ofRectangle::getStandardized ( ) const

Get the standardized representation of this rectangle.

"Standardized" rectangles are rectangles whose width and height are positive. For more information about standardized rectangles, see the discussion of the standardize() method.

Returns
the Standardized version of this ofRectangle.

◆ getTop()

float ofRectangle::getTop ( ) const

Gets the y position of the top edge of the ofRectangle as float.

See also
getMinY()
Returns
The y position of the top edge of the rectangle.

◆ getTopLeft()

glm::vec3 ofRectangle::getTopLeft ( ) const

Get the top-left coordinates of the ofRectangle as glm::vec3.

See also
getMin()
Returns
The top-left coordinates of the rectangle.

◆ getTopRight()

glm::vec3 ofRectangle::getTopRight ( ) const

Get the top-right coordinates of the ofRectangle as glm::vec3.

Returns
The top-right coordinates of the rectangle.

◆ getUnion()

ofRectangle ofRectangle::getUnion ( const ofRectangle rect) const

Get the union area between this rectangle and anohter.

See also
getIntersection(const ofRectangle& rect) const
Parameters
rectThe rectangle to unite with.
Returns
A new ofRectangle whose area contains both the area of the this rectangle and the passed rectangle..

◆ getVertAnchor()

float ofRectangle::getVertAnchor ( ofAlignVert  anchor) const

A convenience method that returns the value of one of the vertical edges of the ofRectangle using the ofAlignVert enum.

Parameters
anchorThe anchor position to query.
Returns
the value of the referenced anchor position.

◆ getWidth()

float ofRectangle::getWidth ( ) const

Gets the width of the ofRectangle as float.

Returns
The width of the rectangle.

◆ getX()

float ofRectangle::getX ( ) const

Gets the x position of the ofRectangle as float.

Returns
The x position of the rectangle.

◆ getY()

float ofRectangle::getY ( ) const

Gets the y position of the ofRectangle as float.

Returns
the y position of the rectangle.

◆ growToInclude() [1/6]

void ofRectangle::growToInclude ( const glm::vec2 &  p)

◆ growToInclude() [2/6]

void ofRectangle::growToInclude ( const glm::vec2 &  p0,
const glm::vec2 &  p1 
)

◆ growToInclude() [3/6]

void ofRectangle::growToInclude ( const glm::vec3 &  p)

Grow the ofRectangle to include the given point.

This will potentially change the width, height, x-position, and y- position of the ofRectangle. If the point is already within the rectangle, this rectangle will remain unchanged.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
pThe position to include.

◆ growToInclude() [4/6]

void ofRectangle::growToInclude ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
)

Grow the ofRectangle to include the given line segment.

This will potentially change the width, height, x-position, and y-position of the ofRectangle. If the points are already within the rectangle, this rectangle will remain unchanged.

Warning
The z-components of the passed glm::vec3s are ignored.
Parameters
p0The first point to include.
p1The second point to include.

◆ growToInclude() [5/6]

void ofRectangle::growToInclude ( const ofRectangle rect)

Grow the ofRectangle to include the given ofRectangle.

This will potentially change the width, height, x-position, and y- position of the ofRectangle. If the rectangle is already within the rectangle, this rectangle will remain unchanged.

Parameters
rectThe rectangle to include.

◆ growToInclude() [6/6]

void ofRectangle::growToInclude ( float  px,
float  py 
)

Grow the ofRectangle to include the given (x, y) coordinates.

This will potentially change the width, height, x-position, and y- position of the ofRectangle. If the points are already within the rectangle, this rectangle will remain unchanged.

Parameters
pxThe x-coordinate to include.
pyThe y-coordiante to include.

◆ inside() [1/6]

bool ofRectangle::inside ( const glm::vec2 &  p) const

◆ inside() [2/6]

bool ofRectangle::inside ( const glm::vec2 &  p0,
const glm::vec2 &  p1 
) const

◆ inside() [3/6]

bool ofRectangle::inside ( const glm::vec3 &  p) const

Determines if the glm::vec3 is within the ofRectangle.

Note that points on the edge of the ofRectangle are not considered within the rectangle and will return false.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
pThe point to test.
Returns
true if the point p is inside this ofRectangle.

◆ inside() [4/6]

bool ofRectangle::inside ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
) const

Determines if both of the passed glm::vec3s are within the ofRectangle or not.

Note that points on the edge of the ofRectangle are not considered within the rectangle and will return false.

Warning
The z-components of the passed glm::vec3s are ignored.
Parameters
p0The first point to test.
p1The second point to test.
Returns
true if both points are inside the rectangle.

◆ inside() [5/6]

bool ofRectangle::inside ( const ofRectangle rect) const

Determines if another ofRectangle is completely within the ofRectangle.

Note that rectangles that share an edge with the ofRectangle are not considered within the rectangle and will return false.

Parameters
rectThe ofRectangle to test.
Returns
true if all four corners of the rect are within this rectangle.

◆ inside() [6/6]

bool ofRectangle::inside ( float  px,
float  py 
) const

Determines if the coordinates (x, y) are within the ofRectangle.

Note that coordinates on the edge of the ofRectangle are not considered within the rectangle and will return false.

Parameters
pxThe x-coordinate to test.
pyThe y-coordinate to test.
Returns
true if px and py are inside this ofRectangle.

◆ intersects() [1/3]

bool ofRectangle::intersects ( const glm::vec2 &  p0,
const glm::vec2 &  p1 
) const

◆ intersects() [2/3]

bool ofRectangle::intersects ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
) const

Determines if a line segment intersects with the ofRectangle.

Warning
The z-components of the passed glm::vec3s are ignored.
Parameters
p0The first point to test.
p1The second point to test.
Returns
true if the line segment defined by the two passed glm::vec3s either crosses the perimeter of the ofRectangle or is completely contained within.

◆ intersects() [3/3]

bool ofRectangle::intersects ( const ofRectangle rect) const

Determines if another rectangle intersects with this rectangle.

Rectangles that only share an edge and do not intersect otherwise are not considered to intersect and will return false.

Parameters
rectThe rectangle to test.
Returns
true if the area contained within the ofRectangle overlaps with the area contained within the passed ofRectangle.

◆ isEmpty()

bool ofRectangle::isEmpty ( ) const

Determines if the ofRectangle's area is zero.

See also
getArea().
Returns
true if both the width == 0 and height == 0, false if either is non-zero.

◆ isStandardized()

bool ofRectangle::isStandardized ( ) const

Returns true if this ofRectangle is standardized.

"Standardized" rectangles are rectangles whose width and height are positive. For more information about standardized rectangles, see the discussion of the standardize() method.

Returns
true if both width >= 0 and height >= 0.

◆ isZero()

bool ofRectangle::isZero ( ) const

◆ map() [1/2]

glm::vec2 ofRectangle::map ( const glm::vec2 &  coeff) const

Maps a normalized coordinate into this rectangle.

Normalized coordinates range from [0,1] inclusive. It is used to define a ratio between the coordinates and a unitary rectangle. This ratio is mapped into this rectangle to scale to real values. If normalized coordinates are out of bounds, output will be scaled accordingly.

Parameters
coeffNormalized coordinate to map to this rectangle
Returns
The mapped coordinate

◆ map() [2/2]

ofRectangle ofRectangle::map ( const ofRectangle coeff) const

Maps a normalized coordinate into this rectangle.

Normalized rectangles' position, width and height range from [0,1] inclusive. It is used to define a ratio between the rectangle and a unitary rectangle. This ratio is mapped into this rectangle to scale to real values. If normalized rectangle is out of bounds, output will be scaled accordingly.

Parameters
coeffNormalized rectangle to map to this rectangle
Returns
The mapped coordinate

◆ mapClamp() [1/2]

glm::vec2 ofRectangle::mapClamp ( const glm::vec2 &  coeff) const

Maps a normalized coordinate into this rectangle, clamping if out of bounds.

Normalized coordinates range from [0,1] inclusive. It is used to define a ratio between the coordinates and a unitary rectangle. This ratio is mapped into this rectangle to scale to real values. If normalized coordinates are out of bounds, output will be clamped to this rectangle's position, width and height.

Parameters
coeffNormalized coordinate to map to this rectangle
Returns
The mapped coordinate, clamped

◆ mapClamp() [2/2]

ofRectangle ofRectangle::mapClamp ( const ofRectangle coeff) const

Maps a normalized rectangle to this rectangle, clamping if out of bounds.

Normalized rectangles' position, width and height range from [0,1] inclusive. It is used to define a ratio between the rectangle and a unitary rectangle. This ratio is mapped into this rectangle to scale to real values. If normalized rectangle is out of bounds, output will be clamped to this rectangle's position, width and height.

Parameters
coeffNormalized rectangle to map to this rectangle
Returns
The mapped rectangle

◆ OF_DEPRECATED_MSG()

ofRectangle::OF_DEPRECATED_MSG ( "Use getPosition() instead."  ,
glm::vec3 &  getPositionRef() 
)

◆ operator!=()

bool ofRectangle::operator!= ( const ofRectangle rect) const

If the two ofRectangles differ in x, y, width, or height, they are considered unequal.

Parameters
rectThe rectangle to compare.
Returns
True if the rectangles are not equal.

◆ operator+() [1/2]

ofRectangle ofRectangle::operator+ ( const glm::vec2 &  p)

◆ operator+() [2/2]

ofRectangle ofRectangle::operator+ ( const glm::vec3 &  p)

Returns a new ofRectangle where the x and y positions of the rectangle are offset by the (x, y) coordinates of the glm::vec3.

Parameters
pThe point to translate.
Returns
The translated ofRectangle.

◆ operator-() [1/2]

ofRectangle ofRectangle::operator- ( const glm::vec2 &  p)

◆ operator-() [2/2]

ofRectangle ofRectangle::operator- ( const glm::vec3 &  p)

Returns a new ofRectangle where the x and y-positions of the rectangle are offset by the (x, y) coordinates of the glm::vec3.

Parameters
pThe point to translate.
Returns
The translated ofRectangle.

◆ operator=()

ofRectangle & ofRectangle::operator= ( const ofRectangle rect)

Assignment operator.

Parameters
rectThe rectangle to assign.
Returns
A reference to this rectangle.

◆ operator==()

bool ofRectangle::operator== ( const ofRectangle rect) const

If both ofRectangles have the same x, y, width, and height, they are considered equal.

Parameters
rectThe rectangle to compare.
Returns
True if the rectangles are equal.

◆ scale() [1/4]

void ofRectangle::scale ( const glm::vec2 &  s)

◆ scale() [2/4]

void ofRectangle::scale ( const glm::vec3 &  s)

Scale the rectangle.

Scaling will scale the width and the height, but will not change the position.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
sThe scaling factor.

◆ scale() [3/4]

void ofRectangle::scale ( float  s)

Scale the rectangle.

Scaling will scale the width and the height, but will not change the position.

Parameters
sThe scaling factor.

◆ scale() [4/4]

void ofRectangle::scale ( float  sX,
float  sY 
)

Scale the rectangle.

Scaling will scale the width and the height, but will not change the position.

Parameters
sXThe width-scaling factor.
sYThe height-scaling factor.

◆ scaleFromCenter() [1/4]

void ofRectangle::scaleFromCenter ( const glm::vec2 &  s)

◆ scaleFromCenter() [2/4]

void ofRectangle::scaleFromCenter ( const glm::vec3 &  s)

Scales both the width and height the ofRectangle from its center.

The center point of the rectangle will remain fixed and the width, height, x, and y will be adjusted.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
sThe scaling factor.

◆ scaleFromCenter() [3/4]

void ofRectangle::scaleFromCenter ( float  s)

Scales both the width and height the ofRectangle from its center.

The center point of the rectangle will remain fixed and the width, height, x, and y will be adjusted.

Parameters
sThe scaling factor.

◆ scaleFromCenter() [4/4]

void ofRectangle::scaleFromCenter ( float  sX,
float  sY 
)

Scales both the width and height the ofRectangle from its center.

The center point of the rectangle will remain fixed and the width, height, x, and y will be adjusted.

Parameters
sXthe width-scaling factor.
sYthe height-scaling factor.

◆ scaleHeight()

void ofRectangle::scaleHeight ( float  sY)

Scale the height of the rectangle.

This will scale the height but will not change the position and width.

Parameters
sYThe height-scaling factor.

◆ scaleTo() [1/3]

void ofRectangle::scaleTo ( const ofRectangle targetRect,
ofAspectRatioMode  subjectAspectRatioMode,
ofAlignHorz  modelHorzAnchor,
ofAlignVert  modelVertAnchor,
ofAlignHorz  subjectHorzAnchor,
ofAlignVert  subjectVertAnchor 
)

Scale the rectangle using a target ofRectangle and parameters.

Adjusts the ofRectangle to match the passed-in ofRectangle. It will use the ofAspectRatioMode to scale the ofRectangle, and will use the use the alignment anchor parameters to position the rectangle.

Parameters
targetRectThe Target Rectangle to scale to.
subjectAspectRatioModeAspect ratio scaling mode.
modelHorzAnchorThe target horizontal alignment method.
modelVertAnchorThe target vertical alignment method.
subjectHorzAnchorThe subject horizontal alignment method.
subjectVertAnchorThe subject vertical alignment method.

◆ scaleTo() [2/3]

void ofRectangle::scaleTo ( const ofRectangle targetRect,
ofAspectRatioMode  subjectAspectRatioMode,
ofAlignHorz  sharedHorzAnchor = OF_ALIGN_HORZ_CENTER,
ofAlignVert  sharedVertAnchor = OF_ALIGN_VERT_CENTER 
)

Scale the rectangle using a target ofRectangle and parameters.

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

Parameters
targetRectThe Target Rectangle to scale to.
subjectAspectRatioModeAspect ratio scaling mode.
sharedHorzAnchorThe horizontal alignment method.
sharedVertAnchorThe vertical alignment method.

◆ scaleTo() [3/3]

void ofRectangle::scaleTo ( const ofRectangle targetRect,
ofScaleMode  scaleMode = OF_SCALEMODE_FIT 
)

Scale the rectanle using a target ofRectangle and ofScaleMode.

Adjusts the ofRectangle to match the provided ofRectangle using the provided ofScaleMode.

Parameters
targetRectThe Target Rectangle to scale to.
scaleModeThe scale mode to use when scaling.

◆ scaleWidth()

void ofRectangle::scaleWidth ( float  sX)

Scale the width of the rectangle.

This will scale the width but will not change the position or height.

Parameters
sXThe width-scaling factor.

◆ set() [1/6]

void ofRectangle::set ( const glm::vec2 &  p,
float  w,
float  h 
)

◆ set() [2/6]

void ofRectangle::set ( const glm::vec2 &  p0,
const glm::vec2 &  p1 
)

◆ set() [3/6]

void ofRectangle::set ( const glm::vec3 &  p,
float  w,
float  h 
)

Set the position and size of the rectangle.

To produce consistent results, users are encouraged to initialize rectangles in the standardized form with width >=0 and height >= 0.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
pThe new position.
wThe new width.
hThe new height.

◆ set() [4/6]

void ofRectangle::set ( const glm::vec3 &  p0,
const glm::vec3 &  p1 
)

Set the position and size of the rectangle using corners.

Warning
The z-components of the passed glm::vec3s are ignored.
Parameters
p0The glm::vec3 representing the upper left hand corner.
p1The glm::vec3 representing the lower right hand corner.

◆ set() [5/6]

void ofRectangle::set ( const ofRectangle rect)

Set the position and size by copying them from anohter rectangle.

Parameters
rectThe rectangle to copy.

◆ set() [6/6]

void ofRectangle::set ( float  px,
float  py,
float  w,
float  h 
)

Set the position and size of the rectangle.

To produce consistent results, users are encouraged to initialize rectangles in the standardized form with width >=0 and height >= 0.

Parameters
pxThe new x-position.
pyThe new y-position.
wThe new width.
hThe new height.

◆ setFromCenter() [1/3]

void ofRectangle::setFromCenter ( const glm::vec2 &  p,
float  w,
float  h 
)

◆ setFromCenter() [2/3]

void ofRectangle::setFromCenter ( const glm::vec3 &  p,
float  w,
float  h 
)

Set position and size of the rectangle from the center.

The center of the rectangle is defined and the width and height grow out around the center.

Parameters
pThe position of the rectangle's center as an glm::vec3.
wThe width of the rectangle.
hThe height of the rectangle.

◆ setFromCenter() [3/3]

void ofRectangle::setFromCenter ( float  px,
float  py,
float  w,
float  h 
)

Set position and size of the rectangle from the center.

The center of the rectangle is defined and the width and height grow out around the center.

Parameters
pxThe x-position of the rectangle's center.
pyThe y-position of the rectangle's center.
wThe width of the rectangle.
hThe height of the rectangle.

◆ setHeight()

void ofRectangle::setHeight ( float  h)

Set the height of the rectangle.

Parameters
hThe new height.

◆ setPosition() [1/2]

void ofRectangle::setPosition ( const glm::vec3 &  p)

Set the position of the rectangle.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
pThe position as an glm::vec3.

◆ setPosition() [2/2]

void ofRectangle::setPosition ( float  px,
float  py 
)

Set the position of the rectangle.

Parameters
pxThe new x-position.
pyThe new y-position.

◆ setSize()

void ofRectangle::setSize ( float  w,
float  h 
)

Set the size of the rectangle.

Parameters
wThe new width.
hThe new height.

◆ setWidth()

void ofRectangle::setWidth ( float  w)

Set the width of the rectangle.

Parameters
wThe new width.

◆ setX()

void ofRectangle::setX ( float  px)

Set the x-position of the rectangle.

Parameters
pxThe new x-position.

◆ setY()

void ofRectangle::setY ( float  py)

Set the y-position of the rectangle.

Parameters
pyThe new y-position.

◆ standardize()

void ofRectangle::standardize ( )

Standardize the rectangle.

"Standardized" rectangles are rectangles whose width and height are positive: width >= 0 and height >= 0. This method can be used to ensure that the rectangle is "standardized". If the rectangle is non-standard, it will modify the x / width and y / height values into their respective standardized versions.

◆ translate() [1/3]

void ofRectangle::translate ( const glm::vec2 &  dp)

◆ translate() [2/3]

void ofRectangle::translate ( const glm::vec3 &  dp)

Translate the rectangle's position by an x and y amount.

Warning
The z-component of the passed glm::vec3 is ignored.
Parameters
dpThe amount to translate as an glm::vec3.

◆ translate() [3/3]

void ofRectangle::translate ( float  dx,
float  dy 
)

Translate the rectangle's position by an x and y amount.

Parameters
dxThe amount to translate in the x direction.
dyThe amount to translate in the y direction.

◆ translateX()

void ofRectangle::translateX ( float  dx)

Translate the x-position of the rectangle.

Parameters
dxThe amount to translate on the x-axis.

◆ translateY()

void ofRectangle::translateY ( float  dy)

Translate the y-position of the rectangle.

Parameters
dyThe amount to translate on the y-axis.

Member Data Documentation

◆ height

float ofRectangle::height

The height of the ofRectangle.

◆ position

glm::vec3 ofRectangle::position {}

The (x,y) position of the ofRectangle as an glm::vec3.

Warning
The z-component of this position is preserved and can be used but all ofRectangle operations will ignore the z-component.

◆ width

float ofRectangle::width

The width of the ofRectangle.

◆ x

float& ofRectangle::x

The x position of the ofRectangle.

◆ y

float& ofRectangle::y

The y position of the ofRectangle.


The documentation for this class was generated from the following files:
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/types/ofRectangle.h
  • /Users/icq4ever/Desktop/oF0120/libs/openFrameworks/types/ofRectangle.cpp