Rect Class Reference

Class defining a 2D rectangle with top-left corner coordinates and width/height in pixels. More...

Functions

 Rect (size_t x_=0, size_t y_=0, size_t w_=0, size_t h_=0)
 Default constructor. More...
 
size_t area ()
 Returns the area of the rectangle. More...
 
bool operator== (const Rect &that) const
 Tests if the given sl::Rect has the same properties. More...
 
bool operator!= (const Rect &that) const
 Tests if the given sl::Rect has different properties. More...
 
bool isEmpty () const
 Tests if the given sl::Rect is empty (width or/and height is null). More...
 
bool contains (const Rect &target, bool proper=false) const
 Tests if this sl::Rect contains the target sl::Rect. More...
 
bool isContained (const Rect &target, bool proper=false) const
 Tests if this sl::Rect is contained inside the given target sl::Rect. More...
 
bool isContained (const Resolution &resolution, bool proper=false) const
 Overloaded method of isContained(). Tests if this sl::Rect is contained inside a given sl::Resolution. More...
 

Attributes

size_t x
 x coordinates of top-left corner. More...
 
size_t y
 y coordinates of top-left corner. More...
 
size_t width
 Width of the rectangle in pixels. More...
 
size_t height
 Height of the rectangle in pixels. More...
 

Detailed Description

Class defining a 2D rectangle with top-left corner coordinates and width/height in pixels.

Constructor and Destructor

◆ Rect()

Rect ( size_t  x_ = 0,
size_t  y_ = 0,
size_t  w_ = 0,
size_t  h_ = 0 
)
inline

Default constructor.

Functions

◆ area()

size_t area ( )
inline

Returns the area of the rectangle.

◆ operator==()

bool operator== ( const Rect &  that) const
inline

Tests if the given sl::Rect has the same properties.

Returns
True if all the components matches.

◆ operator!=()

bool operator!= ( const Rect &  that) const
inline

Tests if the given sl::Rect has different properties.

Returns
True if one of the components does not match.

◆ isEmpty()

bool isEmpty ( ) const
inline

Tests if the given sl::Rect is empty (width or/and height is null).

◆ contains()

bool contains ( const Rect &  target,
bool  proper = false 
) const
inline

Tests if this sl::Rect contains the target sl::Rect.

Returns
true if this rectangle contains the target rectangle, otherwise false.
Note
By default (proper false) a target whose edges land exactly on this rectangle's edges is contained. Pass proper true to require a strict interior and exclude the edge.

◆ isContained() [1/2]

bool isContained ( const Rect &  target,
bool  proper = false 
) const
inline

Tests if this sl::Rect is contained inside the given target sl::Rect.

Returns
true if this rectangle is inside the current target sl::Rect, otherwise false.
Note
By default (proper false) a rectangle whose edges land exactly on the target's edges is contained. Pass proper true to require a strict interior and exclude the edge.

◆ isContained() [2/2]

bool isContained ( const Resolution &  resolution,
bool  proper = false 
) const
inline

Overloaded method of isContained(). Tests if this sl::Rect is contained inside a given sl::Resolution.

It tests if the current rectangle is contained inside a sl::Rect defined by Rect(0, 0, resolution.width, resolution.height).

Returns
true if this rectangle is inside the rectangle defined by Rect(0, 0, resolution.width, resolution.height), otherwise false.
Note
By default (proper false) a rectangle whose far edge lands exactly on the resolution is contained, since the last valid column is width - 1. Pass proper true to require a strict interior and exclude the edge.

Variables

◆ x

size_t x

x coordinates of top-left corner.

Referenced by Rect::contains(), Rect::isContained(), Rect::operator!=(), and Rect::operator==().

◆ y

size_t y

y coordinates of top-left corner.

Referenced by Rect::contains(), Rect::isContained(), Rect::operator!=(), and Rect::operator==().

◆ width

size_t width

Width of the rectangle in pixels.

Referenced by Rect::contains(), Rect::isContained(), Rect::operator!=(), and Rect::operator==().

◆ height

size_t height

Height of the rectangle in pixels.

Referenced by Rect::contains(), Rect::isContained(), Rect::operator!=(), and Rect::operator==().