This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.
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 | |
ofRectangle & | operator= (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
-
px The x-position of the rectangle. py The y-position of the rectangle. w The width of the rectangle. h The 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
-
p The glm::vec3 representing the position of the rectangle. w The width of the rectangle. h The 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
-
rect The 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
-
p0 An glm::vec3 representing the upper left hand corner. p1 An glm::vec3 representing the lower right hand corner.
◆ ofRectangle() [7/7]
ofRectangle::ofRectangle | ( | const glm::vec2 & | p0, |
const glm::vec2 & | p1 | ||
) |
◆ ~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
-
targetPoint The target glm::vec3 to align to. thisHorzAnchor The horizontal alignment anchor. thisVertAnchor The 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
-
targetRect The target ofRectangle to align this rectangle to. sharedHorzAnchor The alignment anchor for both rectangles. sharedVertAnchor The 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
-
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.
◆ 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
-
targetX The x-position to align this rectangle to. thisHorzAnchor The 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
-
targetRect The target rectangle to align this rectangle to. sharedAnchor The 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
-
targetRect The target rectangle to align this rectangle to. targetHorzAnchor The edge of the other rectangle to align. thisHorzAnchor The 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
-
targetY The target y-position to align this rectangle to. sharedAnchor The 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
-
targetRect The target ofRectangle to align this rectangle to. sharedAnchor The 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
-
targetRect The target ofRectangle to align this rectangle to. targetVertAnchor The alignment anchor for this rectangle. thisVertAnchor The 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
-
anchor The 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
-
rect The 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.
- Parameters
-
rect The 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
-
anchor The 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
-
p The 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
-
p0 The first point to include. p1 The 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
-
rect The 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
-
px The x-coordinate to include. py The 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
-
p The 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
-
p0 The first point to test. p1 The 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
-
rect The 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
-
px The x-coordinate to test. py The 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
-
p0 The first point to test. p1 The 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
-
rect The 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
-
coeff Normalized 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
-
coeff Normalized 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
-
coeff Normalized 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
-
coeff Normalized 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
-
rect The 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
-
p The 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
-
p The point to translate.
- Returns
- The translated ofRectangle.
◆ operator=()
ofRectangle & ofRectangle::operator= | ( | const ofRectangle & | rect | ) |
Assignment operator.
- Parameters
-
rect The 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
-
rect The 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
-
s The 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
-
s The 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
-
sX The width-scaling factor. sY The 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
-
s The 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
-
s The 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
-
sX the width-scaling factor. sY the 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
-
sY The 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
-
targetRect The Target Rectangle to scale to. subjectAspectRatioMode Aspect ratio scaling mode. modelHorzAnchor The target horizontal alignment method. modelVertAnchor The target vertical alignment method. subjectHorzAnchor The subject horizontal alignment method. subjectVertAnchor The 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
-
targetRect The Target Rectangle to scale to. subjectAspectRatioMode Aspect ratio scaling mode. sharedHorzAnchor The horizontal alignment method. sharedVertAnchor The 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
-
targetRect The Target Rectangle to scale to. scaleMode The 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
-
sX The 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
-
p The new position. w The new width. h The 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
-
p0 The glm::vec3 representing the upper left hand corner. p1 The 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
-
rect The 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
-
px The new x-position. py The new y-position. w The new width. h The 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
-
p The position of the rectangle's center as an glm::vec3. w The width of the rectangle. h The 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
-
px The x-position of the rectangle's center. py The y-position of the rectangle's center. w The width of the rectangle. h The height of the rectangle.
◆ setHeight()
void ofRectangle::setHeight | ( | float | h | ) |
Set the height of the rectangle.
- Parameters
-
h The 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
-
p The position as an glm::vec3.
◆ setPosition() [2/2]
void ofRectangle::setPosition | ( | float | px, |
float | py | ||
) |
Set the position of the rectangle.
- Parameters
-
px The new x-position. py The new y-position.
◆ setSize()
void ofRectangle::setSize | ( | float | w, |
float | h | ||
) |
Set the size of the rectangle.
- Parameters
-
w The new width. h The new height.
◆ setWidth()
void ofRectangle::setWidth | ( | float | w | ) |
Set the width of the rectangle.
- Parameters
-
w The new width.
◆ setX()
void ofRectangle::setX | ( | float | px | ) |
Set the x-position of the rectangle.
- Parameters
-
px The new x-position.
◆ setY()
void ofRectangle::setY | ( | float | py | ) |
Set the y-position of the rectangle.
- Parameters
-
py The 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
-
dp The 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
-
dx The amount to translate in the x direction. dy The amount to translate in the y direction.
◆ translateX()
void ofRectangle::translateX | ( | float | dx | ) |
Translate the x-position of the rectangle.
- Parameters
-
dx The amount to translate on the x-axis.
◆ translateY()
void ofRectangle::translateY | ( | float | dy | ) |
Translate the y-position of the rectangle.
- Parameters
-
dy The 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