22 #ifndef ULTIMA8_MISC_RECT_H 23 #define ULTIMA8_MISC_RECT_H 36 Rect() : top(0), left(0), bottom(0), right(0) {}
37 Rect(
int x1,
int y1,
int x2,
int y2) : top(y1), left(x1), bottom(y2), right(x2) {}
39 bool operator==(
const Rect &rhs)
const {
return equals(rhs); }
40 bool operator!=(
const Rect &rhs)
const {
return !equals(rhs); }
42 int16 width()
const {
return right - left; }
43 int16 height()
const {
return bottom - top; }
45 void setWidth(int16 aWidth) {
46 right = left + aWidth;
49 void setHeight(int16 aHeight) {
50 bottom = top + aHeight;
53 void grow(int16 offset) {
61 bool isEmpty()
const {
62 return (left >= right || top >= bottom);
66 bool isValidRect()
const {
67 return (left <= right && top <= bottom);
71 bool contains(int16 x, int16 y)
const {
72 return (left <= x) && (x < right) && (top <= y) && (y < bottom);
76 bool contains(
const Rect &r)
const {
77 return (left <= r.left) && (r.right <= right) && (top <= r.top) && (r.bottom <= bottom);
81 void translate(int32 dx, int32 dy) {
89 void moveTo(int32 x, int32 y) {
96 void clip(
const Rect &r) {
97 if (top < r.top) top = r.top;
98 else if (top > r.bottom) top = r.bottom;
100 if (left < r.left) left = r.left;
101 else if (left > r.right) left = r.right;
103 if (bottom < r.top) bottom = r.top;
104 else if (bottom > r.bottom) bottom = r.bottom;
106 if (right < r.left) right = r.left;
107 else if (right > r.right) right = r.right;
110 bool intersects(
const Rect &r)
const {
111 return (left < r.right) && (r.left < right) && (top < r.bottom) && (r.top < bottom);
114 bool equals(
const Rect &o)
const {
115 return left == o.left && top == o.top && right == o.right && bottom == o.bottom;
Definition: detection.h:27