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

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.

Detailed Description

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

Function Documentation

◆ Empty() [1/2]

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

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]

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

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]

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

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]

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

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()

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

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]

FRect SDL::FRect::GetEnclosingPoints ( SpanRef< const FPointRaw > points,
OptionalRef< const FRectRaw > clip = std::nullopt )
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.

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.
Thread safety:
It is safe to call this function from any thread.
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

Calculate a minimal rectangle enclosing a set of points.

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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetIntersection() [1/2]

FRect SDL::FRect::GetIntersection ( const FRectRaw & other) const
inline

Calculate the intersection of two rectangles with float precision.

If result is nullptr then this function will return false.

Parameters
otheran FRect structure representing the second rectangle.
Returns
an FRect structure filled in with the intersection of if there is intersection, an empty FRect 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.HasIntersection

◆ GetIntersection() [2/2]

Rect SDL::Rect::GetIntersection ( const RectRaw & other) const
inline

Calculate the intersection of two rectangles.

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

◆ GetLineIntersection() [1/2]

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

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.
Thread safety:
It is safe to call this function from any thread.
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

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.

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.
Thread safety:
It is safe to call this function from any thread.
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

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.

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.
Thread safety:
It is safe to call this function from any thread.
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

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.

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.
Thread safety:
It is safe to call this function from any thread.
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

Calculate a minimal rectangle enclosing a set of points.

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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetRectEnclosingPointsFloat()

FRect SDL::GetRectEnclosingPointsFloat ( SpanRef< const FPointRaw > points,
OptionalRef< const FRectRaw > clip = std::nullopt )
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.

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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetRectIntersection()

Rect SDL::GetRectIntersection ( const RectRaw & A,
const RectRaw & B )
inline

Calculate the intersection of two rectangles.

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

◆ GetRectIntersectionFloat()

FRect SDL::GetRectIntersectionFloat ( const FRectRaw & A,
const FRectRaw & B )
inline

Calculate the intersection of two rectangles with float precision.

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

◆ GetRectUnion()

Rect SDL::GetRectUnion ( const RectRaw & A,
const RectRaw & B )
constexpr

Calculate the union of two rectangles.

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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetRectUnionFloat()

FRect SDL::GetRectUnionFloat ( const FRectRaw & A,
const FRectRaw & B )
constexpr

Calculate the union of two rectangles with float precision.

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.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetUnion() [1/2]

FRect SDL::FRect::GetUnion ( const FRectRaw & other) const
constexpr

Calculate the union of two rectangles with float precision.

Parameters
otheran FRect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ GetUnion() [2/2]

Rect SDL::Rect::GetUnion ( const RectRaw & other) const
constexpr

Calculate the union of two rectangles.

Parameters
otheran SDL_Rect structure representing the second rectangle.
Returns
Rect representing union of two rectangles
Exceptions
Erroron failure.
Thread safety:
It is safe to call this function from any thread.
Since
This function is available since SDL 3.2.0.

◆ HasIntersection() [1/2]

bool SDL::FRect::HasIntersection ( const FRectRaw & other) const
inline

Determine whether two rectangles intersect with float precision.

Parameters
otheran FRect 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
FRect.GetIntersection

◆ HasIntersection() [2/2]

bool SDL::Rect::HasIntersection ( const RectRaw & other) const
inline

Determine whether two rectangles intersect.

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()

bool SDL::HasRectIntersection ( const RectRaw & A,
const RectRaw & B )
inline

Determine whether two rectangles intersect.

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()

bool SDL::HasRectIntersectionFloat ( const FRectRaw & A,
const FRectRaw & B )
inline

Determine whether two rectangles intersect with float precision.

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

◆ InRect() [1/2]

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

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]

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

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()

SDL::Rect::operator SDL_FRect ( ) const
inline

Convert an SDL_Rect to SDL_FRect.

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()

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

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()

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

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()

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

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()

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

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()

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

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()

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

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()

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

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()

FRect SDL::RectToFRect ( const RectRaw & rect)
inline

Convert an Rect to FRect.

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.