aboutsummaryrefslogtreecommitdiff
path: root/src/RectangleUtil.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/RectangleUtil.hh')
-rw-r--r--src/RectangleUtil.hh44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/RectangleUtil.hh b/src/RectangleUtil.hh
index 88c3a33..9725e63 100644
--- a/src/RectangleUtil.hh
+++ b/src/RectangleUtil.hh
@@ -24,6 +24,50 @@ bool insideBorder(const RectangleLike& rect,
24 y < rect.y() + (int)rect.height() + border_width; 24 y < rect.y() + (int)rect.height() + border_width;
25} 25}
26 26
27
28
29/*
30 * Determines if rectangle 'a' overlaps rectangle 'b'
31 * @returns true if 'a' overlaps 'b'
32 *
33 * outside overlap situations
34 *
35 * a----a a----a a--------a b--------b
36 * | | b----b | b-+--b | b----b | | a----a |
37 * a----a | | a--+-a | | | | | | | | |
38 * b----b b----b | b----b | | a----a |
39 * a--------a b--------b
40 *
41 */
42
43inline bool overlapRectangles(
44 int ax, int ay, int awidth, int aheight,
45 int bx, int by, int bwidth, int bheight) {
46
47 bool do_not_overlap =
48 ax > (bx + bwidth)
49 || bx > (ax + awidth)
50 || ay > (by + bheight)
51 || by > (ay + aheight);
52
53 return !do_not_overlap;
54}
55
56
57/*
58 * Determines if rectangle 'a' overlaps rectangle 'b'
59 * @param a - rectangle a
60 * @param b - rectangle b
61 * @returns true if 'a' overlaps 'b'
62 */
63template <typename RectangleLikeA, typename RectangleLikeB>
64bool overlapRectangles(const RectangleLikeA& a, const RectangleLikeB& b) {
65
66 return overlapRectangles(
67 a.x(), a.y(), a.width(), a.height(),
68 b.x(), b.y(), b.width(), b.height());
69}
70
27} // namespace RectangleUtil 71} // namespace RectangleUtil
28 72
29 73