|
SDL3pp
A slim C++ wrapper for SDL3
|
Some helper functions for managing rectangles and 2D points, in both integer and floating point versions. More...

Classes | |
| struct | SDL::Point |
| The structure that defines a point (using integers). More... | |
| struct | SDL::FPoint |
| The structure that defines a point (using floating point values). More... | |
| struct | SDL::Rect |
| A rectangle, with the origin at the upper left (using integers). More... | |
| struct | SDL::FRect |
| A rectangle, with the origin at the upper left (using floating point values). More... | |
Typedefs | |
| using | SDL::PointRaw = SDL_Point |
| Alias to raw representation for Point. | |
| using | SDL::FPointRaw = SDL_FPoint |
| Alias to raw representation for FPoint. | |
| using | SDL::RectRaw = SDL_Rect |
| Alias to raw representation for Rect. | |
| using | SDL::FRectRaw = SDL_FRect |
| Alias to raw representation for FRect. | |
Functions | |
| constexpr bool | SDL::operator== (const PointRaw &lhs, const PointRaw &rhs) |
| Comparison operator for Point. | |
| constexpr bool | SDL::operator== (const FPointRaw &lhs, const FPointRaw &rhs) |
| Comparison operator for FPoint. | |
| constexpr bool | SDL::operator== (const RectRaw &lhs, const RectRaw &rhs) |
| Comparison operator for Rect. | |
| constexpr bool | SDL::operator== (const FRectRaw &lhs, const FRectRaw &rhs) |
| Comparison operator for FRect. | |
| constexpr FRect | SDL::RectToFRect (const RectRaw &rect) |
| Convert an Rect to FRect. More... | |
| constexpr bool | SDL::PointInRect (const PointRaw &p, const RectRaw &r) |
| Determine whether a point resides inside a rectangle. More... | |
| constexpr bool | SDL::RectEmpty (const RectRaw &r) |
| Determine whether a rectangle has no area. More... | |
| constexpr bool | SDL::RectsEqual (const RectRaw &a, const RectRaw &b) |
| Determine whether two rectangles are equal. More... | |
| constexpr bool | SDL::HasRectIntersection (const RectRaw &A, const RectRaw &B) |
| Determine whether two rectangles intersect. More... | |
| constexpr Rect | SDL::GetRectIntersection (const RectRaw &A, const RectRaw &B) |
| Calculate the intersection of two rectangles. More... | |
| constexpr Rect | SDL::GetRectUnion (const RectRaw &A, const RectRaw &B) |
| Calculate the union of two rectangles. More... | |
| Rect | SDL::GetRectEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points. More... | |
| bool | SDL::GetRectAndLineIntersection (const RectRaw &rect, int *X1, int *Y1, int *X2, int *Y2) |
| Calculate the intersection of a rectangle and line segment. More... | |
| constexpr bool | SDL::PointInRectFloat (const FPointRaw &p, const FRectRaw &r) |
| Determine whether a point resides inside a floating point rectangle. More... | |
| constexpr bool | SDL::RectEmptyFloat (const FRectRaw &r) |
| Determine whether a floating point rectangle can contain any point. More... | |
| constexpr bool | SDL::RectsEqualEpsilon (const FRectRaw &a, const FRectRaw &b, const float epsilon) |
| Determine whether two floating point rectangles are equal, within some given epsilon. More... | |
| constexpr bool | SDL::RectsEqualFloat (const FRectRaw &a, const FRectRaw &b) |
| Determine whether two floating point rectangles are equal, within a default epsilon. More... | |
| constexpr bool | SDL::HasRectIntersectionFloat (const FRectRaw &A, const FRectRaw &B) |
| Determine whether two rectangles intersect with float precision. More... | |
| constexpr FRect | SDL::GetRectIntersectionFloat (const FRectRaw &A, const FRectRaw &B) |
| Calculate the intersection of two rectangles with float precision. More... | |
| constexpr FRect | SDL::GetRectUnionFloat (const FRectRaw &A, const FRectRaw &B) |
| Calculate the union of two rectangles with float precision. More... | |
| constexpr FRect | SDL::GetRectEnclosingPointsFloat (SpanRef< const FPointRaw > points, OptionalRef< const FRectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points with float precision. More... | |
| bool | SDL::GetRectAndLineIntersectionFloat (const FRectRaw &rect, float *X1, float *Y1, float *X2, float *Y2) |
| Calculate the intersection of a rectangle and line segment with float precision. More... | |
| constexpr | SDL::Rect::operator SDL_FRect () const |
| Convert an SDL_Rect to SDL_FRect. More... | |
| constexpr bool | SDL::Point::InRect (const RectRaw &r) const |
| Determine whether a point resides inside a rectangle. More... | |
| constexpr bool | SDL::Rect::Empty () const |
| Determine whether a rectangle has no area. More... | |
| constexpr bool | SDL::Rect::Equal (const RectRaw &other) const |
| Determine whether two rectangles are equal. More... | |
| constexpr bool | SDL::Rect::HasIntersection (const RectRaw &other) const |
| Determine whether two rectangles intersect. More... | |
| constexpr Rect | SDL::Rect::GetIntersection (const RectRaw &other) const |
| Calculate the intersection of two rectangles. More... | |
| constexpr Rect | SDL::Rect::GetUnion (const RectRaw &other) const |
| Calculate the union of two rectangles. More... | |
| static Rect | SDL::Rect::GetEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points. More... | |
| bool | SDL::Rect::GetLineIntersection (int *X1, int *Y1, int *X2, int *Y2) const |
| Calculate the intersection of a rectangle and line segment. More... | |
| constexpr bool | SDL::FPoint::InRect (const FRectRaw &r) const |
| Determine whether a point resides inside a floating point rectangle. More... | |
| constexpr bool | SDL::FRect::Empty () const |
| Determine whether a rectangle has no area. More... | |
| constexpr bool | SDL::FRect::EqualEpsilon (const FRectRaw &other, const float epsilon) const |
| Determine whether two floating point rectangles are equal, within some given epsilon. More... | |
| constexpr bool | SDL::FRect::Equal (const FRectRaw &other) const |
| Determine whether two rectangles are equal. More... | |
| constexpr bool | SDL::FRect::HasIntersection (const FRectRaw &other) const |
| Determine whether two rectangles intersect. More... | |
| constexpr FRect | SDL::FRect::GetIntersection (const FRectRaw &other) const |
| Calculate the intersection of two rectangles with float precision. More... | |
| constexpr FRect | SDL::FRect::GetUnion (const FRectRaw &other) const |
| Calculate the union of two rectangles with float precision. More... | |
| static constexpr FRect | SDL::FRect::GetEnclosingPoints (SpanRef< const FPointRaw > points, OptionalRef< const FRectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points with float precision. More... | |
| bool | SDL::FRect::GetLineIntersection (float *X1, float *Y1, float *X2, float *Y2) const |
| Calculate the intersection of a rectangle and line segment with float precision. More... | |
|
constexpr |
A rectangle is considered "empty" for this function if r is nullptr, 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).
|
constexpr |
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).
|
constexpr |
Rectangles are considered equal if both are not nullptr and each of their x, y, width and height are within FLT_EPSILON of each other. This is often a reasonable way to compare two floating point rectangles and deal with the slight precision variations in floating point calculations that tend to pop up.
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. |
|
constexpr |
Rectangles are considered equal if both are not nullptr 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. |
|
constexpr |
Rectangles are considered equal if both are not nullptr 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 FRect.Equal 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. |
|
staticconstexpr |
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. |
|
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. |
If result is nullptr then this function will return false.
| other | an SDL_Rect structure representing the second rectangle. |
If result is nullptr then this function will return false.
| 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. |
|
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. |
|
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.
| rect | an Rect structure representing the rectangle to intersect. |
| 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. |
|
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.
| rect | an FRect structure representing the rectangle to intersect. |
| 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. |
|
inline |
If clip is not nullopt then only points inside of the clipping rectangle are considered.
| points | an array of Point structures representing points to be enclosed. |
| clip | an Rect used for clipping or nullptr to enclose all points. |
|
constexpr |
If clip is not std::nullopt then only points inside of the clipping rectangle are considered.
| points | an array of FPoint structures representing points to be enclosed. |
| clip | an FRect used for clipping or nullptr to enclose all points. |
If result is nullptr then this function will return false.
| A | an Rect structure representing the first rectangle. |
| B | an Rect structure representing the second rectangle. |
If result is nullptr then this function will return false.
| A | an FRect structure representing the first rectangle. |
| B | an FRect structure representing the second rectangle. |
|
constexpr |
| other | an SDL_Rect structure representing the second rectangle. |
|
constexpr |
| other | an SDL_Rect structure representing the second rectangle. |
If either pointer is nullptr the function will return false.
| A | an Rect structure representing the first rectangle. |
| B | an Rect structure representing the second rectangle. |
If either pointer is nullptr the function will return false.
| A | an FRect structure representing the first rectangle. |
| B | an FRect structure representing the second rectangle. |
|
constexpr |
A point is considered part of a rectangle if both p and r are not nullptr, and p's x and y coordinates are >= to the rectangle's top left corner, and <= the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) and (0,1) as "inside" and (0,2) as not.
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).
| r | the rectangle to test. |
r, false otherwise.
|
constexpr |
A point is considered part of a rectangle if both p and r are not nullptr, and p's x and y coordinates are >= to the rectangle's top left corner, and < the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) as "inside" and (0,1) as not.
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).
| r | the rectangle to test. |
r, false otherwise.
|
constexpr |
A point is considered part of a rectangle if both p and r are not nullptr, and p's x and y coordinates are >= to the rectangle's top left corner, and < the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) as "inside" and (0,1) as not.
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).
| p | the point to test. |
| r | the rectangle to test. |
p is contained by r, false otherwise.A point is considered part of a rectangle if both p and r are not nullptr, and p's x and y coordinates are >= to the rectangle's top left corner, and <= the rectangle's x+w and y+h. So a 1x1 rectangle considers point (0,0) and (0,1) as "inside" and (0,2) as not.
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).
| p | the point to test. |
| r | the rectangle to test. |
p is contained by r, false otherwise.
|
constexpr |
A rectangle is considered "empty" for this function if r is nullptr, 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).
| r | the rectangle to test. |
|
constexpr |
A rectangle is considered "empty" for this function if r is nullptr, or if r's width and/or height are < 0.0f.
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).
| r | the rectangle to test. |
Rectangles are considered equal if both are not nullptr 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).
| a | the first rectangle to test. |
| b | the second rectangle to test. |
|
constexpr |
Rectangles are considered equal if both are not nullptr 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 FRect.Equal 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).
| a | the first rectangle to test. |
| b | the second rectangle to test. |
| epsilon | the epsilon value for comparison. |
Rectangles are considered equal if both are not nullptr and each of their x, y, width and height are within FLT_EPSILON of each other. This is often a reasonable way to compare two floating point rectangles and deal with the slight precision variations in floating point calculations that tend to pop up.
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).
| a | the first rectangle to test. |
| b | the second rectangle to test. |