diff options
Diffstat (limited to 'src/RectangleUtil.hh')
-rw-r--r-- | src/RectangleUtil.hh | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/RectangleUtil.hh b/src/RectangleUtil.hh new file mode 100644 index 0000000..88c3a33 --- /dev/null +++ b/src/RectangleUtil.hh | |||
@@ -0,0 +1,30 @@ | |||
1 | #ifndef RECTANGLEUTIL_HH | ||
2 | #define RECTANGLEUTIL_HH | ||
3 | |||
4 | namespace RectangleUtil { | ||
5 | |||
6 | |||
7 | /* | ||
8 | * Determines if a point is inside a rectangle-like objects border. | ||
9 | * @param rect A rectangle-like object that has accessors for x, y, width, and | ||
10 | * height. | ||
11 | * @param x | ||
12 | * @param y | ||
13 | * @param border_width The size of the border. | ||
14 | * @returns true if point is inside the rectangle-like object. | ||
15 | */ | ||
16 | template <typename RectangleLike> | ||
17 | bool insideBorder(const RectangleLike& rect, | ||
18 | int x, int y, | ||
19 | int border_width) { | ||
20 | return | ||
21 | x >= rect.x() + border_width && | ||
22 | x < rect.x() + (int)rect.width() + border_width && | ||
23 | y >= rect.y() + border_width && | ||
24 | y < rect.y() + (int)rect.height() + border_width; | ||
25 | } | ||
26 | |||
27 | } // namespace RectangleUtil | ||
28 | |||
29 | |||
30 | #endif // RECTANGLEUTIL_HH | ||