libSDL2pp
C++ bindings/wrapper for SDL2
|
2D rectangle More...
#include <SDL2pp/Rect.hh>
Public Member Functions | |
constexpr | Rect () |
Default constructor. | |
constexpr | Rect (const SDL_Rect &rect) |
Construct a rect from existing SDL_Rect. | |
constexpr | Rect (const Point &corner, const Point &size) |
Construct the rect from given corner coordinates, and size. | |
constexpr | Rect (int x, int y, int w, int h) |
Construct the rect from given corner coordinates, width and height. | |
Rect (const Rect &) noexcept=default | |
Copy constructor. | |
Rect (Rect &&) noexcept=default | |
Move constructor. | |
Rect & | operator= (const Rect &) noexcept=default |
Assignment operator. | |
Rect & | operator= (Rect &&) noexcept=default |
Move assignment operator. | |
constexpr int | GetX () const |
Get X coordinate of the rect corner. | |
Rect & | SetX (int nx) |
Set X coordinate of the rect corner. | |
constexpr int | GetY () const |
Get Y coordinate of the rect corner. | |
Rect & | SetY (int ny) |
Set Y coordinate of the rect corner. | |
constexpr int | GetW () const |
Get width of the rect. | |
Rect & | SetW (int nw) |
Set width of the rect. | |
constexpr int | GetH () const |
Get height of the rect. | |
Rect & | SetH (int nh) |
Set height of the rect. | |
constexpr int | GetX2 () const |
Get X coordinate of the rect second corner. | |
Rect & | SetX2 (int x2) |
Set X coordinate of the rect second corner. | |
constexpr int | GetY2 () const |
Get Y coordinate of the rect second corner. | |
Rect & | SetY2 (int y2) |
Set Y coordinate of the rect second corner. | |
constexpr Point | GetTopLeft () const |
Get top left corner of the rect. | |
constexpr Point | GetTopRight () const |
Get top right corner of the rect. | |
constexpr Point | GetBottomLeft () const |
Get bottom left corner of the rect. | |
constexpr Point | GetBottomRight () const |
Get bottom right corner of the rect. | |
constexpr Point | GetSize () const |
Get size of the rect. | |
constexpr Point | GetCentroid () const |
Get centroid of the rect. | |
constexpr bool | Contains (int px, int py) const |
Check whether the rect contains given point. | |
constexpr bool | Contains (const Point &point) const |
Check whether the rect contains given point. | |
constexpr bool | Contains (const Rect &rect) const |
Check whether the rect contains another rect. | |
constexpr bool | Intersects (const Rect &rect) const |
Check whether the rect intersects another rect. | |
Rect | GetUnion (const Rect &rect) const |
Calculate union with another rect. | |
Rect & | Union (const Rect &rect) |
Union rect with another rect. | |
Rect | GetExtension (unsigned int amount) const |
Get a rect extended by specified amount of pixels. | |
Rect | GetExtension (unsigned int hamount, unsigned int vamount) const |
Get a rect extended by specified amount of pixels. | |
Rect & | Extend (unsigned int amount) |
Extend a rect by specified amount of pixels. | |
Rect & | Extend (unsigned int hamount, unsigned int vamount) |
Extend a rect by specified amount of pixels. | |
Optional< Rect > | GetIntersection (const Rect &rect) const |
Calculate intersection with another rect. | |
bool | IntersectLine (int &x1, int &y1, int &x2, int &y2) const |
Calculate the intersection of a rectangle and line segment. | |
bool | IntersectLine (Point &p1, Point &p2) const |
Calculate the intersection of a rectangle and line segment. | |
constexpr Rect | operator+ (const Point &offset) const |
Get rectangle moved by a given offset. | |
constexpr Rect | operator- (const Point &offset) const |
Get rectangle moved by an opposite of given offset. | |
Rect & | operator+= (const Point &offset) |
Move by then given offset. | |
Rect & | operator-= (const Point &offset) |
Move by an opposite of the given offset. | |
Static Public Member Functions | |
static constexpr Rect | FromCenter (int cx, int cy, int w, int h) |
Construct the rect from given center coordinates, width and height. | |
static constexpr Rect | FromCenter (const Point ¢er, const Point &size) |
Construct the rect from given center coordinates and size. | |
static constexpr Rect | FromCorners (int x1, int y1, int x2, int y2) |
Construct the rect from given corners coordinates. | |
static constexpr Rect | FromCorners (const Point &p1, const Point &p2) |
Construct the rect from given centers coordinates. | |
2D rectangle
This class is public-derived from SDL_Rect structure, may generally used as it if passed via pointer or reference. It also supports direct access to x, y, w and h members.
|
inlineconstexpr |
Default constructor.
Creates a Rect(0, 0, 0, 0)
|
inlineconstexpr |
Construct a rect from existing SDL_Rect.
[in] | rect | Existing SDL_Rect |
Construct the rect from given corner coordinates, and size.
[in] | corner | Coordinates of the top left rectangle corner |
[in] | size | Dimensions of the rectangle |
|
inlineconstexpr |
Construct the rect from given corner coordinates, width and height.
[in] | x | X coordinate of the top left rectangle corner |
[in] | y | Y coordinate of the top left rectangle corner |
[in] | w | Width of the rectangle |
[in] | h | Height of the rectangle |
|
defaultnoexcept |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
inlineconstexpr |
Check whether the rect contains given point.
[in] | point | Point to check |
|
inlineconstexpr |
Check whether the rect contains another rect.
[in] | rect | Rect to check |
|
inlineconstexpr |
Check whether the rect contains given point.
[in] | px | X coordinate of a point |
[in] | py | Y coordinate of a point |
Rect & SDL2pp::Rect::Extend | ( | unsigned int | amount | ) |
Extend a rect by specified amount of pixels.
[in] | amount | Number of pixels to extend by |
Rect & SDL2pp::Rect::Extend | ( | unsigned int | hamount, |
unsigned int | vamount | ||
) |
Extend a rect by specified amount of pixels.
[in] | hamount | Number of pixels to extend by in horizontal direction |
[in] | vamount | Number of pixels to extend by in vertical direction |
|
inlinestaticconstexpr |
Construct the rect from given center coordinates and size.
[in] | center | Coordinates of the rectangle center |
[in] | size | Dimensions of the rectangle |
|
inlinestaticconstexpr |
Construct the rect from given center coordinates, width and height.
[in] | cx | X coordinate of the rectangle center |
[in] | cy | Y coordinate of the rectangle center |
[in] | w | Width of the rectangle |
[in] | h | Height of the rectangle |
|
inlinestaticconstexpr |
Construct the rect from given centers coordinates.
[in] | p1 | Coordinates of the top left rectangle corner |
[in] | p2 | Coordinates of the bottom right rectangle corner |
|
inlinestaticconstexpr |
Construct the rect from given corners coordinates.
[in] | x1 | X coordinate of the top left rectangle corner |
[in] | y1 | Y coordinate of the top left rectangle corner |
[in] | x2 | X coordinate of the bottom right rectangle corner |
[in] | y2 | Y coordinate of the bottom right rectangle corner |
|
inlineconstexpr |
Get bottom left corner of the rect.
|
inlineconstexpr |
Get bottom right corner of the rect.
|
inlineconstexpr |
Get centroid of the rect.
Rect SDL2pp::Rect::GetExtension | ( | unsigned int | amount | ) | const |
Get a rect extended by specified amount of pixels.
[in] | amount | Number of pixels to extend by |
Rect SDL2pp::Rect::GetExtension | ( | unsigned int | hamount, |
unsigned int | vamount | ||
) | const |
Get a rect extended by specified amount of pixels.
[in] | hamount | Number of pixels to extend by in horizontal direction |
[in] | vamount | Number of pixels to extend by in vertical direction |
|
inlineconstexpr |
Get height of the rect.
|
inlineconstexpr |
Get size of the rect.
|
inlineconstexpr |
Get top left corner of the rect.
|
inlineconstexpr |
Get top right corner of the rect.
|
inlineconstexpr |
Get width of the rect.
|
inlineconstexpr |
Get X coordinate of the rect corner.
|
inlineconstexpr |
Get X coordinate of the rect second corner.
|
inlineconstexpr |
Get Y coordinate of the rect corner.
|
inlineconstexpr |
Get Y coordinate of the rect second corner.
bool SDL2pp::Rect::IntersectLine | ( | int & | x1, |
int & | y1, | ||
int & | x2, | ||
int & | y2 | ||
) | const |
Calculate the intersection of a rectangle and line segment.
[in,out] | x1 | Starting X-coordinate of the line |
[in,out] | y1 | Starting Y-coordinate of the line |
[in,out] | x2 | Ending X-coordinate of the line |
[in,out] | y2 | Ending Y-coordinate of the line |
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in x1, y1, x2, and/or y2 as necessary.
Calculate the intersection of a rectangle and line segment.
[in,out] | p1 | Starting coordinates of the line |
[in,out] | p2 | Ending coordinates of the line |
This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in p1 and/or p2 as necessary.
|
inlineconstexpr |
Check whether the rect intersects another rect.
[in] | rect | Rect to check |
Get rectangle moved by a given offset.
[in] | offset | Point specifying an offset |
Get rectangle moved by an opposite of given offset.
[in] | offset | Point specifying an offset |
Move by an opposite of the given offset.
[in] | offset | Point specifying an offset |
Assignment operator.
Move assignment operator.
|
inline |
Set height of the rect.
[in] | nh | New height of the rect |
|
inline |
Set width of the rect.
[in] | nw | New width of the rect |
|
inline |
Set X coordinate of the rect corner.
[in] | nx | New X coordinate value |
|
inline |
Set X coordinate of the rect second corner.
[in] | x2 | New X coordinate value |
This modifies rectangle width internally
|
inline |
Set Y coordinate of the rect corner.
[in] | ny | New Y coordinate value |
|
inline |
Set Y coordinate of the rect second corner.
[in] | y2 | New Y coordinate value |
This modifies rectangle height internally