SDL3pp
A slim C++ wrapper for SDL3
|
A rectangle, with the origin at the upper left (using floats). More...
Public Member Functions | |
constexpr | FRect (const SDL_FRect &r={}) |
Wraps FRect. | |
constexpr | FRect (float x, float y, float w, float h) |
Constructs from its fields. | |
constexpr | FRect (const SDL_FPoint &corner, const SDL_FPoint &size) |
Constructs from top-left corner plus size. | |
constexpr bool | operator== (const FRect &other) const |
constexpr bool | operator== (const SDL_FRect &r) const |
Compares with the underlying type. | |
constexpr | operator bool () const |
constexpr float | GetX () const |
Get left x coordinate. | |
constexpr FRect & | SetX (float newX) |
Set the left x coordinate. | |
constexpr float | GetY () const |
Get top y coordinate. | |
constexpr FRect & | SetY (float newY) |
Set the top y coordinate. | |
constexpr float | GetW () const |
Get width of the rect. | |
constexpr FRect & | SetW (float newW) |
Set the width of the rect. | |
constexpr float | GetH () const |
Get height of the rect. | |
constexpr FRect & | SetH (float newH) |
Set the height of the rect. | |
constexpr float | GetX2 () const |
Get X coordinate of the rect second corner. | |
constexpr FRect & | SetX2 (float x2) |
Set X coordinate of the rect second corner. | |
constexpr float | GetY2 () const |
Get Y coordinate of the rect second corner. | |
constexpr FRect & | SetY2 (float y2) |
Set Y coordinate of the rect second corner. | |
constexpr FPoint | GetTopLeft () const |
Get top left corner of the rect. | |
constexpr FPoint | GetTopRight () const |
Get top right corner of the rect. | |
constexpr FPoint | GetBottomLeft () const |
Get bottom left corner of the rect. | |
constexpr FPoint | GetBottomRight () const |
Get bottom right corner of the rect. | |
constexpr FPoint | GetSize () const |
Get size of the rect. | |
constexpr FPoint | GetCentroid () const |
Get centroid of the rect. | |
bool | IntersectLine (float *X1, float *Y1, float *X2, float *Y2) const |
Calculate the intersection of a rectangle and line segment with float precision. | |
bool | IntersectLine (FPoint *p1, FPoint *p2) const |
Calculate the intersection of a rectangle and line segment. | |
constexpr bool | Empty () const |
Determine whether a rectangle has no area. | |
constexpr bool | EqualEpsilon (const FRect &other, const float epsilon) const |
Determine whether two floating point rectangles are equal, within some given epsilon. | |
constexpr bool | Equal (const FRect &other) const |
Determine whether two rectangles are equal. | |
constexpr bool | Contains (const FPoint &p) const |
Check whether the rect contains given point. | |
constexpr bool | Contains (const FRect &other) const |
Check whether the rect contains given point. | |
bool | HasIntersection (const FRect &other) const |
Determine whether two rectangles intersect. | |
FRect | GetIntersection (const FRect &other) const |
Calculate the intersection of two rectangles with float precision. | |
FRect | GetUnion (const FRect &other) const |
Calculate the union of two rectangles with float precision. | |
constexpr FRect | GetExtension (unsigned int amount) const |
Get a rect extended by specified amount of pixels. | |
constexpr FRect | GetExtension (float hAmount, float vAmount) const |
Get a rect extended by specified amount of pixels. | |
constexpr FRect & | Extend (float amount) |
Extend a rect by specified amount of pixels. | |
constexpr FRect & | Extend (float hAmount, float vAmount) |
Extend a rect by specified amount of pixels. | |
constexpr FRect | operator+ (const FPoint &offset) const |
Get rectangle moved by a given offset. | |
constexpr FRect | operator- (const FPoint &offset) const |
Get rectangle moved by an opposite of given offset. | |
constexpr FRect & | operator+= (const FPoint &offset) |
Move by then given offset. | |
constexpr FRect & | operator-= (const FPoint &offset) |
Move by an opposite of the given offset. | |
Static Public Member Functions | |
static FRect | GetEnclosingPoints (SpanRef< const SDL_FPoint > points, OptionalRef< const SDL_FRect > clip=std::nullopt) |
Calculate a minimal rectangle enclosing a set of points with float precision. | |
static constexpr FRect | FromCenter (float cx, float cy, float w, float h) |
Construct the rect from given center coordinates, width and height. | |
static constexpr FRect | FromCenter (const FPoint ¢er, const FPoint &size) |
Construct the rect from given center coordinates and size. | |
static constexpr FRect | FromCorners (float x1, float y1, float x2, float y2) |
Construct the rect from given corners coordinates. | |
static constexpr FRect | FromCorners (const FPoint &p1, const FPoint &p2) |
Construct the rect from given centers coordinates. | |
|
inlineconstexpr |
r | the value to be wrapped |
|
inlineconstexpr |
x | the left x. |
y | the top y. |
w | the width. |
h | the height. |
|
inlineconstexpr |
p | Point to check |
|
inlineconstexpr |
other | Point to check |
|
inlineconstexpr |
A rectangle is considered "empty" for this function if r
is NULL, or if r
's width and/or height are <= 0.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
|
inlineconstexpr |
Rectangles are considered equal if both are not NULL and each of their x, y, width and height match.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
other | the second rectangle to test. |
|
inlineconstexpr |
Rectangles are considered equal if both are not NULL and each of their x, y, width and height are within epsilon
of each other. If you don't know what value to use for epsilon
, you should call the SDL_RectsEqualFloat function instead.
Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).
other | the second rectangle to test. |
epsilon | the epsilon value for comparison. |
|
inlineconstexpr |
[in] | amount | Number of pixels to extend by |
|
inlineconstexpr |
[in] | hAmount | Number of pixels to extend by in horizontal direction |
[in] | vAmount | Number of pixels to extend by in vertical direction |
|
inlinestaticconstexpr |
[in] | center | Coordinates of the rectangle center |
[in] | size | Dimensions of the rectangle |
|
inlinestaticconstexpr |
[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 |
[in] | p1 | Coordinates of the top left rectangle corner |
[in] | p2 | Coordinates of the bottom right rectangle corner |
|
inlinestaticconstexpr |
[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 |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlinestatic |
If clip
is not nullptr then only points inside of the clipping rectangle are considered.
points | a span of SDL_Point structures representing points to be enclosed. |
clip | an SDL_Rect used for clipping or std::nullopt to enclose all points. |
|
inlineconstexpr |
[in] | hAmount | Number of pixels to extend by in horizontal direction |
[in] | vAmount | Number of pixels to extend by in vertical direction |
|
inlineconstexpr |
[in] | amount | Number of pixels to extend by |
|
inlineconstexpr |
If result
is nullptr then this function will return false.
other | an SDL_Rect structure representing the second rectangle. |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inline |
other | an SDL_Rect structure representing the second rectangle. |
|
inline |
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.
X1 | a pointer to the starting X-coordinate of the line. |
Y1 | a pointer to the starting Y-coordinate of the line. |
X2 | a pointer to the ending X-coordinate of the line. |
Y2 | a pointer to the ending Y-coordinate of the line. |
[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 |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
[in] | offset | Point specifying an offset |
|
inlineconstexpr |
newH | the new height. |
|
inlineconstexpr |
newW | the new width. |
|
inlineconstexpr |
newX | the new left x. |
|
inlineconstexpr |
[in] | x2 | New X coordinate value |
This modifies rectangle width internally
|
inlineconstexpr |
newY | the new top y. |
|
inlineconstexpr |
[in] | y2 | New Y coordinate value |
This modifies rectangle height internally