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

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

Inheritance diagram for SDL::Rect:
[legend]

Public Member Functions

constexpr Rect (const RectRaw &r={}) noexcept
 Wraps Rect.
constexpr Rect (int x, int y, int w, int h) noexcept
 Constructs from its fields.
constexpr Rect (const PointRaw &corner, const PointRaw &size)
 Construct from offset and size.
bool operator== (const RectRaw &other) const
 Compares with the underlying type.
bool operator== (const Rect &other) const
 Compares with the underlying type.
 operator bool () const
constexpr int GetX () const noexcept
 Get left x coordinate.
constexpr RectSetX (int newX) noexcept
 Set the left x coordinate.
constexpr int GetY () const noexcept
 Get top y coordinate.
constexpr RectSetY (int newY) noexcept
 Set the top y coordinate.
constexpr int GetW () const noexcept
 Get width of the rect.
constexpr RectSetW (int newW) noexcept
 Set the width of the rect.
constexpr int GetH () const noexcept
 Get height of the rect.
constexpr RectSetH (int newH) noexcept
 Set the height of the rect.
constexpr int GetX2 () const
 Get X coordinate of the rect second corner.
constexpr RectSetX2 (int x2)
 Set X coordinate of the rect second corner.
constexpr int GetY2 () const
 Get Y coordinate of the rect second corner.
constexpr RectSetY2 (int y2)
 Set Y coordinate of the rect second corner.
constexpr Point GetTopLeft () const
 Get top left corner of the rect.
constexpr Point GetTopRight () const
 Get top right corner of the rect.
constexpr Point GetBottomLeft () const
 Get bottom left corner of the rect.
constexpr Point GetBottomRight () const
 Get bottom right corner of the rect.
constexpr Point GetSize () const
 Get size of the rect.
constexpr Point GetCentroid () const
 Get centroid of the rect.
bool GetLineIntersection (PointRaw *p1, PointRaw *p2) const
 Calculate the intersection of a rectangle and line segment.
bool GetLineIntersection (int *X1, int *Y1, int *X2, int *Y2) const
 Calculate the intersection of a rectangle and line segment.
 operator SDL_FRect () const
 Convert an SDL_Rect to SDL_FRect.
constexpr operator FRect () const
bool Empty () const
 Determine whether a rectangle has no area.
bool Equal (const RectRaw &other) const
 Determine whether two rectangles are equal.
bool Contains (const PointRaw &p) const
 Check whether the rect contains given point.
bool Contains (const RectRaw &other) const
 Check whether the rect contains given point.
bool HasIntersection (const RectRaw &other) const
 Determine whether two rectangles intersect.
Rect GetIntersection (const RectRaw &other) const
 Calculate the intersection of two rectangles.
constexpr Rect GetUnion (const RectRaw &other) const
 Calculate the union of two rectangles.
constexpr Rect GetExtension (unsigned int amount) const
 Get a rect extended by specified amount of pixels.
constexpr Rect GetExtension (unsigned int hAmount, unsigned int vAmount) const
 Get a rect extended by specified amount of pixels.
constexpr RectExtend (unsigned int amount)
 Extend a rect by specified amount of pixels.
constexpr RectExtend (unsigned int hAmount, unsigned int vAmount)
 Extend a rect by specified amount of pixels.
constexpr Rect operator+ (const Point &offset) const
 Get rectangle moved by a given offset.
constexpr Rect operator- (const Point &offset) const
 Get rectangle moved by an opposite of given offset.
constexpr Rectoperator+= (const Point &offset)
 Move by then given offset.
constexpr Rectoperator-= (const Point &offset)
 Move by an opposite of the given offset.

Static Public Member Functions

static Rect GetEnclosingPoints (SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt)
 Calculate a minimal rectangle enclosing a set of points.
static constexpr Rect FromCenter (int cx, int cy, int w, int h)
 Construct the rect from given center coordinates, width and height.
static constexpr Rect FromCenter (Point center, Point size)
 Construct the rect from given center coordinates and size.
static constexpr Rect FromCorners (int x1, int y1, int x2, int y2)
 Construct the rect from given corners coordinates.
static constexpr Rect FromCorners (Point p1, Point p2)
 Construct the rect from given centers coordinates.

Detailed Description

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

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

Constructor & Destructor Documentation

◆ Rect() [1/3]

SDL::Rect::Rect ( const RectRaw & r = {})
inlineconstexprnoexcept

Wraps Rect.

Parameters
rthe value to be wrapped

◆ Rect() [2/3]

SDL::Rect::Rect ( int x,
int y,
int w,
int h )
inlineconstexprnoexcept

Constructs from its fields.

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

◆ Rect() [3/3]

SDL::Rect::Rect ( const PointRaw & corner,
const PointRaw & size )
inlineconstexpr

Construct from offset and size.

Parameters
cornerthe top-left corner
sizethe size

Member Function Documentation

◆ Contains() [1/2]

bool SDL::Rect::Contains ( const PointRaw & 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::Rect::Contains ( const RectRaw & 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]

Rect & SDL::Rect::Extend ( unsigned int 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]

Rect & SDL::Rect::Extend ( unsigned int hAmount,
unsigned int 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 Rect SDL::Rect::FromCenter ( int cx,
int cy,
int w,
int 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 Rect SDL::Rect::FromCenter ( Point center,
Point 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 Rect SDL::Rect::FromCorners ( int x1,
int y1,
int x2,
int 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 Rect SDL::Rect::FromCorners ( Point p1,
Point 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()

Point SDL::Rect::GetBottomLeft ( ) const
inlineconstexpr

Get bottom left corner of the rect.

Returns
bottom left corner of the rect

◆ GetBottomRight()

Point SDL::Rect::GetBottomRight ( ) const
inlineconstexpr

Get bottom right corner of the rect.

Returns
Bottom right corner of the rect

◆ GetCentroid()

Point SDL::Rect::GetCentroid ( ) const
inlineconstexpr

Get centroid of the rect.

Returns
Centroid of the rect

◆ GetExtension() [1/2]

Rect SDL::Rect::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

◆ GetExtension() [2/2]

Rect SDL::Rect::GetExtension ( unsigned int hAmount,
unsigned int 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

◆ GetH()

int SDL::Rect::GetH ( ) const
inlineconstexprnoexcept

Get height of the rect.

Returns
Height of the rect

◆ GetLineIntersection()

bool SDL::Rect::GetLineIntersection ( PointRaw * p1,
PointRaw * p2 ) const
inline

Calculate the intersection of a rectangle and line segment.

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

Point SDL::Rect::GetSize ( ) const
inlineconstexpr

Get size of the rect.

Returns
Size of the rect

◆ GetTopLeft()

Point SDL::Rect::GetTopLeft ( ) const
inlineconstexpr

Get top left corner of the rect.

Returns
Top left corner of the rect

◆ GetTopRight()

Point SDL::Rect::GetTopRight ( ) const
inlineconstexpr

Get top right corner of the rect.

Returns
Top right corner of the rect

◆ GetW()

int SDL::Rect::GetW ( ) const
inlineconstexprnoexcept

Get width of the rect.

Returns
Width of the rect

◆ GetX()

int SDL::Rect::GetX ( ) const
inlineconstexprnoexcept

Get left x coordinate.

Returns
coordinate of the left x

◆ GetX2()

int SDL::Rect::GetX2 ( ) const
inlineconstexpr

Get X coordinate of the rect second corner.

Returns
X coordinate of the rect second corner

◆ GetY()

int SDL::Rect::GetY ( ) const
inlineconstexprnoexcept

Get top y coordinate.

Returns
coordinate of the top y.

◆ GetY2()

int SDL::Rect::GetY2 ( ) const
inlineconstexpr

Get Y coordinate of the rect second corner.

Returns
Y coordinate of the rect second corner

◆ operator bool()

SDL::Rect::operator bool ( ) const
inlineexplicit
See also
Empty()

◆ operator FRect()

SDL::Rect::operator FRect ( ) const
constexpr
See also
operator ToFRect()

◆ operator+()

Rect SDL::Rect::operator+ ( const Point & offset) const
inlineconstexpr

Get rectangle moved by a given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator+=()

Rect & SDL::Rect::operator+= ( const Point & offset)
inlineconstexpr

Move by then given offset.

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

◆ operator-()

Rect SDL::Rect::operator- ( const Point & offset) const
inlineconstexpr

Get rectangle moved by an opposite of given offset.

Parameters
[in]offsetPoint specifying an offset
Returns
Moved rectangle

◆ operator-=()

Rect & SDL::Rect::operator-= ( const Point & offset)
inlineconstexpr

Move by an opposite of the given offset.

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

◆ SetH()

Rect & SDL::Rect::SetH ( int newH)
inlineconstexprnoexcept

Set the height of the rect.

Parameters
newHthe new height.
Returns
Reference to self.

◆ SetW()

Rect & SDL::Rect::SetW ( int newW)
inlineconstexprnoexcept

Set the width of the rect.

Parameters
newWthe new width.
Returns
Reference to self.

◆ SetX()

Rect & SDL::Rect::SetX ( int newX)
inlineconstexprnoexcept

Set the left x coordinate.

Parameters
newXthe new left x.
Returns
Reference to self.

◆ SetX2()

Rect & SDL::Rect::SetX2 ( int 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()

Rect & SDL::Rect::SetY ( int newY)
inlineconstexprnoexcept

Set the top y coordinate.

Parameters
newYthe new top y.
Returns
Reference to self.

◆ SetY2()

Rect & SDL::Rect::SetY2 ( int 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: