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} {}
60 : SDL_Rect{pos.x, pos.y,
size.x,
size.y}
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);
158 return { x - dx, y - dy,
w + dx * 2,
h + dy * 2 };
171 rect subrect(
const SDL_FPoint& top_left,
const SDL_FPoint& bottom_right)
const;
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 point origin() const
constexpr rect(const SDL_Rect &r)
There's nothing extra when converting an SDL_Rect.
point point_at(double x, double y) const
Returns the proper point that corresponds to the given [0.0, 1.0] coordinates.
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
rect subrect(const SDL_FPoint &top_left, const SDL_FPoint &bottom_right) const
Returns the sub-rect bounded to the top left and bottom right by the given [0.0, 1....
constexpr rect()
Explicitly initialize rects to 0.
bool contains(int x, int y) const
Whether the given point lies within the rectangle.
constexpr rect padded_by(int amount) const
Returns a new rectangle with equal amount horizontal and vertical padding.
bool operator==(const rect &r) const
constexpr rect padded_by(int dx, int dy) const
Returns a new rectangle with dx horizontal padding and dy vertical padding.
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
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