aboutsummaryrefslogtreecommitdiff
path: root/src/RectangleUtil.hh
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2011-03-19 13:56:45 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2011-03-19 13:56:45 (GMT)
commita798e0e0ffe327b405206a561538e88d1e8db7da (patch)
treea822c1133de1031cd7c78c32a4926336e98e2b5b /src/RectangleUtil.hh
parentcea6887f650730da25d72fd1bcaef7d48d5f53e7 (diff)
downloadfluxbox-a798e0e0ffe327b405206a561538e88d1e8db7da.zip
fluxbox-a798e0e0ffe327b405206a561538e88d1e8db7da.tar.bz2
added RectangleUtil::overlapRectangles() + test cases
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