summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 935566440..c3dd13d7c 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -600,3 +600,23 @@ Socket::read_indefinite (uint8_t* data, int size, int timeout)
assert (size >= _buffer_data);
memcpy (data, _buffer, size);
}
+
+Rectangle
+Rectangle::intersection (Rectangle const & other) const
+{
+ int const tx = max (x, other.x);
+ int const ty = max (y, other.y);
+
+ return Rectangle (
+ tx, ty,
+ min (x + w, other.x + other.w) - tx,
+ min (y + h, other.y + other.h) - ty
+ );
+}
+
+int
+round_up (int a, int t)
+{
+ a += (t - 1);
+ return a - (a % t);
+}