CUGL 2.1
Cornell University Game Library
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
cugl::Rect Class Reference

#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)
 
Rectoperator= (const Rect &other)
 
Rectoperator= (const Rect &&other)
 
Rectoperator= (const float *array)
 
Rectset (float x, float y, float width, float height)
 
Rectset (const float *array)
 
Rectset (const Vec2 pos, const Size dimen)
 
Rectset (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
 
Rectoperator+= (const Rect rect)
 
Rectoperator+= (const Vec2 vec)
 
Rectoperator-= (const Vec2 vec)
 
Rectoperator*= (float scale)
 
Rectoperator*= (const Vec2 scale)
 
Rectoperator*= (const Affine2 &transform)
 
Rectoperator*= (const Mat4 &transform)
 
Rectoperator/= (float scale)
 
Rectoperator/= (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
 
Recttranslate (const Vec2 vec)
 
Recttranslate (float x, float y)
 
Rect getTranslation (const Vec2 vec) const
 
Rect getTranslation (float x, float y) const
 
Rectscale (float scale)
 
Rectscale (float sx, float sy)
 
Rectscale (const Vec2 scale)
 
Rectscale (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
 
Rectmerge (const Rect &rect)
 
Rectintersect (const Rect &rect)
 
Rectexpand (float factor)
 
Rectexpand (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)
 

Detailed Description

This class represents a rectangle area in 2D space.

It is generally safe to manipulate the fields directly.

Constructor & Destructor Documentation

◆ Rect() [1/6]

cugl::Rect::Rect ( )
inline

Creates an empty Rect at the origin

◆ Rect() [2/6]

cugl::Rect::Rect ( float  x,
float  y,
float  width,
float  height 
)
inline

Creates a rect with the given origin and dimensions.

Parameters
xThe x-coordinate of the bottom left corner
yThe y-coordinate of the bottom left corner
widthThe width of the rect
heightThe width of the rect

◆ Rect() [3/6]

cugl::Rect::Rect ( float *  array)
inline

Creates a rect from the given float array.

Parameters
arrayAn array containing the attributes in the order origin, size.

◆ Rect() [4/6]

cugl::Rect::Rect ( const Vec2  pos,
const Size  dimen 
)
inline

Creates a rect with the given origin and dimensions.

Parameters
posThe position the bottom left corner
dimenThe size of the rect

◆ Rect() [5/6]

cugl::Rect::Rect ( const Rect rect)
inline

Creates a copy of the given rectangle.

Parameters
rectThe rectangle to copy

◆ Rect() [6/6]

cugl::Rect::Rect ( const Rect &&  rect)
inline

Creates a copy of the given rectangle.

Parameters
rectThe rectangle to copy

Member Function Documentation

◆ contains() [1/3]

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 >.

Parameters
rectThe potentially smaller rect
Returns
True if this rect can hold the given rect.

◆ contains() [2/3]

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.

Parameters
centerThe center of the circle
radiusThe radius of the circle
Returns
True if this rect contains the given circle.

◆ contains() [3/3]

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().

Parameters
pointThe point to test
Returns
True if this rect contains the given point.

◆ doesIntersect() [1/2]

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.

Parameters
rectThe rect to test
Returns
true if this rect intersects the other.

◆ doesIntersect() [2/2]

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.

Parameters
centerThe center of the circle
radiusThe radius of the circle
Returns
true if this rect intersects the given circle.

◆ equals()

bool cugl::Rect::equals ( const Rect  rect,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if the rects are within tolerance of each other.

The tolerance bound is on attribute independently.

Parameters
rectThe rect to compare against.
varianceThe comparison tolerance.
Returns
true if the rects are within tolerance of each other.

◆ expand() [1/2]

Rect& cugl::Rect::expand ( const Vec2  point)

Expands this rectangle to the minimal one containing the given point.

If the rectangle already contains the point, it is unchanged.

Parameters
pointThe point to envelop
Returns
This rect, after the expansion.

◆ expand() [2/2]

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.

Parameters
factorThe amount to expand each edge from the center.
Returns
This rect, after the expansion.

◆ getExpansion() [1/2]

Rect cugl::Rect::getExpansion ( const Vec2  point) const
inline

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.

Parameters
pointThe point to envelop
Returns
a copy of this rect, expanded to contain the given point.

◆ getExpansion() [2/2]

Rect cugl::Rect::getExpansion ( float  factor) const
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.

Parameters
factorThe amount to expand each edge from the center.
Returns
a copy of this rect, expanded uniformly from its center.

◆ getIntersection()

Rect cugl::Rect::getIntersection ( const Rect rect) const
inline

Returns the intersection of this rect and the other.

If there is no intersection, this method returns the zero rectangle.

Parameters
rectThe rect to intersect with this one.

Note: This does not modify the rect.

Returns
the intersection of this rect and the other.

◆ getMaxX()

float cugl::Rect::getMaxX ( ) const
inline

Returns the rightmost x-value of the rect.

Returns
the rightmost x-value of the rect.

◆ getMaxY()

float cugl::Rect::getMaxY ( ) const
inline

Returns the top y-value of the rect.

Returns
the top y-value of the rect.

◆ getMerge()

Rect cugl::Rect::getMerge ( const Rect rect) const
inline

Returns the union of this rect and the other.

Parameters
rectThe rect to union with this one.

Note: This does not modify the rect.

Returns
the union of this rect and the other.

◆ getMidX()

float cugl::Rect::getMidX ( ) const
inline

Returns the center x-value of the rect.

Returns
the center x-value of the rect.

◆ getMidY()

float cugl::Rect::getMidY ( ) const
inline

Returns the center y-value of the rect.

Returns
the center y-value of the rect.

◆ getMinX()

float cugl::Rect::getMinX ( ) const
inline

Returns the leftmost x-value of the rect.

Returns
the leftmost x-value of the rect.

◆ getMinY()

float cugl::Rect::getMinY ( ) const
inline

Returns the bottom y-value of the rect.

Returns
the bottom y-value of the rect.

◆ getScale() [1/4]

Rect cugl::Rect::getScale ( const Vec2  scale) const

Returns the non-uniform scale of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe non-uniform scaling factor
Returns
the non-uniform scale of this rectangle.

◆ getScale() [2/4]

Rect cugl::Rect::getScale ( const Vec2  scale,
const Vec2  anchor 
) const

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.

Parameters
scaleThe non-uniform scaling factor
anchorThe anchor for the scale origin point.
Returns
the non-uniform scale of this rectangle.

◆ getScale() [3/4]

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.

Parameters
scaleThe uniform scaling factor
Returns
the uniform scale of this rectangle.

◆ getScale() [4/4]

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.

Parameters
sxThe x-axis scale factor
syThe y-axis scale factor
Returns
the non-uniform scale of this rectangle.

◆ getTranslation() [1/2]

Rect cugl::Rect::getTranslation ( const Vec2  vec) 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.

Parameters
vecThe translation vector
Returns
the translation of this rectangle by the given vector.

◆ getTranslation() [2/2]

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.

Parameters
xThe translation x amount
yThe translation y amount
Returns
the translation of this rectangle by the given vector.

◆ inside()

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 <.

Parameters
rectThe potentially larger rect
Returns
True if this rect fits inside of the given rect.

◆ intersect()

Rect& cugl::Rect::intersect ( const Rect 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.

Parameters
rectThe rect to intersect with this one.
Returns
This rect, after the intersection operation.

◆ isDegenerate()

float cugl::Rect::isDegenerate ( ) const
inline

Returns true if the rectangle has non-positive size.

Returns
true if the rectangle has non-positive size.

◆ merge()

Rect& cugl::Rect::merge ( const Rect rect)

Computes the union of this rect and the other, assigning it in place.

Parameters
rectThe rect to union with this one.
Returns
This rect, after the union operation.

◆ operator std::string()

cugl::Rect::operator std::string ( ) const
inline

Cast from Rect to a string.

◆ operator!=()

bool cugl::Rect::operator!= ( const Rect  rect) const
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.

Parameters
rectThe rect to compare against.
Returns
true if the rects are not equal to each other.

◆ operator*() [1/4]

Rect cugl::Rect::operator* ( const Affine2 transform) const
inline

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).

Parameters
transformThe affine transform
Returns
the bounding box of the transformed quadrilateral.

◆ operator*() [2/4]

Rect cugl::Rect::operator* ( const Mat4 transform) const
inline

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).

Parameters
transformThe affine transform
Returns
the bounding box of the transformed quadrilateral.

◆ operator*() [3/4]

Rect cugl::Rect::operator* ( const Vec2  scale) const
inline

Returns the non-uniform scale of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe uniform scaling factor
Returns
the non-uniform scale of this rectangle.

◆ operator*() [4/4]

Rect cugl::Rect::operator* ( float  scale) const
inline

Returns the uniform scale of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe uniform scaling factor
Returns
the uniform scale of this rectangle.

◆ operator*=() [1/4]

Rect& cugl::Rect::operator*= ( const Affine2 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).

Parameters
transformThe affine transform
Returns
This rectangle, as the bounding box of the transformed quadrilateral.

◆ operator*=() [2/4]

Rect& cugl::Rect::operator*= ( const Mat4 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).

Parameters
transformThe affine transform
Returns
This rectangle, as the bounding box of the transformed quadrilateral.

◆ operator*=() [3/4]

Rect& cugl::Rect::operator*= ( const Vec2  scale)
inline

Nonuniformly scales the size of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe non-uniform scaling factor
Returns
This rectangle, scaled non-uniformly.

◆ operator*=() [4/4]

Rect& cugl::Rect::operator*= ( float  scale)
inline

Uniformly the scales the size of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe uniform scaling factor
Returns
This rectangle, scaled uniformly.

◆ operator+() [1/2]

Rect cugl::Rect::operator+ ( const Rect  rect)
inline

Returns the union of this rect and the other.

Parameters
rectThe rect to union with this one.
Returns
the union of this rect and the other.

◆ operator+() [2/2]

Rect cugl::Rect::operator+ ( const Vec2  vec) const
inline

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.

Parameters
vecThe translation vector
Returns
the translation of this rectangle by the given vector.

◆ operator+=() [1/2]

Rect& cugl::Rect::operator+= ( const Rect  rect)
inline

Computes the union of this rect and the other, assigning it in place.

Parameters
rectThe rect to union with this one.
Returns
This rect, after the union operation.

◆ operator+=() [2/2]

Rect& cugl::Rect::operator+= ( const Vec2  vec)
inline

Translates this rectangle by the given vector.

The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.

Parameters
vecThe translation vector
Returns
This rectangle, translated.

◆ operator-()

Rect cugl::Rect::operator- ( const Vec2  vec) const
inline

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.

Parameters
vecThe inverse of the translation vector
Returns
the translation of this rectangle by subtracting the given vector.

◆ operator-=()

Rect& cugl::Rect::operator-= ( const Vec2  vec)
inline

Translates this rectangle by subtracting the given vector.

The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.

Parameters
vecThe inverse of the translation vector
Returns
This rectangle, translated.

◆ operator/() [1/2]

Rect cugl::Rect::operator/ ( const Vec2  scale) const
inline

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.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
the non-uniform scale of this rectangle by the inverse of scale.

◆ operator/() [2/2]

Rect cugl::Rect::operator/ ( float  scale) const
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.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
the uniform scale of this rectangle by the inverse of scale.

◆ operator/=() [1/2]

Rect& cugl::Rect::operator/= ( const Vec2  scale)
inline

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.

Parameters
scaleThe inverse of the non-uniform scaling factor
Returns
This rectangle, scaled non-uniformly.

◆ operator/=() [2/2]

Rect& cugl::Rect::operator/= ( float  scale)
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.

Parameters
scaleThe inverse of the uniform scaling factor
Returns
This rectangle, scaled uniformly.

◆ operator<()

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.

Parameters
rectThe potentially larger rect
Returns
True if this rect properly fits inside of the given rect.

◆ operator<=()

bool cugl::Rect::operator<= ( const Rect  rect) const
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.

Parameters
rectThe potentially larger rect
Returns
True if this rect fits inside of the given rect.

◆ operator=() [1/3]

Rect& cugl::Rect::operator= ( const float *  array)
inline

Sets the elements of this rect from the values in the specified array.

Parameters
arrayAn array containing the elements in the order origin, size.
Returns
This rectangle, after assignment

◆ operator=() [2/3]

Rect& cugl::Rect::operator= ( const Rect &&  other)
inline

Sets this rectangle to be a copy of the given one.

Parameters
otherThe rectangle to copy
Returns
This rectangle, returned for chaining

◆ operator=() [3/3]

Rect& cugl::Rect::operator= ( const Rect other)
inline

Sets this rectangle to be a copy of the given one.

Parameters
otherThe rectangle to copy
Returns
This rectangle, returned for chaining

◆ operator==()

bool cugl::Rect::operator== ( const Rect  rect) const
inline

Returns true if the rects are equal to each other.

This operator uses exact equality and may fail due to round-off error.

Parameters
rectThe rect to compare against.
Returns
true if the rects are equal to each other.

◆ operator>()

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.

Parameters
rectThe potentially smaller rect
Returns
True if this rect can properly hold the given rect.

◆ operator>=()

bool cugl::Rect::operator>= ( const Rect  rect) const
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.

Parameters
rectThe potentially smaller rect
Returns
True if this rect can hold the given rect.

◆ scale() [1/4]

Rect& cugl::Rect::scale ( const Vec2  scale)

Nonuniformly scales the size of this rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe non-uniform scaling factor
Returns
This polygon, scaled non-uniformly.

◆ scale() [2/4]

Rect& cugl::Rect::scale ( const Vec2  scale,
const Vec2  anchor 
)

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.

Parameters
scaleThe non-uniform scaling factor
anchorThe anchor for the scale origin point.
Returns
This polygon, scaled non-uniformly.

◆ scale() [3/4]

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.

Parameters
scaleThe uniform scaling factor
Returns
This rectangle, scaled uniformly.

◆ scale() [4/4]

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.

Parameters
sxThe x-axis scale factor
syThe y-axis scale factor
Returns
This polygon, scaled non-uniformly.

◆ set() [1/4]

Rect& cugl::Rect::set ( const float *  array)

Sets the elements of this rect from the values in the specified array.

Parameters
arrayAn array containing the elements in the order origin, size.
Returns
This rectangle, after assignment

◆ set() [2/4]

Rect& cugl::Rect::set ( const Rect other)

Assigns this rect to be a copy of the given rectangle.

Parameters
otherThe rectangle to copy
Returns
This rectangle, after assignment

◆ set() [3/4]

Rect& cugl::Rect::set ( const Vec2  pos,
const Size  dimen 
)

Assigns this rect to have the given position and dimensions.

Parameters
posThe position the bottom left corner
dimenThe size of the rect
Returns
This rectangle, after assignment

◆ set() [4/4]

Rect& cugl::Rect::set ( float  x,
float  y,
float  width,
float  height 
)

Assigns this rect to have the given position and dimensions.

Parameters
xThe x-coordinate of the bottom left corner
yThe y-coordinate of the bottom left corner
widthThe width of the rect
heightThe width of the rect
Returns
This rectangle, after assignment

◆ toString()

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.

Parameters
verboseWhether to include class information
Returns
a string representation of this rectangle for debuggging purposes.

◆ touches()

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.

Parameters
pointThe point to test
Returns
True if the given point is on the boundar of this rect.

◆ translate() [1/2]

Rect& cugl::Rect::translate ( const Vec2  vec)

Translates this rectangle by the given vector.

The size of the rectangle is unaffected. To alter the rectangle size, scale the rectangle.

Parameters
vecThe translation vector
Returns
This rectangle, translated.

◆ translate() [2/2]

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.

Parameters
xThe translation x amount
yThe translation y amount
Returns
This rectangle, translated.

Friends And Related Function Documentation

◆ operator* [1/2]

Rect operator* ( const Vec2  scale,
const Rect  rect 
)
friend

Returns the non-uniform scale of the rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe non-uniform scaling factor
rectThe rectangle to scale
Returns
the non-uniform scale of the rectangle.

◆ operator* [2/2]

Rect operator* ( float  scale,
const Rect  rect 
)
friend

Returns the uniform scale of the rectangle.

The origin of the rectangle is unaffected. To move the origin, translate the rectangle.

Parameters
scaleThe uniform scaling factor
rectThe rectangle to scale
Returns
the uniform scale of the rectangle.

◆ operator+

Rect operator+ ( const Vec2  vec,
const Rect  rect 
)
friend

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.

Parameters
vecThe translation vector
rectThe rectangle to translate
Returns
the translation of the rectangle by the given vector.

◆ operator-

Rect operator- ( const Vec2  vec,
const Rect  rect 
)
friend

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.

Parameters
vecThe inverse of the translation vector
rectThe rectangle to translate
Returns
the translation of the rectangle by subtracting the given vector.

Member Data Documentation

◆ origin

Vec2 cugl::Rect::origin

The bottom left point of rect.

◆ size

Size cugl::Rect::size

The width and height of the rect.

◆ UNIT

const Rect cugl::Rect::UNIT
static

The unit square.

◆ ZERO

const Rect cugl::Rect::ZERO
static

The empty Rect.


The documentation for this class was generated from the following file: