|
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 stored 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) noexcept |
| Comparison operator for Point. | |
| constexpr bool | SDL::operator== (const FPointRaw &lhs, const FPointRaw &rhs) noexcept |
| Comparison operator for FPoint. | |
| bool | SDL::operator== (const RectRaw &lhs, const RectRaw &rhs) noexcept |
| Comparison operator for Rect. | |
| bool | SDL::operator== (const FRectRaw &lhs, const FRectRaw &rhs) noexcept |
| Comparison operator for FRect. | |
| constexpr auto | SDL::operator<=> (const PointRaw &lhs, const PointRaw &rhs) noexcept |
| Spaceship operator for Point. | |
| constexpr auto | SDL::operator<=> (const FPointRaw &lhs, const FPointRaw &rhs) noexcept |
| Spaceship operator for FPoint. | |
| FRect | SDL::RectToFRect (const RectRaw &rect) |
| Convert an Rect to FRect. | |
| bool | SDL::PointInRect (const PointRaw &p, const RectRaw &r) |
| Determine whether a point resides inside a rectangle. | |
| bool | SDL::RectEmpty (const RectRaw &r) |
| Determine whether a rectangle has no area. | |
| bool | SDL::RectsEqual (const RectRaw &a, const RectRaw &b) |
| Determine whether two rectangles are equal. | |
| bool | SDL::HasRectIntersection (const RectRaw &A, const RectRaw &B) |
| Determine whether two rectangles intersect. | |
| Rect | SDL::GetRectIntersection (const RectRaw &A, const RectRaw &B) |
| Calculate the intersection of two rectangles. | |
| constexpr Rect | SDL::GetRectUnion (const RectRaw &A, const RectRaw &B) |
| Calculate the union of two rectangles. | |
| Rect | SDL::GetRectEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points. | |
| bool | SDL::GetRectAndLineIntersection (const RectRaw &rect, int *X1, int *Y1, int *X2, int *Y2) |
| Calculate the intersection of a rectangle and line segment. | |
| bool | SDL::PointInRectFloat (const FPointRaw &p, const FRectRaw &r) |
| Determine whether a point resides inside a floating point rectangle. | |
| bool | SDL::RectEmptyFloat (const FRectRaw &r) |
| Determine whether a floating point rectangle takes no space. | |
| bool | SDL::RectsEqualEpsilon (const FRectRaw &a, const FRectRaw &b, const float epsilon) |
| Determine whether two floating point rectangles are equal, within some given epsilon. | |
| bool | SDL::RectsEqualFloat (const FRectRaw &a, const FRectRaw &b) |
| Determine whether two floating point rectangles are equal, within a default epsilon. | |
| bool | SDL::HasRectIntersectionFloat (const FRectRaw &A, const FRectRaw &B) |
| Determine whether two rectangles intersect with float precision. | |
| FRect | SDL::GetRectIntersectionFloat (const FRectRaw &A, const FRectRaw &B) |
| Calculate the intersection of two rectangles with float precision. | |
| constexpr FRect | SDL::GetRectUnionFloat (const FRectRaw &A, const FRectRaw &B) |
| Calculate the union of two rectangles with float precision. | |
| 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. | |
| 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. | |
| SDL::Rect::operator SDL_FRect () const | |
| Convert an SDL_Rect to SDL_FRect. | |
| bool | SDL::Point::InRect (const RectRaw &r) const |
| Determine whether a point resides inside a rectangle. | |
| bool | SDL::Rect::Empty () const |
| Determine whether a rectangle has no area. | |
| bool | SDL::Rect::Equal (const RectRaw &other) const |
| Determine whether two rectangles are equal. | |
| bool | SDL::Rect::HasIntersection (const RectRaw &other) const |
| Determine whether two rectangles intersect. | |
| Rect | SDL::Rect::GetIntersection (const RectRaw &other) const |
| Calculate the intersection of two rectangles. | |
| constexpr Rect | SDL::Rect::GetUnion (const RectRaw &other) const |
| Calculate the union of two rectangles. | |
| static Rect | SDL::Rect::GetEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt) |
| Calculate a minimal rectangle enclosing a set of points. | |
| bool | SDL::Rect::GetLineIntersection (int *X1, int *Y1, int *X2, int *Y2) const |
| Calculate the intersection of a rectangle and line segment. | |
| bool | SDL::FPoint::InRect (const FRectRaw &r) const |
| Determine whether a point resides inside a floating point rectangle. | |
| bool | SDL::FRect::Empty () const |
| Determine whether a rectangle has no area. | |
| bool | SDL::FRect::EqualEpsilon (const FRectRaw &other, const float epsilon) const |
| Determine whether two floating point rectangles are equal, within some given epsilon. | |
| bool | SDL::FRect::Equal (const FRectRaw &other) const |
| Determine whether two floating point rectangles are equal, within a default epsilon. | |
| bool | SDL::FRect::HasIntersection (const FRectRaw &other) const |
| Determine whether two rectangles intersect with float precision. | |
| FRect | SDL::FRect::GetIntersection (const FRectRaw &other) const |
| Calculate the intersection of two rectangles with float precision. | |
| constexpr FRect | SDL::FRect::GetUnion (const FRectRaw &other) const |
| Calculate the union of two rectangles with float precision. | |
| static 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. | |
| 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. | |
Some helper functions for managing rectangles and 2D points, in both integer and floating point versions.
|
inline |
Determine whether a rectangle has no area.
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).
|
inline |
Determine whether a rectangle has no area.
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).
|
inline |
Determine whether two floating point rectangles are equal, within a default epsilon.
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. |
|
inline |
Determine whether two rectangles are equal.
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. |
|
inline |
Determine whether two floating point rectangles are equal, within some given epsilon.
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. |
|
inlinestatic |
Calculate a minimal rectangle enclosing a set of points with float precision.
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 |
Calculate a minimal rectangle enclosing a set of points.
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. |
Calculate the intersection of two rectangles with float precision.
If result is nullptr then this function will return false.
| other | an FRect structure representing the second rectangle. |
Calculate the intersection of two rectangles.
If result is nullptr then this function will return false.
| other | an SDL_Rect structure representing the second rectangle. |
|
inline |
Calculate the intersection of a rectangle and line segment with float precision.
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 |
Calculate the intersection of a rectangle and line segment.
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 |
Calculate the intersection of a rectangle and line segment.
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 |
Calculate the intersection of a rectangle and line segment with float precision.
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 |
Calculate a minimal rectangle enclosing a set of points.
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. |
|
inline |
Calculate a minimal rectangle enclosing a set of points with float precision.
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. |
Calculate the intersection of two rectangles.
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. |
Calculate the intersection of two rectangles with float precision.
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. |
Calculate the union of two rectangles.
| A | an Rect structure representing the first rectangle. |
| B | an Rect structure representing the second rectangle. |
| Error | on failure. |
Calculate the union of two rectangles with float precision.
| A | an FRect structure representing the first rectangle. |
| B | an FRect structure representing the second rectangle. |
| Error | on failure. |
Calculate the union of two rectangles with float precision.
| other | an FRect structure representing the second rectangle. |
| Error | on failure. |
Calculate the union of two rectangles.
| other | an SDL_Rect structure representing the second rectangle. |
| Error | on failure. |
|
inline |
Determine whether two rectangles intersect with float precision.
| other | an FRect structure representing the second rectangle. |
|
inline |
Determine whether two rectangles intersect.
| other | an SDL_Rect structure representing the second rectangle. |
Determine whether two rectangles intersect.
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. |
Determine whether two rectangles intersect with float precision.
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. |
|
inline |
Determine whether a point resides inside a floating point rectangle.
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. |
|
inline |
Determine whether a point resides inside a rectangle.
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. |
|
inline |
Determine whether a point resides inside a rectangle.
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. |
Determine whether a point resides inside a floating point rectangle.
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. |
|
inline |
Determine whether a rectangle has no area.
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. |
|
inline |
Determine whether a floating point rectangle takes no space.
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. |
Determine whether two rectangles are equal.
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. |
Determine whether two floating point rectangles are equal, within some given epsilon.
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. |
Determine whether two floating point rectangles are equal, within a default epsilon.
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. |