SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Rectangle Functions

Some helper functions for managing rectangles and 2D points, in both integer and floating point versions. More...

Collaboration diagram for Rectangle Functions:

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...
 

Detailed Description

Function Documentation

◆ Empty() [1/2]

constexpr bool SDL::Rect::Empty ( ) const
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).

Returns
true if the rectangle is "empty", false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ Empty() [2/2]

constexpr bool SDL::FRect::Empty ( ) const
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).

Returns
true if the rectangle is "empty", false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ Equal() [1/2]

constexpr bool SDL::FRect::Equal ( const FRectRaw other) const
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).

Parameters
otherthe second rectangle to test.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
FRect.EqualEpsilon

◆ Equal() [2/2]

constexpr bool SDL::Rect::Equal ( const RectRaw other) const
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).

Parameters
otherthe second rectangle to test.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ EqualEpsilon()

constexpr bool SDL::FRect::EqualEpsilon ( const FRectRaw other,
const float  epsilon 
) const
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).

Parameters
otherthe second rectangle to test.
epsilonthe epsilon value for comparison.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
FRect.Equal

◆ GetEnclosingPoints() [1/2]

constexpr FRect SDL::FRect::GetEnclosingPoints ( SpanRef< const FPointRaw points,
OptionalRef< const FRectRaw clip = std::nullopt 
)
staticconstexpr

If clip is not nullptr then only points inside of the clipping rectangle are considered.

Parameters
pointsa span of SDL_Point structures representing points to be enclosed.
clipan SDL_Rect used for clipping or std::nullopt to enclose all points.
Returns
a FRect structure filled in with the minimal enclosing rectangle or an empty FRect if all the points were outside of the clipping rectangle.
Since
This function is available since SDL 3.2.0.

◆ GetEnclosingPoints() [2/2]

Rect SDL::Rect::GetEnclosingPoints ( SpanRef< const PointRaw points,
OptionalRef< const RectRaw clip = std::nullopt 
)
inlinestatic

If clip is not nullptr then only points inside of the clipping rectangle are considered.

Parameters
pointsa span of SDL_Point structures representing points to be enclosed.
clipan SDL_Rect used for clipping or std::nullopt to enclose all points.
Returns
a SDL_Rect structure filled in with the minimal enclosing rectangle or an empty rect if all the points were outside of the clipping rectangle.
Since
This function is available since SDL 3.2.0.

◆ GetIntersection() [1/2]

constexpr FRect SDL::FRect::GetIntersection ( const FRectRaw other) const
constexpr

If result is nullptr then this function will return false.

Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
an SDL_Rect structure filled in with the intersection of if there is intersection, an empty FRect otherwise.
Since
This function is available since SDL 3.2.0.
See also
FRect.HasIntersection

◆ GetIntersection() [2/2]

constexpr Rect SDL::Rect::GetIntersection ( const RectRaw other) const
constexpr

If result is nullptr then this function will return false.

Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
a Rect structure filled in with the intersection of if there is intersection, std::nullopt otherwise.
Since
This function is available since SDL 3.2.0.
See also
Rect.HasIntersection

◆ GetLineIntersection() [1/2]

bool SDL::FRect::GetLineIntersection ( float *  X1,
float *  Y1,
float *  X2,
float *  Y2 
) const
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.

Parameters
X1a pointer to the starting X-coordinate of the line.
Y1a pointer to the starting Y-coordinate of the line.
X2a pointer to the ending X-coordinate of the line.
Y2a pointer to the ending Y-coordinate of the line.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ GetLineIntersection() [2/2]

bool SDL::Rect::GetLineIntersection ( int *  X1,
int *  Y1,
int *  X2,
int *  Y2 
) const
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.

Parameters
X1a pointer to the starting X-coordinate of the line.
Y1a pointer to the starting Y-coordinate of the line.
X2a pointer to the ending X-coordinate of the line.
Y2a pointer to the ending Y-coordinate of the line.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ GetRectAndLineIntersection()

bool SDL::GetRectAndLineIntersection ( const RectRaw rect,
int *  X1,
int *  Y1,
int *  X2,
int *  Y2 
)
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.

Parameters
rectan Rect structure representing the rectangle to intersect.
X1a pointer to the starting X-coordinate of the line.
Y1a pointer to the starting Y-coordinate of the line.
X2a pointer to the ending X-coordinate of the line.
Y2a pointer to the ending Y-coordinate of the line.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ GetRectAndLineIntersectionFloat()

bool SDL::GetRectAndLineIntersectionFloat ( const FRectRaw rect,
float *  X1,
float *  Y1,
float *  X2,
float *  Y2 
)
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.

Parameters
rectan FRect structure representing the rectangle to intersect.
X1a pointer to the starting X-coordinate of the line.
Y1a pointer to the starting Y-coordinate of the line.
X2a pointer to the ending X-coordinate of the line.
Y2a pointer to the ending Y-coordinate of the line.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.

◆ GetRectEnclosingPoints()

Rect SDL::GetRectEnclosingPoints ( SpanRef< const PointRaw points,
OptionalRef< const RectRaw clip = std::nullopt 
)
inline

If clip is not nullopt then only points inside of the clipping rectangle are considered.

Parameters
pointsan array of Point structures representing points to be enclosed.
clipan Rect used for clipping or nullptr to enclose all points.
Returns
Result if any points were enclosed or empty rect if all the points were outside of the clipping rectangle.
Since
This function is available since SDL 3.2.0.

◆ GetRectEnclosingPointsFloat()

constexpr FRect SDL::GetRectEnclosingPointsFloat ( SpanRef< const FPointRaw points,
OptionalRef< const FRectRaw clip = std::nullopt 
)
constexpr

If clip is not std::nullopt then only points inside of the clipping rectangle are considered.

Parameters
pointsan array of FPoint structures representing points to be enclosed.
clipan FRect used for clipping or nullptr to enclose all points.
Returns
a FRect structure filled in with the minimal enclosing rectangle or false if all the points were outside of the clipping rectangle.
Since
This function is available since SDL 3.2.0.

◆ GetRectIntersection()

constexpr Rect SDL::GetRectIntersection ( const RectRaw A,
const RectRaw B 
)
constexpr

If result is nullptr then this function will return false.

Parameters
Aan Rect structure representing the first rectangle.
Ban Rect structure representing the second rectangle.
Returns
a Rect structure filled in with the intersection of if there is intersection, std::nullopt otherwise.
Since
This function is available since SDL 3.2.0.
See also
Rect.HasIntersection

◆ GetRectIntersectionFloat()

constexpr FRect SDL::GetRectIntersectionFloat ( const FRectRaw A,
const FRectRaw B 
)
constexpr

If result is nullptr then this function will return false.

Parameters
Aan FRect structure representing the first rectangle.
Ban FRect structure representing the second rectangle.
Returns
a FRect structure filled in with the intersection of if there is intersection, std::nullopt otherwise.
Since
This function is available since SDL 3.2.0.
See also
FRect.HasIntersection

◆ GetRectUnion()

constexpr Rect SDL::GetRectUnion ( const RectRaw A,
const RectRaw B 
)
constexpr
Parameters
Aan Rect structure representing the first rectangle.
Ban Rect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.

◆ GetRectUnionFloat()

constexpr FRect SDL::GetRectUnionFloat ( const FRectRaw A,
const FRectRaw B 
)
constexpr
Parameters
Aan FRect structure representing the first rectangle.
Ban FRect structure representing the second rectangle.
Returns
a FRect structure filled in with the union of rectangles A and B.
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.

◆ GetUnion() [1/2]

constexpr FRect SDL::FRect::GetUnion ( const FRectRaw other) const
constexpr
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.

◆ GetUnion() [2/2]

constexpr Rect SDL::Rect::GetUnion ( const RectRaw other) const
constexpr
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Since
This function is available since SDL 3.2.0.

◆ HasIntersection() [1/2]

constexpr bool SDL::FRect::HasIntersection ( const FRectRaw other) const
constexpr
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
true if there is an intersection, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Rect.GetIntersection

◆ HasIntersection() [2/2]

constexpr bool SDL::Rect::HasIntersection ( const RectRaw other) const
constexpr
Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
true if there is an intersection, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Rect.GetIntersection

◆ HasRectIntersection()

constexpr bool SDL::HasRectIntersection ( const RectRaw A,
const RectRaw B 
)
constexpr

If either pointer is nullptr the function will return false.

Parameters
Aan Rect structure representing the first rectangle.
Ban Rect structure representing the second rectangle.
Returns
true if there is an intersection, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
Rect.GetIntersection

◆ HasRectIntersectionFloat()

constexpr bool SDL::HasRectIntersectionFloat ( const FRectRaw A,
const FRectRaw B 
)
constexpr

If either pointer is nullptr the function will return false.

Parameters
Aan FRect structure representing the first rectangle.
Ban FRect structure representing the second rectangle.
Returns
true if there is an intersection, false otherwise.
Since
This function is available since SDL 3.2.0.
See also
Rect.GetIntersection

◆ InRect() [1/2]

constexpr bool SDL::FPoint::InRect ( const FRectRaw r) const
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).

Parameters
rthe rectangle to test.
Returns
true if this is contained by r, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ InRect() [2/2]

constexpr bool SDL::Point::InRect ( const RectRaw r) const
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).

Parameters
rthe rectangle to test.
Returns
true if this is contained by r, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ operator SDL_FRect()

constexpr SDL::Rect::operator SDL_FRect ( ) const
constexpr
Returns
A FRect filled in with the floating point representation of rect.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ PointInRect()

constexpr bool SDL::PointInRect ( const PointRaw p,
const RectRaw r 
)
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).

Parameters
pthe point to test.
rthe rectangle to test.
Returns
true if p is contained by r, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ PointInRectFloat()

constexpr bool SDL::PointInRectFloat ( const FPointRaw p,
const FRectRaw r 
)
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).

Parameters
pthe point to test.
rthe rectangle to test.
Returns
true if p is contained by r, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ RectEmpty()

constexpr bool SDL::RectEmpty ( const RectRaw r)
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).

Parameters
rthe rectangle to test.
Returns
true if the rectangle is "empty", false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ RectEmptyFloat()

constexpr bool SDL::RectEmptyFloat ( const FRectRaw r)
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).

Parameters
rthe rectangle to test.
Returns
true if the rectangle is "empty", false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ RectsEqual()

constexpr bool SDL::RectsEqual ( const RectRaw a,
const RectRaw b 
)
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).

Parameters
athe first rectangle to test.
bthe second rectangle to test.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ RectsEqualEpsilon()

constexpr bool SDL::RectsEqualEpsilon ( const FRectRaw a,
const FRectRaw b,
const float  epsilon 
)
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).

Parameters
athe first rectangle to test.
bthe second rectangle to test.
epsilonthe epsilon value for comparison.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
FRect.Equal

◆ RectsEqualFloat()

constexpr bool SDL::RectsEqualFloat ( const FRectRaw a,
const FRectRaw b 
)
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).

Parameters
athe first rectangle to test.
bthe second rectangle to test.
Returns
true if the rectangles are equal, false otherwise.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.
See also
FRect.EqualEpsilon

◆ RectToFRect()

constexpr FRect SDL::RectToFRect ( const RectRaw rect)
constexpr
Parameters
recta pointer to an Rect.
Returns
the floating point representation of rect.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.