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());
192 int16
width()
const {
return right - left; }
193 int16
height()
const {
return bottom - top; }
196 right = left + aWidth;
200 bottom = top + aHeight;
212 return (left <= x) && (x < right) && (top <= y) && (y < bottom);
223 return contains(p.
x, p.
y);
234 return (left <= r.
left) && (r.
right <= right) && (top <= r.top) && (r.bottom <= bottom);
245 return (left == r.
left) && (right == r.
right) && (top == r.top) && (bottom == r.bottom);
257 return (left < r.
right) && (r.
left < right) && (top < r.bottom) && (r.top < bottom);
282 top =
MIN(top, r.top);
283 bottom =
MAX(bottom, r.bottom);
302 assert(isValidRect());
305 if (top < r.top) top = r.top;
306 else if (top > r.bottom) top = r.bottom;
311 if (bottom > r.bottom) bottom = r.bottom;
312 else if (bottom < r.top) bottom = r.top;
315 else if (right < r.
left) right = r.
left;
321 void clip(int16 maxw, int16 maxh) {
322 clip(
Rect(0, 0, maxw, maxh));
332 return (left >= right || top >= bottom);
339 return (left <= right && top <= bottom);
356 left += dx; right += dx;
357 top += dy; bottom += dy;
370 void debugPrint(
int debuglevel = 0,
const char *caption =
"Rect:")
const {
371 debug(debuglevel,
"%s %d, %d, %d, %d", caption, left, top, right, bottom);
377 void debugPrintC(
int debuglevel, uint32 debugChannel,
const char *caption =
"Rect:")
const {
378 debugC(debuglevel, debugChannel,
"%s %d, %d, %d, %d", caption, left, top, right, bottom);
386 int x = cx - w / 2,
y = cy - h / 2;
387 return Rect(x,
y, x + w,
y + h);
398 if (dst.
x < clip.
left) {
403 if (dst.
y < clip.top) {
404 rect.top += clip.top - dst.
y;
408 int right = dst.
x + rect.
right;
409 if (right > clip.
right)
412 int bottom = dst.
y + rect.bottom;
413 if (bottom > clip.bottom)
414 rect.bottom -= bottom - clip.bottom;
Point operator/(double divisor) const
Definition: rect.h:82
void setHeight(int16 aHeight)
Definition: rect.h:199
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:363
Common::Point origin() const
Definition: rect.h:191
Point operator/(int divisor) const
Definition: rect.h:74
void extend(const Rect &r)
Definition: rect.h:279
Rect findIntersectingRect(const Rect &r) const
Definition: rect.h:267
bool contains(int16 x, int16 y) const
Definition: rect.h:211
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:385
void translate(int16 dx, int16 dy)
Definition: rect.h:355
Rect(int16 x1, int16 y1, int16 x2, int16 y2)
Definition: rect.h:175
void void void void void debugC(int level, uint32 debugChannel, MSVC_PRINTF const char *s,...) GCC_PRINTF(3
bool operator==(const Point &p) const
Definition: rect.h:58
bool contains(const Point &p) const
Definition: rect.h:222
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
void clip(int16 maxw, int16 maxh)
Definition: rect.h:321
int16 width() const
Definition: rect.h:192
static bool getBlitRect(Point &dst, Rect &rect, const Rect &clip)
Definition: rect.h:397
void setWidth(int16 aWidth)
Definition: rect.h:195
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:345
bool contains(const Rect &r) const
Definition: rect.h:233
bool intersects(const Rect &r) const
Definition: rect.h:256
bool isValidRect() const
Definition: rect.h:338
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:61
bool equals(const Rect &r) const
Definition: rect.h:244
void clip(const Rect &r)
Definition: rect.h:301
T MAX(T a, T b)
Definition: util.h:64
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:291
T ABS(T x)
Definition: util.h:58
void debugPrint(int debuglevel=0, const char *caption="Rect:") const
Definition: rect.h:370
bool operator!=(const Rect &rhs) const
Definition: rect.h:189
int16 height() const
Definition: rect.h:193
constexpr Rect(const Point &topLeft, int16 w, int16 h)
Definition: rect.h:167
bool isEmpty() const
Definition: rect.h:331
void debugPrintC(int debuglevel, uint32 debugChannel, const char *caption="Rect:") const
Definition: rect.h:377
void operator+=(const Point &delta)
Definition: rect.h:91
uint sqrDist(const Point &p) const
Definition: rect.h:110