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 floating point values). More...

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

Public Member Functions

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

Static Public Member Functions

static constexpr 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...
 
static constexpr FRect FromCenter (float cx, float cy, float w, float h)
 Construct the rect from given center coordinates, width and height. More...
 
static constexpr FRect FromCenter (FPoint center, FPoint size)
 Construct the rect from given center coordinates and size. More...
 
static constexpr FRect FromCorners (float x1, float y1, float x2, float y2)
 Construct the rect from given corners coordinates. More...
 
static constexpr FRect FromCorners (FPoint p1, FPoint p2)
 Construct the rect from given centers coordinates. More...
 

Detailed Description

Since
This struct is available since SDL 3.2.0.
Category:
Wrap extending struct
See also
FRect.Empty
FRect.Equal
FRect.EqualEpsilon
FRect.HasIntersection
FRect.GetIntersection
FRect.GetLineIntersection
FRect.GetUnion
FRect.GetEnclosingPoints
FPoint.InRect

Constructor & Destructor Documentation

◆ FRect() [1/2]

constexpr SDL::FRect::FRect ( const FRectRaw 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 FPointRaw 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 FRectRaw other) const
inlineconstexpr
Parameters
otherPoint to check
Returns
True if the point is contained in the rect

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

◆ FromCenter() [2/2]

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

◆ FromCorners() [1/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

◆ FromCorners() [2/2]

static constexpr FRect SDL::FRect::FromCorners ( FPoint  p1,
FPoint  p2 
)
inlinestaticconstexpr
Parameters
[in]p1Coordinates of the top left rectangle corner
[in]p2Coordinates 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

◆ 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

◆ GetLineIntersection()

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

◆ 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

◆ 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

◆ 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

◆ 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: