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.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofConstants.h"
4#include <glm/vec3.hpp>
5#include <glm/vec2.hpp>
6
18
32
33
47
77
78
88public:
89
92
95
105 ofRectangle(float px, float py, float w, float h);
106
117 ofRectangle(const glm::vec3& p, float w, float h);
118 ofRectangle(const glm::vec2& p, float w, float h);
119
122 ofRectangle(const ofRectangle& rect);
123
130 ofRectangle(const glm::vec3& p0, const glm::vec3& p1);
131 ofRectangle(const glm::vec2& p0, const glm::vec2& p1);
132
134 virtual ~ofRectangle();
135
137
140
150 void set(float px, float py, float w, float h);
151
162 void set(const glm::vec3& p, float w, float h);
163 void set(const glm::vec2& p, float w, float h);
164
167 void set(const ofRectangle& rect);
168
175 void set(const glm::vec3& p0, const glm::vec3& p1);
176 void set(const glm::vec2& p0, const glm::vec2& p1);
177
180 void setX(float px);
181
184 void setY(float py);
185
188 void setWidth(float w);
189
192 void setHeight(float h);
193
197 void setPosition(float px, float py);
198
204 void setPosition(const glm::vec3& p);
205
209 void setSize(float w, float h);
210
220 void setFromCenter(float px, float py, float w, float h);
221
230 void setFromCenter(const glm::vec3& p, float w, float h);
231 void setFromCenter(const glm::vec2& p, float w, float h);
232
234
237
241 void translate(float dx, float dy);
242
248 void translate(const glm::vec3& dp);
249 void translate(const glm::vec2& dp);
250
253 void translateX(float dx);
254
257 void translateY(float dy);
258
265 void scale(float s);
266
274 void scale(float sX, float sY);
275
284 void scale(const glm::vec3& s);
285 void scale(const glm::vec2& s);
286
292 void scaleWidth(float sX);
293
299 void scaleHeight(float sY);
300
307 void scaleFromCenter(float s);
308
316 void scaleFromCenter(float sX, float sY);
317
326 void scaleFromCenter(const glm::vec3& s);
327 void scaleFromCenter(const glm::vec2& s);
328
336 void scaleTo(const ofRectangle& targetRect,
337 ofScaleMode scaleMode = OF_SCALEMODE_FIT);
338
339
350 void scaleTo(const ofRectangle& targetRect,
351 ofAspectRatioMode subjectAspectRatioMode,
352 ofAlignHorz sharedHorzAnchor = OF_ALIGN_HORZ_CENTER,
353 ofAlignVert sharedVertAnchor = OF_ALIGN_VERT_CENTER);
354
367 void scaleTo(const ofRectangle& targetRect,
368 ofAspectRatioMode subjectAspectRatioMode,
369 ofAlignHorz modelHorzAnchor,
370 ofAlignVert modelVertAnchor,
371 ofAlignHorz subjectHorzAnchor,
372 ofAlignVert subjectVertAnchor);
373
375
378
379
388 void alignToHorz(const float& targetX,
389 ofAlignHorz thisHorzAnchor = OF_ALIGN_HORZ_CENTER);
390
404 void alignToHorz(const ofRectangle& targetRect,
405 ofAlignHorz sharedAnchor = OF_ALIGN_HORZ_CENTER);
406
418 void alignToHorz(const ofRectangle& targetRect,
419 ofAlignHorz targetHorzAnchor,
420 ofAlignHorz thisHorzAnchor);
421
430 void alignToVert(const float& targetY,
431 ofAlignVert sharedAnchor = OF_ALIGN_VERT_CENTER);
432
445 void alignToVert(const ofRectangle& targetRect,
446 ofAlignVert sharedAnchor = OF_ALIGN_VERT_CENTER);
447
448
457 void alignToVert(const ofRectangle& targetRect,
458 ofAlignVert targetVertAnchor,
459 ofAlignVert thisVertAnchor);
460
472 void alignTo(const glm::vec3& targetPoint,
473 ofAlignHorz thisHorzAnchor = OF_ALIGN_HORZ_CENTER,
474 ofAlignVert thisVertAnchor = OF_ALIGN_VERT_CENTER);
475 void alignTo(const glm::vec2& targetPoint,
476 ofAlignHorz thisHorzAnchor = OF_ALIGN_HORZ_CENTER,
477 ofAlignVert thisVertAnchor = OF_ALIGN_VERT_CENTER);
478
494 void alignTo(const ofRectangle& targetRect,
495 ofAlignHorz sharedHorzAnchor = OF_ALIGN_HORZ_CENTER,
496 ofAlignVert sharedVertAnchor = OF_ALIGN_VERT_CENTER);
497
498
513 void alignTo(const ofRectangle& targetRect,
514 ofAlignHorz targetHorzAnchor,
515 ofAlignVert targetVertAnchor,
516 ofAlignHorz thisHorzAnchor,
517 ofAlignVert thisVertAnchor);
518
520
523
532 bool inside(float px, float py) const;
533
543 bool inside(const glm::vec3& p) const;
544 bool inside(const glm::vec2& p) const;
545
553 bool inside(const ofRectangle& rect) const;
554
565 bool inside(const glm::vec3& p0, const glm::vec3& p1) const;
566 bool inside(const glm::vec2& p0, const glm::vec2& p1) const;
567
576 bool intersects(const ofRectangle& rect) const;
577
587 bool intersects(const glm::vec3& p0, const glm::vec3& p1) const;
588 bool intersects(const glm::vec2& p0, const glm::vec2& p1) const;
589
598 void growToInclude(float px, float py);
599
609 void growToInclude(const glm::vec3& p);
610 void growToInclude(const glm::vec2& p);
611
619 void growToInclude(const ofRectangle& rect);
620
631 void growToInclude(const glm::vec3& p0, const glm::vec3& p1);
632 void growToInclude(const glm::vec2& p0, const glm::vec2& p1);
633
651 ofRectangle getIntersection(const ofRectangle& rect) const;
652
659 ofRectangle getUnion(const ofRectangle& rect) const;
660
662
665
672 void standardize();
673
681
688 bool isStandardized() const;
689
691
694
700 float getArea() const;
701
702
708 float getPerimeter() const;
709
713 float getAspectRatio() const;
714
718 bool isEmpty() const;
719
722 glm::vec3 getMin() const;
723
726 glm::vec3 getMax() const;
727
730 float getMinX() const;
731
734 float getMaxX() const;
735
738 float getMinY() const;
739
742 float getMaxY() const;
743
747 float getLeft() const;
748
752 float getRight() const;
753
757 float getTop() const;
758
762 float getBottom() const;
763
767 glm::vec3 getTopLeft() const;
768
771 glm::vec3 getTopRight() const;
772
775 glm::vec3 getBottomLeft() const;
776
780 glm::vec3 getBottomRight() const;
781
787 float getHorzAnchor(ofAlignHorz anchor) const;
788
794 float getVertAnchor(ofAlignVert anchor) const;
795
801 const glm::vec3& getPosition() const;
802
803 OF_DEPRECATED_MSG("Use getPosition() instead.", glm::vec3& getPositionRef() );
804
810 glm::vec3 getCenter() const;
811
814 float getX() const;
815
818 float getY() const;
819
822 float getWidth() const;
823
826 float getHeight() const;
827
828
838 glm::vec2 map(const glm::vec2 & coeff) const;
839
849 ofRectangle map(const ofRectangle & coeff) const;
850
860 glm::vec2 mapClamp(const glm::vec2 & coeff) const;
861
872 ofRectangle mapClamp(const ofRectangle & coeff) const;
873
875
878
882 ofRectangle& operator = (const ofRectangle& rect);
883
888 ofRectangle operator + (const glm::vec3& p);
889 ofRectangle operator + (const glm::vec2& p);
890
895 ofRectangle operator - (const glm::vec3& p);
896 ofRectangle operator - (const glm::vec2& p);
897
902 bool operator == (const ofRectangle& rect) const;
903
908 bool operator != (const ofRectangle& rect) const;
909
910 bool isZero() const;
911
912
914
917
918
923 glm::vec3 position{};
924
926 float& x;
927
929 float& y;
930
932 float width;
933
935 float height;
936
938};
939
943std::ostream& operator<<(std::ostream& os, const ofRectangle& rect);
946std::istream& operator>>(std::istream& is, ofRectangle& rect);
A class representing a 2D rectangle.
Definition ofRectangle.h:87
void scaleTo(const ofRectangle &targetRect, ofScaleMode scaleMode=OF_SCALEMODE_FIT)
Scale the rectanle using a target ofRectangle and ofScaleMode.
Definition ofRectangle.cpp:233
const glm::vec3 & getPosition() const
Get the ofRectangle's position.
Definition ofRectangle.cpp:722
void standardize()
Standardize the rectangle.
Definition ofRectangle.cpp:562
void alignToVert(const float &targetY, ofAlignVert sharedAnchor=OF_ALIGN_VERT_CENTER)
Vertically align a rectangle using a position and anchor edge.
Definition ofRectangle.cpp:355
float getMaxX() const
Get the largest x position of the ofRectangle as float.
Definition ofRectangle.cpp:626
float getMaxY() const
Get the largest y position of the ofRectangle as float.
Definition ofRectangle.cpp:636
float getArea() const
Get the area of the ofRectangle.
Definition ofRectangle.cpp:591
virtual ~ofRectangle()
Destroy the rectangle.
Definition ofRectangle.cpp:14
void setWidth(float w)
Set the width of the rectangle.
Definition ofRectangle.cpp:100
ofRectangle getStandardized() const
Get the standardized representation of this rectangle.
Definition ofRectangle.cpp:575
void scaleWidth(float sX)
Scale the width of the rectangle.
Definition ofRectangle.cpp:193
float getY() const
Gets the y position of the ofRectangle as float.
Definition ofRectangle.cpp:742
glm::vec3 getBottomRight() const
Get the bottom-right coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:676
glm::vec2 map(const glm::vec2 &coeff) const
Maps a normalized coordinate into this rectangle.
Definition ofRectangle.cpp:757
void scaleFromCenter(float s)
Scales both the width and height the ofRectangle from its center.
Definition ofRectangle.cpp:202
float & y
The y position of the ofRectangle.
Definition ofRectangle.h:929
bool operator!=(const ofRectangle &rect) const
If the two ofRectangles differ in x, y, width, or height, they are considered unequal.
Definition ofRectangle.cpp:717
float & x
The x position of the ofRectangle.
Definition ofRectangle.h:926
void growToInclude(float px, float py)
Grow the ofRectangle to include the given (x, y) coordinates.
Definition ofRectangle.cpp:494
float getMinX() const
Get the smallest x position of the ofRectangle as float.
Definition ofRectangle.cpp:621
float getRight() const
Gets the x position of the right edge of the ofRectangle as float.
Definition ofRectangle.cpp:646
float getX() const
Gets the x position of the ofRectangle as float.
Definition ofRectangle.cpp:737
void setHeight(float h)
Set the height of the rectangle.
Definition ofRectangle.cpp:105
float getAspectRatio() const
Gets the ratio of width to height of the ofRectangle.
Definition ofRectangle.cpp:601
float getBottom() const
Gets the y position of the bottom edge of the ofRectangle as float.
Definition ofRectangle.cpp:656
float getMinY() const
Get the smallest y position of the ofRectangle as float.
Definition ofRectangle.cpp:631
glm::vec3 position
The (x,y) position of the ofRectangle as an glm::vec3.
Definition ofRectangle.h:923
float getHorzAnchor(ofAlignHorz anchor) const
A convenience method that returns the value of one of the horizontal edges of the ofRectangle using t...
Definition ofRectangle.cpp:681
float getTop() const
Gets the y position of the top edge of the ofRectangle as float.
Definition ofRectangle.cpp:651
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.
Definition ofRectangle.cpp:391
ofRectangle operator+(const glm::vec3 &p)
Returns a new ofRectangle where the x and y positions of the rectangle are offset by the (x,...
Definition ofRectangle.cpp:795
bool isStandardized() const
Returns true if this ofRectangle is standardized.
Definition ofRectangle.cpp:586
float getVertAnchor(ofAlignVert anchor) const
A convenience method that returns the value of one of the vertical edges of the ofRectangle using the...
Definition ofRectangle.cpp:699
glm::vec3 getBottomLeft() const
Get the bottom-left coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:671
float width
The width of the ofRectangle.
Definition ofRectangle.h:932
bool intersects(const ofRectangle &rect) const
Determines if another rectangle intersects with this rectangle.
Definition ofRectangle.cpp:465
glm::vec3 getTopLeft() const
Get the top-left coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:661
ofRectangle()
Construct a rectangle with zero width and zero height at 0, 0.
Definition ofRectangle.cpp:9
glm::vec3 getTopRight() const
Get the top-right coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:666
glm::vec3 getMax() const
Get the maximum x and y coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:616
glm::vec2 mapClamp(const glm::vec2 &coeff) const
Maps a normalized coordinate into this rectangle, clamping if out of bounds.
Definition ofRectangle.cpp:773
bool isEmpty() const
Determines if the ofRectangle's area is zero.
Definition ofRectangle.cpp:606
void setPosition(float px, float py)
Set the position of the rectangle.
Definition ofRectangle.cpp:110
void scaleHeight(float sY)
Scale the height of the rectangle.
Definition ofRectangle.cpp:197
float getPerimeter() const
Gets the perimeter of the ofRectangle.
Definition ofRectangle.cpp:596
glm::vec3 getCenter() const
Get the coordiantes of the ofRectangle's center as glm::vec3.
Definition ofRectangle.cpp:732
void setX(float px)
Set the x-position of the rectangle.
Definition ofRectangle.cpp:90
ofRectangle operator-(const glm::vec3 &p)
Returns a new ofRectangle where the x and y-positions of the rectangle are offset by the (x,...
Definition ofRectangle.cpp:808
void translateX(float dx)
Translate the x-position of the rectangle.
Definition ofRectangle.cpp:160
float height
The height of the ofRectangle.
Definition ofRectangle.h:935
void setY(float py)
Set the y-position of the rectangle.
Definition ofRectangle.cpp:95
ofRectangle getUnion(const ofRectangle &rect) const
Get the union area between this rectangle and anohter.
Definition ofRectangle.cpp:555
bool inside(float px, float py) const
Determines if the coordinates (x, y) are within the ofRectangle.
Definition ofRectangle.cpp:431
void setSize(float w, float h)
Set the size of the rectangle.
Definition ofRectangle.cpp:121
void scale(float s)
Scale the rectangle.
Definition ofRectangle.cpp:170
void translate(float dx, float dy)
Translate the rectangle's position by an x and y amount.
Definition ofRectangle.cpp:143
glm::vec3 getMin() const
Get the minimum x and y coordinates of the ofRectangle as glm::vec3.
Definition ofRectangle.cpp:611
ofRectangle getIntersection(const ofRectangle &rect) const
Get the intersecting area between this rectangle and another.
Definition ofRectangle.cpp:537
ofRectangle & operator=(const ofRectangle &rect)
Assignment operator.
Definition ofRectangle.cpp:789
bool operator==(const ofRectangle &rect) const
If both ofRectangles have the same x, y, width, and height, they are considered equal.
Definition ofRectangle.cpp:821
void alignToHorz(const float &targetX, ofAlignHorz thisHorzAnchor=OF_ALIGN_HORZ_CENTER)
Horizontally align a rectangle using a position and anchor edge.
Definition ofRectangle.cpp:319
void translateY(float dy)
Translate the y-position of the rectangle.
Definition ofRectangle.cpp:165
void set(float px, float py, float w, float h)
Set the position and size of the rectangle.
Definition ofRectangle.cpp:47
float getWidth() const
Gets the width of the ofRectangle as float.
Definition ofRectangle.cpp:747
void setFromCenter(float px, float py, float w, float h)
Set position and size of the rectangle from the center.
Definition ofRectangle.cpp:128
float getHeight() const
Gets the height of the ofRectangle as float.
Definition ofRectangle.cpp:752
bool isZero() const
Definition ofRectangle.cpp:826
float getLeft() const
Gets the x position of the left edge of the ofRectangle as float.
Definition ofRectangle.cpp:641
OF_DEPRECATED_MSG("Use getPosition() instead.", glm::vec3 &getPositionRef())
std::ostream & operator<<(std::ostream &os, const ofMatrix3x3 &M)
Definition ofMatrix3x3.cpp:304
std::istream & operator>>(std::istream &is, ofMatrix3x3 &M)
Definition ofMatrix3x3.cpp:323
#define px
#define py
ofAlignVert
Used to represent the available vertical rectangle alignment modes.
Definition ofRectangle.h:22
@ OF_ALIGN_VERT_TOP
Use the upper edge of the rectangle to vertically anchor the alignment.
Definition ofRectangle.h:26
@ OF_ALIGN_VERT_IGNORE
Do not perform any vertical alignment.
Definition ofRectangle.h:24
@ OF_ALIGN_VERT_CENTER
Use the center of the rectangle to vertically anchor the alignment.
Definition ofRectangle.h:30
@ OF_ALIGN_VERT_BOTTOM
Use the bottom edge of the rectangle to vertically anchor the alignment.
Definition ofRectangle.h:28
ofScaleMode
Used to represent the available rectangle scaling modes.
Definition ofRectangle.h:52
@ OF_SCALEMODE_FIT
Center and scale the rectangle to fit inside the target.
Definition ofRectangle.h:59
@ OF_SCALEMODE_FILL
Move and scale the rectangle to completely enclose the target.
Definition ofRectangle.h:66
@ OF_SCALEMODE_CENTER
Move the rectangle to be centered on the target.
Definition ofRectangle.h:72
@ OF_SCALEMODE_STRETCH_TO_FILL
Match the target rectangle's position and dimensions.
Definition ofRectangle.h:75
ofAlignHorz
Used to represent the available horizontal rectangle alignment modes.
Definition ofRectangle.h:37
@ OF_ALIGN_HORZ_RIGHT
Use the right edge of the rectangle to horizontally anchor the alignment.
Definition ofRectangle.h:43
@ OF_ALIGN_HORZ_LEFT
Use the left edge of the rectangle to horizontally anchor the alignment.
Definition ofRectangle.h:41
@ OF_ALIGN_HORZ_CENTER
Use the center of the rectangle to horizontally anchor the alignment.
Definition ofRectangle.h:45
@ OF_ALIGN_HORZ_IGNORE
Do not perform any horizontal alignment.
Definition ofRectangle.h:39
ofAspectRatioMode
Used to represent the available rectangle aspect ratio scaling modes.
Definition ofRectangle.h:10
@ OF_ASPECT_RATIO_KEEP_BY_EXPANDING
Resizes the rectangle to completely enclose the target.
Definition ofRectangle.h:16
@ OF_ASPECT_RATIO_IGNORE
Set the rectangle's width and height to match the target.
Definition ofRectangle.h:12
@ OF_ASPECT_RATIO_KEEP
Resizes the rectangle to completely fit within the target.
Definition ofRectangle.h:14