CUGL 2.1
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 &rect) | |
Rect (const Rect &&rect) | |
Rect & | operator= (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 center, float radius) const |
bool | doesIntersect (const Rect rect) const |
bool | doesIntersect (const Vec2 center, float radius) const |
Rect & | operator+= (const Rect rect) |
Rect & | operator+= (const Vec2 vec) |
Rect & | operator-= (const Vec2 vec) |
Rect & | operator*= (float scale) |
Rect & | operator*= (const Vec2 scale) |
Rect & | operator*= (const Affine2 &transform) |
Rect & | operator*= (const Mat4 &transform) |
Rect & | operator/= (float scale) |
Rect & | operator/= (const Vec2 scale) |
Rect | operator+ (const Rect rect) |
Rect | operator+ (const Vec2 vec) const |
Rect | operator- (const Vec2 vec) const |
Rect | operator* (float scale) const |
Rect | operator* (const Vec2 scale) const |
Rect | operator* (const Affine2 &transform) const |
Rect | operator* (const Mat4 &transform) const |
Rect | operator/ (float scale) const |
Rect | operator/ (const Vec2 scale) const |
Rect & | translate (const Vec2 vec) |
Rect & | translate (float x, float y) |
Rect | getTranslation (const Vec2 vec) const |
Rect | getTranslation (float x, float y) const |
Rect & | scale (float scale) |
Rect & | scale (float sx, float sy) |
Rect & | scale (const Vec2 scale) |
Rect & | scale (const Vec2 scale, const Vec2 anchor) |
Rect | getScale (float scale) const |
Rect | getScale (float sx, float sy) const |
Rect | getScale (const Vec2 scale) const |
Rect | getScale (const Vec2 scale, const Vec2 anchor) 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) const |
Rect | getIntersection (const Rect &rect) const |
Rect | getExpansion (float factor) const |
Rect | getExpansion (const Vec2 point) const |
std::string | toString (bool verbose=false) const |
operator std::string () const | |
Public Attributes | |
Vec2 | origin |
Size | size |
Static Public Attributes | |
static const Rect | ZERO |
static const Rect | UNIT |
Friends | |
Rect | operator+ (const Vec2 vec, const Rect rect) |
Rect | operator- (const Vec2 vec, const Rect rect) |
Rect | operator* (float scale, const Rect rect) |
Rect | operator* (const Vec2 scale, const Rect rect) |
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.
rect | The rectangle to copy |
|
inline |
Creates a copy of the given rectangle.
rect | 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 | 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::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::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. |
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 |
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. |
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 |
|
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 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.
Returns the non-uniform scale of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The non-uniform scaling factor |
Returns the non-uniform scale of this rectangle.
The origin scale is the given anchor point, which is a percentage of the rectangle. (0,0) is the origin (bottom left corner) of the rectangle, while (1,1) is the top right corner of the rectangle.
scale | The non-uniform scaling factor |
anchor | The anchor for the scale origin point. |
Rect cugl::Rect::getScale | ( | float | scale | ) | const |
Returns the uniform scale of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
Rect cugl::Rect::getScale | ( | float | sx, |
float | sy | ||
) | const |
Returns the non-uniform scale of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
sx | The x-axis scale factor |
sy | The y-axis scale factor |
Returns the translation of this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The translation vector |
Rect cugl::Rect::getTranslation | ( | float | x, |
float | y | ||
) | const |
Returns the translation of this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
x | The translation x amount |
y | The translation y amount |
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 |
Cast from Rect to a string.
|
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. |
Returns the bounding box of the transformed quadrilateral.
Unlike the other mathematical operations, this method affects both the size and the origin. It uses the transform to map the rectangle into a new coordinate space. It then returns the bounding box of that transformed quadrilateral (in the new space).
transform | The affine transform |
Returns the bounding box of the transformed quadrilateral.
Unlike the other mathematical operations, this method affects both the size and the origin. It uses the transform to map the rectangle into a new coordinate space. It then returns the bounding box of that transformed quadrilateral (in the new space).
transform | The affine transform |
Returns the non-uniform scale of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
|
inline |
Returns the uniform scale of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
Sets this rectangle to the bounding box of the transformed quadrilateral.
Unlike the other mathematical operations, this method affects both the size and the origin. It uses the transform to map the rectangle into a new coordinate space. It then returns the bounding box of that transformed quadrilateral (in the new space).
transform | The affine transform |
Sets this rectangle to the bounding box of the transformed quadrilateral.
Unlike the other mathematical operations, this method affects both the size and the origin. It uses the transform to map the rectangle into a new coordinate space. It then returns the bounding box of that transformed quadrilateral (in the new space).
transform | The affine transform |
Nonuniformly scales the size of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The non-uniform scaling factor |
|
inline |
Uniformly the scales the size of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
Returns the union of this rect and the other.
rect | The rect to union with this one. |
Returns the translation of this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The translation vector |
Computes the union of this rect and the other, assigning it in place.
rect | The rect to union with this one. |
Translates this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The translation vector |
Returns the translation of this rectangle by subtracting the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The inverse of the translation vector |
Translates this rectangle by subtracting the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The inverse of the translation vector |
Returns the non-uniform scale of this rectangle by the inverse of scale.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The inverse of the uniform scaling factor |
|
inline |
Returns the uniform scale of this rectangle by the inverse of scale.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The inverse of the uniform scaling factor |
Nonuniformly scales the size of this rectangle by the inverse of scale.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The inverse of the non-uniform scaling factor |
|
inline |
Uniformly scales the size of this rectangle by the inverse of scale.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The inverse of the uniform scaling factor |
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 |
|
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. |
Sets this rectangle to be a copy of the given one.
other | The rectangle to copy |
Sets this rectangle to be a copy of the given one.
other | The rectangle to copy |
|
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 |
Nonuniformly scales the size of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The non-uniform scaling factor |
Nonuniformly scales this rectangle.
The origin scale is the given anchor point, which is a percentage of the rectangle. (0,0) is the origin (bottom left corner) of the rectangle, while (1,1) is the top right corner of the rectangle.
scale | The non-uniform scaling factor |
anchor | The anchor for the scale origin point. |
Rect& cugl::Rect::scale | ( | float | scale | ) |
Uniformly the scales the size of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
Rect& cugl::Rect::scale | ( | float | sx, |
float | sy | ||
) |
Nonuniformly scales the size of this rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
sx | The x-axis scale factor |
sy | The y-axis scale factor |
Rect& cugl::Rect::set | ( | const float * | array | ) |
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 be a copy of the given rectangle.
other | The rectangle to copy |
Assigns this rect to have the given position and dimensions.
pos | The position the bottom left corner |
dimen | The size of the rect |
Rect& cugl::Rect::set | ( | float | x, |
float | y, | ||
float | width, | ||
float | height | ||
) |
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 |
std::string cugl::Rect::toString | ( | bool | verbose = false | ) | const |
Returns a string representation of this rectangle for debugging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information |
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 |
Translates this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The translation vector |
Rect& cugl::Rect::translate | ( | float | x, |
float | y | ||
) |
Translates this rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
x | The translation x amount |
y | The translation y amount |
Returns the non-uniform scale of the rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The non-uniform scaling factor |
rect | The rectangle to scale |
Returns the uniform scale of the rectangle.
The origin of the rectangle is unaffected. To move the origin, translate the rectangle.
scale | The uniform scaling factor |
rect | The rectangle to scale |
Returns the translation of the rectangle by the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The translation vector |
rect | The rectangle to translate |
Returns the translation of the rectangle by subtracting the given vector.
The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.
vec | The inverse of the translation vector |
rect | The rectangle to translate |
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.