aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2004-01-18 21:41:38 +0000
committerMax Horn2004-01-18 21:41:38 +0000
commitcd045460cc221e5918a0e650948b41cb1e1d7162 (patch)
tree9f877f70c97b964f5e4a83a72eb4092f0dc3c3a2 /common
parent4b9602615c33c0c67c9a9d414bb9ff2e298602cb (diff)
downloadscummvm-rg350-cd045460cc221e5918a0e650948b41cb1e1d7162.tar.gz
scummvm-rg350-cd045460cc221e5918a0e650948b41cb1e1d7162.tar.bz2
scummvm-rg350-cd045460cc221e5918a0e650948b41cb1e1d7162.zip
improved rect clipping & verification
svn-id: r12507
Diffstat (limited to 'common')
-rw-r--r--common/rect.h18
1 files changed, 17 insertions, 1 deletions
diff --git a/common/rect.h b/common/rect.h
index 83e29fe232..2f28aae097 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -54,7 +54,9 @@ struct Rect {
Rect() : top(0), left(0), bottom(0), right(0) {}
Rect(int16 x, int16 y) : top(0), left(0), bottom(x), right(y) {}
- Rect(int16 x1, int16 y1, int16 x2, int16 y2) : top(y1), left(x1), bottom(y2), right(x2) {}
+ Rect(int16 x1, int16 y1, int16 x2, int16 y2) : top(y1), left(x1), bottom(y2), right(x2) {
+ assert(isValidRect());
+ }
int16 width() const { return right - left; }
int16 height() const { return bottom - top; }
@@ -112,15 +114,29 @@ struct Rect {
}
void clip(const Rect & r) {
+ assert(isValidRect());
+ assert(r.isValidRect());
+
if (top < r.top) top = r.top;
+ else if (top > r.bottom) top = r.bottom;
+
if (left < r.left) left = r.left;
+ else if (left > r.right) left = r.right;
+
if (bottom > r.bottom) bottom = r.bottom;
+ else if (bottom < r.top) bottom = r.top;
+
if (right > r.right) right = r.right;
+ else if (right < r.left) right = r.left;
}
void clip(int maxw, int maxh) {
clip(Rect(0, 0, maxw, maxh));
}
+
+ bool isValidRect() const {
+ return (left <= right && top <= bottom);
+ }
};
} // End of namespace Common