SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
SDL::FRect Struct Reference

A rectangle, with the origin at the upper left (using floats). More...

Inheritance diagram for SDL::FRect:
Inheritance graph
[legend]

Public Member Functions

constexpr FRect (const SDL_FRect &r={})
 Wraps FRect.
 
constexpr FRect (float x, float y, float w, float h)
 Constructs from its fields.
 
constexpr FRect (const SDL_FPoint &corner, const SDL_FPoint &size)
 Constructs from top-left corner plus size.
 
constexpr bool operator== (const FRect &other) const
 
constexpr bool operator== (const SDL_FRect &r) const
 Compares with the underlying type.
 
constexpr operator bool () const
 
constexpr float GetX () const
 Get left x coordinate.
 
constexpr FRectSetX (float newX)
 Set the left x coordinate.
 
constexpr float GetY () const
 Get top y coordinate.
 
constexpr FRectSetY (float newY)
 Set the top y coordinate.
 
constexpr float GetW () const
 Get width of the rect.
 
constexpr FRectSetW (float newW)
 Set the width of the rect.
 
constexpr float GetH () const
 Get height of the rect.
 
constexpr FRectSetH (float newH)
 Set the height of the rect.
 
constexpr float GetX2 () const
 Get X coordinate of the rect second corner.
 
constexpr FRectSetX2 (float x2)
 Set X coordinate of the rect second corner.
 
constexpr float GetY2 () const
 Get Y coordinate of the rect second corner.
 
constexpr FRectSetY2 (float y2)
 Set Y coordinate of the rect second corner.
 
constexpr FPoint GetTopLeft () const
 Get top left corner of the rect.
 
constexpr FPoint GetTopRight () const
 Get top right corner of the rect.
 
constexpr FPoint GetBottomLeft () const
 Get bottom left corner of the rect.
 
constexpr FPoint GetBottomRight () const
 Get bottom right corner of the rect.
 
constexpr FPoint GetSize () const
 Get size of the rect.
 
constexpr FPoint GetCentroid () const
 Get centroid of the rect.
 
bool IntersectLine (float *X1, float *Y1, float *X2, float *Y2) const
 Calculate the intersection of a rectangle and line segment with float precision.
 
bool IntersectLine (FPoint *p1, FPoint *p2) const
 Calculate the intersection of a rectangle and line segment.
 
constexpr bool Empty () const
 Determine whether a rectangle has no area.
 
constexpr bool EqualEpsilon (const FRect &other, const float epsilon) const
 Determine whether two floating point rectangles are equal, within some given epsilon.
 
constexpr bool Equal (const FRect &other) const
 Determine whether two rectangles are equal.
 
constexpr bool Contains (const FPoint &p) const
 Check whether the rect contains given point.
 
constexpr bool Contains (const FRect &other) const
 Check whether the rect contains given point.
 
bool HasIntersection (const FRect &other) const
 Determine whether two rectangles intersect.
 
FRect GetIntersection (const FRect &other) const
 Calculate the intersection of two rectangles with float precision.
 
FRect GetUnion (const FRect &other) const
 Calculate the union of two rectangles with float precision.
 
constexpr FRect GetExtension (unsigned int amount) const
 Get a rect extended by specified amount of pixels.
 
constexpr FRect GetExtension (float hAmount, float vAmount) const
 Get a rect extended by specified amount of pixels.
 
constexpr FRectExtend (float amount)
 Extend a rect by specified amount of pixels.
 
constexpr FRectExtend (float hAmount, float vAmount)
 Extend a rect by specified amount of pixels.
 
constexpr FRect operator+ (const FPoint &offset) const
 Get rectangle moved by a given offset.
 
constexpr FRect operator- (const FPoint &offset) const
 Get rectangle moved by an opposite of given offset.
 
constexpr FRectoperator+= (const FPoint &offset)
 Move by then given offset.
 
constexpr FRectoperator-= (const FPoint &offset)
 Move by an opposite of the given offset.
 

Static Public Member Functions

static FRect GetEnclosingPoints (SpanRef< const SDL_FPoint > points, OptionalRef< const SDL_FRect > clip=std::nullopt)
 Calculate a minimal rectangle enclosing a set of points with float precision.
 
static constexpr FRect FromCenter (float cx, float cy, float w, float h)
 Construct the rect from given center coordinates, width and height.
 
static constexpr FRect FromCenter (const FPoint &center, const FPoint &size)
 Construct the rect from given center coordinates and size.
 
static constexpr FRect FromCorners (float x1, float y1, float x2, float y2)
 Construct the rect from given corners coordinates.
 
