diff options
Diffstat (limited to 'src/RectangleUtil.hh')
-rw-r--r-- | src/RectangleUtil.hh | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/RectangleUtil.hh b/src/RectangleUtil.hh index 9725e63..dfb0082 100644 --- a/src/RectangleUtil.hh +++ b/src/RectangleUtil.hh | |||
@@ -3,6 +3,14 @@ | |||
3 | 3 | ||
4 | namespace RectangleUtil { | 4 | namespace RectangleUtil { |
5 | 5 | ||
6 | inline bool insideRectangle(int x, int y, int width, int height, int px, int py) { | ||
7 | |||
8 | return | ||
9 | px >= x && | ||
10 | px < (x + width) && | ||
11 | py >= y && | ||
12 | py < (y + height); | ||
13 | } | ||
6 | 14 | ||
7 | /* | 15 | /* |
8 | * Determines if a point is inside a rectangle-like objects border. | 16 | * Determines if a point is inside a rectangle-like objects border. |
@@ -10,18 +18,17 @@ namespace RectangleUtil { | |||
10 | * height. | 18 | * height. |
11 | * @param x | 19 | * @param x |
12 | * @param y | 20 | * @param y |
13 | * @param border_width The size of the border. | 21 | * @param border The size of the border. |
14 | * @returns true if point is inside the rectangle-like object. | 22 | * @returns true if point is inside the rectangle-like object. |
15 | */ | 23 | */ |
24 | |||
16 | template <typename RectangleLike> | 25 | template <typename RectangleLike> |
17 | bool insideBorder(const RectangleLike& rect, | 26 | bool insideBorder(const RectangleLike& rect, |
18 | int x, int y, | 27 | int x, int y, |
19 | int border_width) { | 28 | int border) { |
20 | return | 29 | const int w = static_cast<int>(rect.width()) - border; |
21 | x >= rect.x() + border_width && | 30 | const int h = static_cast<int>(rect.height()) - border; |
22 | x < rect.x() + (int)rect.width() + border_width && | 31 | return insideRectangle(rect.x() + border, rect.y() + border, w, h, x, y); |
23 | y >= rect.y() + border_width && | ||
24 | y < rect.y() + (int)rect.height() + border_width; | ||
25 | } | 32 | } |
26 | 33 | ||
27 | 34 | ||