25 #include <SDL2/SDL_rect.h>
34 bool operator==(
const SDL_Rect& a,
const SDL_Rect&
b);
35 bool operator!=(
const SDL_Rect& a,
const SDL_Rect&
b);
50 constexpr
rect() : SDL_Rect{0, 0, 0, 0} {}
53 constexpr
rect(
const SDL_Rect& r) : SDL_Rect{r} {}
56 constexpr
rect(
int x,
int y,
int w,
int h) : SDL_Rect{x, y,
w,
h} {}
74 return {x *
s, y *
s,
w *
s,
h *
s};
88 return {x /
s, y /
s,
w /
s,
h /
s};
101 constexpr
int area()
const {
return w *
h; }
106 return {x +
w / 2, y +
h / 2};
117 bool contains(
const SDL_Rect& r)
const;
120 bool overlaps(
const SDL_Rect& r)
const;
142 void clip(
const SDL_Rect& r);
constexpr const SDL_Rect empty_rect
bool operator==(const SDL_Rect &a, const SDL_Rect &b)
std::ostream & operator<<(std::ostream &s, const SDL_Rect &rect)
bool operator!=(const SDL_Rect &a, const SDL_Rect &b)
An abstract description of a rectangle with integer coordinates.
constexpr point center() const
The center point of the rectangle, accounting for origin.
bool empty() const
False if both w and h are > 0, true otherwise.
rect & expand_to_cover(const SDL_Rect &r)
Minimally expand this rect to fully contain another.
rect shifted_by(int x, int y) const
Returns a new rectangle shifted by the given relative position.
constexpr rect(const SDL_Rect &r)
There's nothing extra when converting an SDL_Rect.
constexpr rect & operator*=(int s)
rect minimal_cover(const SDL_Rect &r) const
Calculates the minimal rectangle that completely contains both this rectangle and the given rectangle...
constexpr rect(int x, int y, int w, int h)
Specify via (x, y, w, h).
constexpr rect operator/(int s) const
constexpr rect()
Explicitly initialize rects to 0.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
bool operator==(const rect &r) const
constexpr rect(const point &pos, const point &size)
Specify via top-left corner position and size.
void clip(const SDL_Rect &r)
Clip this rectangle by the given rectangle.
constexpr int area() const
The area of this rectangle, in square pixels.
constexpr rect & operator/=(int s)
constexpr point size() const
void shift(const point &p)
Shift the rectangle by the given relative position.
constexpr rect operator*(int s) const
constexpr point pos() const
rect intersect(const SDL_Rect &r) const
Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is con...
bool overlaps(const SDL_Rect &r) const
Whether the given rectangle and this rectangle overlap.
static map_location::DIRECTION s