11 class Rect :
public SDL_Rect
15 constexpr
Rect() : SDL_Rect{0, 0, 0, 0} {}
22 constexpr
Rect(
int x,
int y,
int w,
int h) : SDL_Rect{x, y, w, h} {}
28 : SDL_Rect{corner.x, corner.y, size.x, size.y}
33 constexpr
Rect(SDL_Rect
const& r) : SDL_Rect{r} {}
36 Rect(
Rect const&) noexcept =
default;
48 return Rect{cx - w / 2, cy - h / 2, w, h};
55 return Rect{center - size / 2, size};
65 return Rect(x1, y1, x2 - x1, y2 - y1);
73 return Rect(corner1.x, corner1.y, corner2.x - corner1.x, corner2.y - corner1.y);
82 bool operator==(
Rect const& other)
const {
return SDL_RectEquals(
this, &other); }
85 constexpr
int x1()
const {
return x; }
87 constexpr
int x2()
const {
return x + w; }
89 constexpr
int y1()
const {
return y; }
91 constexpr
int y2()
const {
return y + h; }
108 bool is_empty()
const {
return SDL_RectEmpty(
this); }
115 return px >=
x1() && px < x2() && py >=
y1() && py <
y2();
133 auto p1mut =
const_cast<Vec2i&
>(p1);
134 auto p2mut =
const_cast<Vec2i&
>(p2);
136 return SDL_IntersectRectAndLine(
this, &p1mut.x, &p1mut.y, &p2mut.x, &p2mut.y);
143 SDL_IntersectRect(
this, &r, &tmp);
152 SDL_UnionRect(
this, &r, &tmp);
Vec2i topright() const
Get the top right corner position.
bool contains(int px, int py) const
Return true if this rect contains the given point.
constexpr int y1() const
Return the 'min Y' position of the Rect.
bool intersects(Vec2i const &p1, Vec2i const &p2) const
Return true if this rect intersect the line.
Rect get_union(Rect const &r) const
Return the union of the two rects.
bool is_empty() const
Return true if this Rect is empty.
sdl::Rect, C++ wrapping of SDL_Rect
constexpr int x2() const
Return the 'max X' position of the Rect.
Vec2i botleft() const
Get the bottom left corner position.
constexpr int x1() const
Return the 'min X' position of the Rect.
bool intersects(Rect const &r) const
Return true if this rect intersect another rect.
Generic templated 2D vector class.
static constexpr Rect from_corners(int x1, int y1, int x2, int y2)
Construct a rect from 2 corner points.
constexpr Rect(Vec2i const &corner, Vec2i const &size)
Construct a Rect with the given dimensions.
static constexpr Rect from_center(Vec2i const ¢er, Vec2i const &size)
Construct a Rect with dimensions around a center point.
Rect & operator=(Rect const &) noexcept=default
Copy assign a Rect.
constexpr int y2() const
Return the 'max Y' position of the Rect.
Vec2i topleft() const
Get the top left corner position.
Vec2i center() const
Get the center of the Rect.
Vec2i botright() const
Get the bottom right corner position.
bool operator==(Rect const &other) const
Returns true if the two rect are the same.
Define to deactivate exception support.
static constexpr Rect from_center(int cx, int cy, int w, int h)
Contruct a Rect with dimensions around a center point.
Vec2i size() const
Get the size of the Rect.
constexpr Rect(SDL_Rect const &r)
Copy a Rect.
constexpr Rect(int x, int y, int w, int h)
Construct a Rect with the given dimensions.
Rect inter(Rect const &r) const
Return the intersection of the two rects.
bool contains(Vec2i const &point) const
Return true if this rect contains the given point.
static constexpr Rect from_corners(Vec2i const &corner1, Vec2i const &corner2)
Construct a rect from 2 corner points.
constexpr Rect()
Construct a Rect initialized at 0.