static constexpr FRect FromCorners (const FPoint &p1, const FPoint &p2)
 Construct the rect from given centers coordinates.
 

Detailed Description

Category:
Wrap extending struct
See also
wrap-extending-struct

Constructor & Destructor Documentation

◆ FRect() [1/2]

constexpr SDL::FRect::FRect ( const SDL_FRect &  r = {})
inlineconstexpr
Parameters
rthe value to be wrapped

◆ FRect() [2/2]

constexpr SDL::FRect::FRect ( float  x,
float  y,
float  w,
float  h 
)
inlineconstexpr
Parameters
xthe left x.
ythe top y.
wthe width.
hthe height.

Member Function Documentation

◆ Contains() [1/2]

constexpr bool SDL::FRect::Contains ( const FPoint p) const
inlineconstexpr
Parameters
pPoint to check
Returns
True if the point is contained in the rect

◆ Contains() [2/2]

constexpr bool SDL::FRect::Contains ( const FRect other) const
inlineconstexpr
Parameters
otherPoint to check
Returns
True if the point is contained in the rect

◆ Empty()

constexpr bool SDL::FRect::Empty ( ) const
inlineconstexpr

A rectangle is considered "empty" for this function if r is NULL, or if r's width and/or height are <= 0.

Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).

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

constexpr bool SDL::FRect::Equal ( const FRect other) const
inlineconstexpr

Rectangles are considered equal if both are not NULL and each of their x, y, width and height match.

Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).

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 FRect other,
const float  epsilon 
) const
inlineconstexpr

Rectangles are considered equal if both are not NULL and each of their x, y, width and height are within epsilon of each other. If you don't know what value to use for epsilon, you should call the SDL_RectsEqualFloat function instead.

Note that this is a forced-inline function in a header, and not a public API function available in the SDL library (which is to say, the code is embedded in the calling program and the linker and dynamic loader will not be able to find this function inside SDL itself).

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

◆ Extend() [1/2]

constexpr FRect & SDL::FRect::Extend ( float  amount)
inlineconstexpr
Parameters
[in]amountNumber of pixels to extend by
Returns
Reference to self

◆ Extend() [2/2]

constexpr FRect & SDL::FRect::Extend ( float  hAmount,
float  vAmount 
)
inlineconstexpr
Parameters
[in]hAmountNumber of pixels to extend by in horizontal direction
[in]vAmountNumber of pixels to extend by in vertical direction
Returns
Reference to self

◆ FromCenter() [1/2]

static constexpr FRect SDL::FRect::FromCenter ( const FPoint center,
const FPoint size 
)
inlinestaticconstexpr
Parameters
[in]centerCoordinates of the rectangle center
[in]sizeDimensions of the rectangle

◆ FromCenter() [2/2]

static constexpr FRect SDL::FRect::FromCenter ( float  cx,
float  cy,
float  w,
float  h 
)
inlinestaticconstexpr
Parameters
[in]cxX coordinate of the rectangle center
[in]cyY coordinate of the rectangle center
[in]wWidth of the rectangle
[in]hHeight of the rectangle

◆ FromCorners() [1/2]

static constexpr FRect SDL::FRect::FromCorners ( const FPoint p1,
const FPoint p2 
)
inlinestaticconstexpr
Parameters
[in]p1Coordinates of the top left rectangle corner
[in]p2Coordinates of the bottom right rectangle corner

◆ FromCorners() [2/2]

static constexpr FRect SDL::FRect::FromCorners ( float  x1,
float  y1,
float  x2,
float  y2 
)
inlinestaticconstexpr
Parameters
[in]x1X coordinate of the top left rectangle corner
[in]y1Y coordinate of the top left rectangle corner
[in]x2X coordinate of the bottom right rectangle corner
[in]y2Y coordinate of the bottom right rectangle corner

◆ GetBottomLeft()

constexpr FPoint SDL::FRect::GetBottomLeft ( ) const
inlineconstexpr
Returns
bottom left corner of the rect

◆ GetBottomRight()

constexpr FPoint SDL::FRect::GetBottomRight ( ) const
inlineconstexpr
Returns
Bottom right corner of the rect

◆ GetCentroid()

constexpr FPoint SDL::FRect::GetCentroid ( ) const
inlineconstexpr
Returns
Centroid of the rect

◆ GetEnclosingPoints()

