SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL::FRect Struct Reference

A rectangle stored using floating point values. More...

Inheritance diagram for SDL::FRect:
[legend]

Public Member Functions

constexpr FRect (const FRectRaw &r={}) noexcept
 Wraps FRect.
constexpr FRect (float x, float y, float w, float h) noexcept
 Constructs from its fields.
constexpr FRect (const FPointRaw &corner, const FPointRaw &size)
 Constructs from top-left corner plus size.
 operator bool () const
constexpr float GetX () const noexcept
 Get left x coordinate.
constexpr FRectSetX (float newX) noexcept
 Set the left x coordinate.
constexpr float GetY () const noexcept
 Get top y coordinate.
constexpr FRectSetY (float newY) noexcept
 Set the top y coordinate.
constexpr float GetW () const noexcept
 Get width of the rect.
constexpr FRectSetW (float newW) noexcept
 Set the width of the rect.
constexpr float GetH () const noexcept
 Get height of the rect.
constexpr FRectSetH (float newH) noexcept
 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 GetLineIntersection (float *X1, float *Y1, float *X2, float *Y2) const
 Calculate the intersection of a rectangle and line segment with float precision.
bool GetLineIntersection (FPoint *p1, FPoint *p2) const
 Determine whether a floating point rectangle takes no space.
bool Empty () const
 Determine whether a rectangle has no area.
bool EqualEpsilon (const FRectRaw &other, const float epsilon) const
 Determine whether two floating point rectangles are equal, within some given epsilon.
bool Equal (const FRectRaw &other) const
 Determine whether two floating point rectangles are equal, within a default epsilon.
bool Contains (const FPointRaw &p) const
 Check whether the rect contains given point.
bool Contains (const FRectRaw &other) const
 Check whether the rect contains given point.
bool HasIntersection (const FRectRaw &other) const
 Determine whether two rectangles intersect with float precision.
FRect GetIntersection (const FRectRaw &other) const
 Calculate the intersection of two rectangles with float precision.
constexpr FRect GetUnion (const FRectRaw &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 FPointRaw > points, OptionalRef< const FRectRaw > 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 (FPoint center, 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 (FPoint p1, FPoint p2)
 Construct the rect from given centers coordinates.

Detailed Description

A rectangle stored using floating point values.

The origin of the coordinate space is in the top-left, with increasing values moving down and right. The properties x and y represent the coordinates of the top-left corner of the rectangle.

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]

SDL::FRect::FRect ( const FRectRaw & r = {})
inlineconstexprnoexcept

Wraps FRect.

Parameters
rthe value to be wrapped

◆ FRect() [2/2]

SDL::FRect::FRect ( float x,
float y,
float w,
float h )
inlineconstexprnoexcept

Constructs from its fields.

Parameters
xthe left x.
ythe top y.
wthe width.
hthe height.

Member Function Documentation

◆ Contains() [1/2]

bool SDL::FRect::Contains ( const FPointRaw & p) const
inline

Check whether the rect contains given point.

Parameters
pPoint to check
Returns
True if the point is contained in the rect

◆ Contains() [2/2]

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

Check whether the rect contains given point.

Parameters
otherPoint to check
Returns
True if the point is contained in the rect

◆ Extend() [1/2]

FRect & SDL::FRect::Extend ( float amount)
inlineconstexpr

Extend a rect by specified amount of pixels.

Parameters
[in]amountNumber of pixels to extend by
Returns
Reference to self

◆ Extend() [2/2]

FRect & SDL::FRect::Extend ( float hAmount,
float vAmount )
inlineconstexpr

Extend a rect by specified amount of pixels.

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]

constexpr FRect SDL::FRect::FromCenter ( float cx,
float cy,
float w,
float h )
inlinestaticconstexpr

Construct the rect from given center coordinates, width and height.

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]

constexpr FRect SDL::FRect::FromCenter ( FPoint center,
FPoint size )
inlinestaticconstexpr

Construct the rect from given center coordinates and size.

Parameters
[in]centerCoordinates of the rectangle center
[in]sizeDimensions of the rectangle

◆ FromCorners() [1/2]

constexpr FRect SDL::FRect::FromCorners ( float x1,
float y1,
float x2,
float y2 )
inlinestaticconstexpr

Construct the rect from given corners coordinates.

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]

constexpr FRect SDL::FRect::FromCorners ( FPoint p1,
FPoint p2 )
inlinestaticconstexpr

Construct the rect from given centers coordinates.

Parameters
[in]p1Coordinates of the top left rectangle corner
[in]p2Coordinates of the bottom right rectangle corner

◆ GetBottomLeft()

FPoint SDL::FRect::GetBottomLeft ( ) const
inlineconstexpr

Get bottom left corner of the rect.

Returns
bottom left corner of the rect

◆ GetBottomRight()

FPoint SDL::FRect::GetBottomRight ( ) const
inlineconstexpr

Get bottom right corner of the rect.

Returns
Bottom right corner of the rect

◆ GetCentroid()

FPoint SDL::FRect::GetCentroid ( ) const
inlineconstexpr

Get centroid of the rect.

Returns
Centroid of the rect

◆ GetExtension() [1/2]

FRect SDL::FRect::GetExtension ( float hAmount,
float vAmount ) const
inlineconstexpr

Get a rect extended by specified amount of pixels.

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]

FRect SDL::FRect::GetExtension ( unsigned int amount) const
inlineconstexpr

Get a rect extended by specified amount of pixels.

Parameters
[in]amountNumber of pixels to extend by
Returns
Extended rect

◆ GetH()

float SDL::FRect::GetH ( ) const
inlineconstexprnoexcept

Get height of the rect.

Returns
Height of the rect

◆ GetLineIntersection()

bool SDL::FRect::GetLineIntersection ( FPoint * p1,
FPoint * p2 ) const
inline

Determine whether a floating point rectangle takes no space.

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

FPoint SDL::FRect::GetSize ( ) const
inlineconstexpr

Get size of the rect.

Returns
Size of the rect

◆ GetTopLeft()

FPoint SDL::FRect::GetTopLeft ( ) const
inlineconstexpr

Get top left corner of the rect.

Returns
Top left corner of the rect

◆ GetTopRight()

FPoint SDL::FRect::GetTopRight ( ) const
inlineconstexpr

Get top right corner of the rect.

Returns
Top right corner of the rect

◆ GetW()

float SDL::FRect::GetW ( ) const
inlineconstexprnoexcept

Get width of the rect.

Returns
Width of the rect

◆ GetX()

float SDL::FRect::GetX ( ) const
inlineconstexprnoexcept

Get left x coordinate.

Returns
coordinate of the left x

◆ GetX2()

float SDL::FRect::GetX2 ( ) const
inlineconstexpr

Get X coordinate of the rect second corner.

Returns
X coordinate of the rect second corner

◆ GetY()

float SDL::FRect::GetY ( ) const
inlineconstexprnoexcept

Get top y coordinate.

Returns
coordinate of the top y.

◆ GetY2()

float SDL::FRect::GetY2 ( ) const
inlineconstexpr

Get Y coordinate of the rect second corner.

Returns
Y coordinate of the rect second corner

◆ operator bool()

SDL::FRect::operator bool ( ) const
inline
See also
Empty()

◆ operator+()

FRect SDL::FRect::operator+ ( const FPoint & offset) const
inlineconstexpr

Get rectangle moved by a given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator+=()

FRect & SDL::FRect::operator+= ( const FPoint & offset)
inlineconstexpr

Move by then given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ operator-()

FRect SDL::FRect::operator- ( const FPoint & offset) const
inlineconstexpr

Get rectangle moved by an opposite of given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator-=()

FRect & SDL::FRect::operator-= ( const FPoint & offset)
inlineconstexpr

Move by an opposite of the given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Reference to self

◆ SetH()

FRect & SDL::FRect::SetH ( float newH)
inlineconstexprnoexcept

Set the height of the rect.

Parameters
newHthe new height.
Returns
Reference to self.

◆ SetW()

FRect & SDL::FRect::SetW ( float newW)
inlineconstexprnoexcept

Set the width of the rect.

Parameters
newWthe new width.
Returns
Reference to self.

◆ SetX()

FRect & SDL::FRect::SetX ( float newX)
inlineconstexprnoexcept

Set the left x coordinate.

Parameters
newXthe new left x.
Returns
Reference to self.

◆ SetX2()

FRect & SDL::FRect::SetX2 ( float x2)
inlineconstexpr

Set X coordinate of the rect second corner.

Parameters
[in]x2New X coordinate value

This modifies rectangle width internally

Returns
Reference to self

◆ SetY()

FRect & SDL::FRect::SetY ( float newY)
inlineconstexprnoexcept

Set the top y coordinate.

Parameters
newYthe new top y.
Returns
Reference to self.

◆ SetY2()

FRect & SDL::FRect::SetY2 ( float y2)
inlineconstexpr

Set Y coordinate of the rect second corner.

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: