CUGL
Cornell University Game Library
|
#include <CURect.h>
Public Member Functions | |
Rect () | |
Rect (float x, float y, float width, float height) | |
Rect (float *array) | |
Rect (const Vec2 &pos, const Size &dimen) | |
Rect (const Rect &other) | |
Rect & | operator= (const Rect &other) |
Rect & | operator= (const float *array) |
Rect & | set (float x, float y, float width, float height) |
Rect & | set (const float *array) |
Rect & | set (const Vec2 &pos, const Size &dimen) |
Rect & | set (const Rect &other) |
float | getMinX () const |
float | getMidX () const |
float | getMaxX () const |
float | getMinY () const |
float | getMidY () const |
float | getMaxY () const |
float | isDegenerate () const |
bool | operator== (const Rect &rect) const |
bool | operator!= (const Rect &rect) const |
bool | equals (const Rect &rect, float variance=CU_MATH_EPSILON) const |
bool | operator<= (const Rect &rect) const |
bool | operator< (const Rect &rect) const |
bool | operator>= (const Rect &rect) const |
bool | operator> (const Rect &rect) const |
bool | inside (const Rect &rect) const |
bool | contains (const Rect &rect) const |
bool | touches (const Vec2 &point) const |
bool | contains (const Vec2 &point) const |
bool | contains (const Vec2 ¢er, float radius) const |
bool | doesIntersect (const Rect &rect) const |
bool | doesIntersect (const Vec2 ¢er, float radius) const |
Rect & | merge (const Rect &rect) |
Rect & | intersect (const Rect &rect) |
Rect & | expand (float factor) |
Rect & | expand (const Vec2 &point) |
Rect | getMerge (const Rect &rect) |
Rect | getIntersection (const Rect &rect) |
Rect | getExpansion (float factor) |
Rect | getExpansion (const Vec2 &point) |
Public Attributes | |
Vec2 | origin |
Size | size |
Static Public Attributes | |
static const Rect | ZERO |
static const Rect | UNIT |
This class represents a rectangle area in 2D space.
It is generally safe to manipulate the fields directly.
|
inline |
Creates an empty Rect at the origin
|
inline |
Creates a rect with the given origin and dimensions.
x | The x-coordinate of the bottom left corner |
y | The y-coordinate of the bottom left corner |
width | The width of the rect |
height | The width of the rect |
|
inline |
Creates a rect from the given float array.
array | An array containing the attributes in the order origin, size. |
Creates a rect with the given origin and dimensions.
pos | The position the bottom left corner |
dimen | The size of the rect |
|
inline |
Creates a copy of the given rectangle
other | The rectangle to copy |
bool cugl::Rect::contains | ( | const Rect & | rect | ) | const |
Returns true if this rect can hold the given rect.
This method does not test for strict containment. To test for strict containment, use the comparison operator >.
rect | The potentially smaller rect |
bool cugl::Rect::contains | ( | const Vec2 & | point | ) | const |
Returns true if this rect contains the given point.
This method does not test for strict containment; it includes the boundardy. To test for strict containment, combine this with the method touches().
point | The point to test |
bool cugl::Rect::contains | ( | const Vec2 & | center, |
float | radius | ||
) | const |
Returns true if this rect contains the given circle.
This method does not test for strict containment; it includes the boundary of both the circle and the rectangle.
center | The center of the circle |
radius | The radius of the circle |
bool cugl::Rect::doesIntersect | ( | const Rect & | rect | ) | const |
Returns true if this rect intersects the other.
This method allows for intersections where the edges of the rects are touching. In this case, the size of the intersection is empty.
rect | The rect to test |
bool cugl::Rect::doesIntersect | ( | const Vec2 & | center, |
float | radius | ||
) | const |
Returns true if this rect intersects the given circle.
This method allows for intersections where the edge of the rect simply touches the boundary of the circle.
center | The center of the circle |
radius | The radius of the circle |
|
inline |
Returns true if the rects are within tolerance of each other.
The tolerance bound is on attribute independently.
rect | The rect to compare against. |
variance | The comparison tolerance. |
Rect& cugl::Rect::expand | ( | float | factor | ) |
Expands this rectangle uniformly from its center.
Each edge of the rectangle is adjusted factor away from the center point. As a result, this method changes both origin and size. The value factor can be negative, in which case the rect shrinks in size.
factor | The amount to expand each edge from the center. |
Expands this rectangle to the minimal one containing the given point.
If the rectangle already contains the point, it is unchanged.
point | The point to envelop |
|
inline |
Returns a copy of this rect, expanded uniformly from its center.
Each edge of the rectangle is adjusted factor away from the center point. As a result, this method changes both origin and size. The value factor can be negative, in which case the rect shrinks in size.
Note: This does not modify the rect.
factor | The amount to expand each edge from the center. |
Returns a copy of this rectangle, expanded to contain the given point.
If the rectangle already contains the point, the rect is the same as the original.
point | The point to envelop |
Returns the intersection of this rect and the other.
If there is no intersection, this method returns the zero rectangle.
rect | The rect to intersect with this one. |
Note: This does not modify the rect.
|
inline |
Returns the rightmost x-value of the rect.
|
inline |
Returns the top y-value of the rect.
Returns the union of this rect and the other.
rect | The rect to union with this one. |
Note: This does not modify the rect.
|
inline |
Returns the center x-value of the rect.
|
inline |
Returns the center y-value of the rect.
|
inline |
Returns the leftmost x-value of the rect.
|
inline |
Returns the bottom y-value of the rect.
bool cugl::Rect::inside | ( | const Rect & | rect | ) | const |
Returns true if this rect fits inside of the given rect.
This method does not test for strict containment. To test for strict containment, use the comparison operator <.
rect | The potentially larger rect |
Computes the intersection of this rect and the other, assigning it in place.
If there is no intersection, this rect becomes the zero rectangle.
rect | The rect to intersect with this one. |
|
inline |
Returns true if the rectangle has non-positive size.
Computes the union of this rect and the other, assigning it in place.
rect | The rect to union with this one. |
|
inline |
Returns true if the rects are not equal to each other.
This operator uses exact equality and may fail due to round-off error.
rect | The rect to compare against. |
bool cugl::Rect::operator< | ( | const Rect & | rect | ) | const |
Returns true if this rect properly fits inside of the given rect.
Proper containment means that no edges of the two rects touch.
This operator is provided for convenience. However, this does not provide a total order, making it unsafe for std::sort.
rect | The potentially larger rect |
|
inline |
Returns true if this rect fits inside of the given rect.
This operator is provided for convenience. However, this does not provide a total order, making it unsafe for std::sort.
rect | The potentially larger rect |
Assigns this rect to be a copy of the given rectangle.
other | The rectangle to copy |
|
inline |
Sets the elements of this rect from the values in the specified array.
array | An array containing the elements in the order origin, size. |
|
inline |
Returns true if the rects are equal to each other.
This operator uses exact equality and may fail due to round-off error.
rect | The rect to compare against. |
bool cugl::Rect::operator> | ( | const Rect & | rect | ) | const |
Returns true if this rect can properly hold the given rect.
Proper containment means that no edges of the two rects touch.
This operator is provided for convenience. However, this does not provide a total order, making it unsafe for std::sort.
rect | The potentially smaller rect |
|
inline |
Returns true if this rect can hold the given rect.
This operator is provided for convenience. However, this does not provide a total order, making it unsafe for std::sort.
rect | The potentially smaller rect |
|
inline |
Assigns this rect to have the given position and dimensions.
x | The x-coordinate of the bottom left corner |
y | The y-coordinate of the bottom left corner |
width | The width of the rect |
height | The width of the rect |
|
inline |
Sets the elements of this rect from the values in the specified array.
array | An array containing the elements in the order origin, size. |
Assigns this rect to have the given position and dimensions.
pos | The position the bottom left corner |
dimen | The size of the rect |
Assigns this rect to be a copy of the given rectangle.
other | The rectangle to copy |
bool cugl::Rect::touches | ( | const Vec2 & | point | ) | const |
Returns true if the given point is on the boundar of this rect.
Combining this method with contains() allows you to test for strict containment.
point | The point to test |
Vec2 cugl::Rect::origin |
The bottom left point of rect.
Size cugl::Rect::size |
The width and height of the rect.
|
static |
The unit square.