static FRect SDL::FRect::GetEnclosingPoints ( SpanRef< const SDL_FPoint >  points,
OptionalRef< const SDL_FRect >  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 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.

◆ GetExtension() [1/2]

constexpr FRect SDL::FRect::GetExtension ( float  hAmount,
float  vAmount 
) const
inlineconstexpr
Parameters
[in]hAmountNumber of pixels to extend by in horizontal direction
[in]vAmountNumber of pixels to extend by in vertical direction
Returns
Extended rect

◆ GetExtension() [2/2]

constexpr FRect SDL::FRect::GetExtension ( unsigned int  amount) const
inlineconstexpr
Parameters
[in]amountNumber of pixels to extend by
Returns
Extended rect

◆ GetH()

constexpr float SDL::FRect::GetH ( ) const
inlineconstexpr
Returns
Height of the rect

◆ GetIntersection()

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

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

◆ GetSize()

constexpr FPoint SDL::FRect::GetSize ( ) const
inlineconstexpr
Returns
Size of the rect

◆ GetTopLeft()

constexpr FPoint SDL::FRect::GetTopLeft ( ) const
inlineconstexpr
Returns
Top left corner of the rect

◆ GetTopRight()

constexpr FPoint SDL::FRect::GetTopRight ( ) const
inlineconstexpr
Returns
Top right corner of the rect

◆ GetUnion()

FRect SDL::FRect::GetUnion ( const FRect other) const
inline
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.

◆ GetW()

constexpr float SDL::FRect::GetW ( ) const
inlineconstexpr
Returns
Width of the rect

◆ GetX()

constexpr float SDL::FRect::GetX ( ) const
inlineconstexpr
Returns
coordinate of the left x

◆ GetX2()

constexpr float SDL::FRect::GetX2 ( ) const
inlineconstexpr
Returns
X coordinate of the rect second corner

◆ GetY()

constexpr float SDL::FRect::GetY ( ) const
inlineconstexpr
Returns
coordinate of the top y.

◆ GetY2()

constexpr float SDL::FRect::GetY2 ( ) const
inlineconstexpr
Returns
Y coordinate of the rect second corner

◆ HasIntersection()

bool SDL::FRect::HasIntersection ( const FRect other) const
inline
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
GetIntersection()

◆ IntersectLine() [1/2]

bool SDL::FRect::IntersectLine ( 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.

◆ IntersectLine() [2/2]

bool SDL::FRect::IntersectLine ( FPoint p1,
FPoint p2 
) const
inline
Parameters
[in,out]p1Starting coordinates of the line
[in,out]p2Ending coordinates of the line
Returns
True if there is an intersection, false otherwise

This function is used to clip a line segment to a rectangle. A line segment contained entirely within the rectangle or that does not intersect will remain unchanged. A line segment that crosses the rectangle at either or both ends will be clipped to the boundary of the rectangle and the new coordinates saved in p1 and/or p2 as necessary.

◆ operator bool()

constexpr SDL::FRect::operator bool ( ) const
inlineconstexpr
See also
Empty()

◆ operator+()

constexpr FRect SDL::FRect::operator+ ( const FPoint offset) const
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator+=()

constexpr FRect & SDL::FRect::operator+= ( const FPoint offset)
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ operator-()

constexpr FRect SDL::FRect::operator- ( const FPoint offset) const
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator-=()

constexpr FRect & SDL::FRect::operator-= ( const FPoint offset)
inlineconstexpr
Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ operator==()

constexpr bool SDL::FRect::operator== ( const FRect other) const
inlineconstexpr
See also
Equal()

◆ SetH()

constexpr FRect & SDL::FRect::SetH ( float  newH)
inlineconstexpr
Parameters
newHthe new height.
Returns
Reference to self.

◆ SetW()

constexpr FRect & SDL::FRect::SetW ( float  newW)
inlineconstexpr
Parameters
newWthe new width.
Returns
Reference to self.

◆ SetX()

constexpr FRect & SDL::FRect::SetX ( float  newX)
inlineconstexpr
Parameters
newXthe new left x.
Returns
Reference to self.

◆ SetX2()

constexpr FRect & SDL::FRect::SetX2 ( float  x2)
inlineconstexpr
Parameters
[in]x2New X coordinate value

This modifies rectangle width internally

Returns
Reference to self

◆ SetY()

constexpr FRect & SDL::FRect::SetY ( float  newY)
inlineconstexpr
Parameters
newYthe new top y.
Returns
Reference to self.

◆ SetY2()

constexpr FRect & SDL::FRect::SetY2 ( float  y2)
inlineconstexpr
Parameters
[in]y2New Y coordinate value

This modifies rectangle height internally

Returns
Reference to self

The documentation for this struct was generated from the following file: