25 #include "common/scummsys.h" 26 #include "common/util.h" 27 #include "common/debug.h" 29 #define PRINT_RECT(x) (x).left,(x).top,(x).right,(x).bottom 49 constexpr
Point() : x(0), y(0) {}
54 constexpr
Point(int16 x1, int16 y1) : x(x1), y(y1) {}
86 Point operator*(
double multiplier)
const {
return Point((int16)(x * multiplier), (int16)(y * multiplier)); }
111 int diffx =
ABS(p.
x - x);
115 int diffy =
ABS(p.
y - y);
119 return uint(diffx * diffx + diffy * diffy);
124 static inline Point operator*(
double multiplier,
const Point &p) {
return Point((int16)(p.
x * multiplier), (int16)(p.
y * multiplier)); }
148 constexpr
Rect() : top(0), left(0), bottom(0), right(0) {}
152 constexpr
Rect(int16 w, int16 h) : top(0), left(0), bottom(h), right(w) {}
160 Rect(
const Point &topLeft,
const Point &bottomRight) : top(topLeft.
y), left(topLeft.
x), bottom(bottomRight.
y), right(bottomRight.
x) {
161 assert(isValidRect());
167 constexpr
Rect(
const Point &topLeft, int16 w, int16 h) : top(topLeft.
y), left(topLeft.
x), bottom(topLeft.
y + h), right(topLeft.
x + w) {
175 Rect(int16 x1, int16 y1, int16 x2, int16 y2) : top(y1), left(x1), bottom(y2), right(x2) {
176 assert(isValidRect());
191 int16
width()
const {
return right - left; }
192 int16
height()
const {
return bottom - top; }
195 right = left + aWidth;
199 bottom = top + aHeight;
211 return (left <= x) && (x < right) && (top <= y) && (y < bottom);
222 return contains(p.
x, p.
y);
233 return (left <= r.
left) && (r.
right <= right) && (top <= r.top) && (r.bottom <= bottom);
244 return (left == r.
left) && (right == r.
right) && (top == r.top) && (bottom == r.bottom);
256 return (left < r.
right) && (r.
left < right) && (top < r.bottom) && (r.top < bottom);
281 top =
MIN(top, r.top);
282 bottom =
MAX(bottom, r.bottom);
301 assert(isValidRect());
304 if (top < r.top) top = r.top;
305 else if (top > r.bottom) top = r.bottom;
310 if (bottom > r.bottom) bottom = r.bottom;
311 else if (bottom < r.top) bottom = r.top;
314 else if (right < r.
left) right = r.
left;
320 void clip(int16 maxw, int16 maxh) {
321 clip(
Rect(0, 0, maxw, maxh));
331 return (left >= right || top >= bottom);
338 return (left <= right && top <= bottom);
355 left += dx; right += dx;
356 top += dy; bottom += dy;
369 void debugPrint(
int debuglevel = 0,
const char *caption =
"Rect:")
const {
370 debug(debuglevel,
"%s %d, %d, %d, %d", caption, left, top, right, bottom);
378 int x = cx - w / 2,
y = cy - h / 2;
379 return Rect(x,
y, x + w,
y + h);
390 if (dst.
x < clip.
left) {
395 if (dst.
y < clip.top) {
396 rect.top += clip.top - dst.
y;
400 int right = dst.
x + rect.
right;
401 if (right > clip.
right)
404 int bottom = dst.
y + rect.bottom;
405 if (bottom > clip.bottom)
406 rect.bottom -= bottom - clip.bottom;
Point operator/(double divisor) const
Definition: rect.h:82
void setHeight(int16 aHeight)
Definition: rect.h:198
constexpr Point(int16 x1, int16 y1)
Definition: rect.h:54
Point operator*(double multiplier) const
Definition: rect.h:86
void moveTo(const Point &p)
Definition: rect.h:362
Point operator/(int divisor) const
Definition: rect.h:74
void extend(const Rect &r)
Definition: rect.h:278
Rect findIntersectingRect(const Rect &r) const
Definition: rect.h:266
bool contains(int16 x, int16 y) const
Definition: rect.h:210
constexpr Rect(int16 w, int16 h)
Definition: rect.h:152
int16 right
Definition: rect.h:146
Rect(const Point &topLeft, const Point &bottomRight)
Definition: rect.h:160
static Rect center(int16 cx, int16 cy, int16 w, int16 h)
Definition: rect.h:377
void translate(int16 dx, int16 dy)
Definition: rect.h:354
Rect(int16 x1, int16 y1, int16 x2, int16 y2)
Definition: rect.h:175
bool operator==(const Point &p) const
Definition: rect.h:58
bool contains(const Point &p) const
Definition: rect.h:221
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
void clip(int16 maxw, int16 maxh)
Definition: rect.h:320
int16 width() const
Definition: rect.h:191
static bool getBlitRect(Point &dst, Rect &rect, const Rect &clip)
Definition: rect.h:389
void setWidth(int16 aWidth)
Definition: rect.h:194
Definition: algorithm.h:29
int16 left
Definition: rect.h:145
Point operator*(int multiplier) const
Definition: rect.h:78
void operator-=(const Point &delta)
Definition: rect.h:99
int16 x
Definition: rect.h:46
void moveTo(int16 x, int16 y)
Definition: rect.h:344
bool contains(const Rect &r) const
Definition: rect.h:232
bool intersects(const Rect &r) const
Definition: rect.h:255
bool isValidRect() const
Definition: rect.h:337
Point operator-(const Point &delta) const
Definition: rect.h:70
int16 y
Definition: rect.h:47
T MIN(T a, T b)
Definition: util.h:59
bool equals(const Rect &r) const
Definition: rect.h:243
void clip(const Rect &r)
Definition: rect.h:300
T MAX(T a, T b)
Definition: util.h:62
bool operator!=(const Point &p) const
Definition: rect.h:62
bool operator==(const Rect &rhs) const
Definition: rect.h:183
Point operator+(const Point &delta) const
Definition: rect.h:66
void grow(int16 offset)
Definition: rect.h:290
T ABS(T x)
Definition: util.h:56
void debugPrint(int debuglevel=0, const char *caption="Rect:") const
Definition: rect.h:369
bool operator!=(const Rect &rhs) const
Definition: rect.h:189
int16 height() const
Definition: rect.h:192
constexpr Rect(const Point &topLeft, int16 w, int16 h)
Definition: rect.h:167
bool isEmpty() const
Definition: rect.h:330
void operator+=(const Point &delta)
Definition: rect.h:91
uint sqrDist(const Point &p) const
Definition: rect.h:110