cpp-sdl2
C++ header-only SDL2 wrapper
sdl::Rect Class Reference

sdl::Rect, C++ wrapping of SDL_Rect More...

#include <rect.hpp>

+ Inheritance diagram for sdl::Rect:

Public Member Functions

constexpr Rect ()
 Construct a Rect initialized at 0. More...
 
constexpr Rect (int x, int y, int w, int h)
 Construct a Rect with the given dimensions. More...
 
constexpr Rect (Vec2i const &corner, Vec2i const &size)
 Construct a Rect with the given dimensions. More...
 
constexpr Rect (SDL_Rect const &r)
 Copy a Rect. More...
 
 Rect (Rect const &) noexcept=default
 Copy a Rect. More...
 
 Rect (Rect &&) noexcept=default
 Move from a Rect. More...
 
Rectoperator= (Rect const &) noexcept=default
 Copy assign a Rect. More...
 
Rectoperator= (Rect &&) noexcept=default
 Move assign a Rect. More...
 
bool operator== (Rect const &other) const
 Returns true if the two rect are the same. More...
 
constexpr int x1 () const
 Return the 'min X' position of the Rect. More...
 
constexpr int x2 () const
 Return the 'max X' position of the Rect. More...
 
constexpr int y1 () const
 Return the 'min Y' position of the Rect. More...
 
constexpr int y2 () const
 Return the 'max Y' position of the Rect. More...
 
Vec2i botleft () const
 Get the bottom left corner position. More...
 
Vec2i botright () const
 Get the bottom right corner position. More...
 
Vec2i topleft () const
 Get the top left corner position. More...
 
Vec2i topright () const
 Get the top right corner position. More...
 
Vec2i size () const
 Get the size of the Rect. More...
 
Vec2i center () const
 Get the center of the Rect. More...
 
bool is_empty () const
 Return true if this Rect is empty. More...
 
bool contains (int px, int py) const
 Return true if this rect contains the given point. More...
 
bool contains (Vec2i const &point) const
 Return true if this rect contains the given point. More...
 
bool intersects (Rect const &r) const
 Return true if this rect intersect another rect. More...
 
bool intersects (Vec2i const &p1, Vec2i const &p2) const
 Return true if this rect intersect the line. More...
 
Rect inter (Rect const &r) const
 Return the intersection of the two rects. More...
 
Rect get_union (Rect const &r) const
 Return the union of the two rects. More...
 

Static Public Member Functions

static constexpr Rect from_center (int cx, int cy, int w, int h)
 Contruct a Rect with dimensions around a center point. More...
 
static constexpr Rect from_center (Vec2i const &center, Vec2i const &size)
 Construct a Rect with dimensions around a center point. More...
 
static constexpr Rect from_corners (int x1, int y1, int x2, int y2)
 Construct a rect from 2 corner points. More...
 
static constexpr Rect from_corners (Vec2i const &corner1, Vec2i const &corner2)
 Construct a rect from 2 corner points. More...
 

Detailed Description

sdl::Rect, C++ wrapping of SDL_Rect

Definition at line 11 of file rect.hpp.

Constructor & Destructor Documentation

◆ Rect() [1/6]

constexpr sdl::Rect::Rect ( )
inline

Construct a Rect initialized at 0.

Definition at line 15 of file rect.hpp.

Referenced by from_corners(), and Rect().

◆ Rect() [2/6]

constexpr sdl::Rect::Rect ( int  x,
int  y,
int  w,
int  h 
)
inline

Construct a Rect with the given dimensions.

Parameters
xPosition on X axis
yPosition on Y axis
wSize on X axis
hSize on Y axis

Definition at line 22 of file rect.hpp.

◆ Rect() [3/6]

constexpr sdl::Rect::Rect ( Vec2i const &  corner,
Vec2i const &  size 
)
inline

Construct a Rect with the given dimensions.

Parameters
cornerX/Y position on screen as a 2D vector
sizeX/Y size on screen as a 2D vector

Definition at line 27 of file rect.hpp.

◆ Rect() [4/6]

constexpr sdl::Rect::Rect ( SDL_Rect const &  r)
inline

Copy a Rect.

Definition at line 33 of file rect.hpp.

References Rect().

◆ Rect() [5/6]

sdl::Rect::Rect ( Rect const &  )
defaultnoexcept

Copy a Rect.

◆ Rect() [6/6]

sdl::Rect::Rect ( Rect &&  )
defaultnoexcept

Move from a Rect.

Member Function Documentation

◆ botleft()

Vec2i sdl::Rect::botleft ( ) const
inline

Get the bottom left corner position.

Definition at line 94 of file rect.hpp.

References x1(), and y1().

◆ botright()

Vec2i sdl::Rect::botright ( ) const
inline

Get the bottom right corner position.

Definition at line 96 of file rect.hpp.

References x2(), and y1().

◆ center()

Vec2i sdl::Rect::center ( ) const
inline

Get the center of the Rect.

Definition at line 105 of file rect.hpp.

◆ contains() [1/2]

bool sdl::Rect::contains ( int  px,
int  py 
) const
inline

Return true if this rect contains the given point.

Parameters
pxX position of the point
pyY position of the point

Definition at line 113 of file rect.hpp.

References x1(), y1(), and y2().

◆ contains() [2/2]

bool sdl::Rect::contains ( Vec2i const &  point) const
inline

Return true if this rect contains the given point.

Parameters
pointThe X/Y coordinates of the point as a vector 2D

Definition at line 120 of file rect.hpp.

References contains().

Referenced by contains().

◆ from_center() [1/2]

static constexpr Rect sdl::Rect::from_center ( int  cx,
int  cy,
int  w,
int  h 
)
inlinestatic

Contruct a Rect with dimensions around a center point.

Parameters
cxposition of the center on the X axis
cyposition of the center on the Y axis
wSize on X axis
hSize on Y axis

Definition at line 46 of file rect.hpp.

◆ from_center() [2/2]

static constexpr Rect sdl::Rect::from_center ( Vec2i const &  center,
Vec2i const &  size 
)
inlinestatic

Construct a Rect with dimensions around a center point.

Parameters
centerX/Y position of the center point as a 2D vector

Definition at line 53 of file rect.hpp.

◆ from_corners() [1/2]

static constexpr Rect sdl::Rect::from_corners ( int  x1,
int  y1,
int  x2,
int  y2 
)
inlinestatic

Construct a rect from 2 corner points.

Parameters
x1X position of first point
y1Y position of first point
x2X position of second point
x2Y position of second point

Definition at line 63 of file rect.hpp.

References Rect().

◆ from_corners() [2/2]

static constexpr Rect sdl::Rect::from_corners ( Vec2i const &  corner1,
Vec2i const &  corner2 
)
inlinestatic

Construct a rect from 2 corner points.

Parameters
corner1X/Y position of the first corner as a 2D vector
corner2X/Y position of the second corner as a 2D vector

Definition at line 71 of file rect.hpp.

References operator=(), and Rect().

◆ get_union()

Rect sdl::Rect::get_union ( Rect const &  r) const
inline

Return the union of the two rects.

Definition at line 149 of file rect.hpp.

◆ inter()

Rect sdl::Rect::inter ( Rect const &  r) const
inline

Return the intersection of the two rects.

Definition at line 140 of file rect.hpp.

◆ intersects() [1/2]

bool sdl::Rect::intersects ( Rect const &  r) const
inline

Return true if this rect intersect another rect.

Definition at line 123 of file rect.hpp.

References x1(), x2(), y1(), and y2().

◆ intersects() [2/2]

bool sdl::Rect::intersects ( Vec2i const &  p1,
Vec2i const &  p2 
) const
inline

Return true if this rect intersect the line.

Definition at line 129 of file rect.hpp.

◆ is_empty()

bool sdl::Rect::is_empty ( ) const
inline

Return true if this Rect is empty.

Definition at line 108 of file rect.hpp.

◆ operator=() [1/2]

Rect& sdl::Rect::operator= ( Rect const &  )
defaultnoexcept

Copy assign a Rect.

Referenced by from_corners().

◆ operator=() [2/2]

Rect& sdl::Rect::operator= ( Rect &&  )
defaultnoexcept

Move assign a Rect.

◆ operator==()

bool sdl::Rect::operator== ( Rect const &  other) const
inline

Returns true if the two rect are the same.

Definition at line 82 of file rect.hpp.

◆ size()

Vec2i sdl::Rect::size ( ) const
inline

Get the size of the Rect.

Definition at line 103 of file rect.hpp.

◆ topleft()

Vec2i sdl::Rect::topleft ( ) const
inline

Get the top left corner position.

Definition at line 98 of file rect.hpp.

References x1(), and y2().

◆ topright()

Vec2i sdl::Rect::topright ( ) const
inline

Get the top right corner position.

Definition at line 100 of file rect.hpp.

References x2(), and y2().

◆ x1()

constexpr int sdl::Rect::x1 ( ) const
inline

Return the 'min X' position of the Rect.

Definition at line 85 of file rect.hpp.

Referenced by botleft(), contains(), intersects(), and topleft().

◆ x2()

constexpr int sdl::Rect::x2 ( ) const
inline

Return the 'max X' position of the Rect.

Definition at line 87 of file rect.hpp.

Referenced by botright(), intersects(), and topright().

◆ y1()

constexpr int sdl::Rect::y1 ( ) const
inline

Return the 'min Y' position of the Rect.

Definition at line 89 of file rect.hpp.

Referenced by botleft(), botright(), contains(), and intersects().

◆ y2()

constexpr int sdl::Rect::y2 ( ) const
inline

Return the 'max Y' position of the Rect.

Definition at line 91 of file rect.hpp.

Referenced by contains(), intersects(), topleft(), and topright().


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