diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-16 17:45:16 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-16 17:45:16 -0400 |
commit | 4a03d938451763dfb95b534f9002865e72ea7ec5 (patch) | |
tree | 9f2a0f074869009760fc33af5032c6de13da897e /src/rectangle.h | |
parent | 57fe8f3c4124819b95164547333a33f4c45eac8d (diff) | |
download | dispatcher-4a03d938451763dfb95b534f9002865e72ea7ec5.tar.gz dispatcher-4a03d938451763dfb95b534f9002865e72ea7ec5.tar.bz2 dispatcher-4a03d938451763dfb95b534f9002865e72ea7ec5.zip |
Diffstat (limited to 'src/rectangle.h')
-rw-r--r-- | src/rectangle.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/rectangle.h b/src/rectangle.h new file mode 100644 index 0000000..7815b56 --- /dev/null +++ b/src/rectangle.h | |||
@@ -0,0 +1,36 @@ | |||
1 | #ifndef RECTANGLE_H_23049366 | ||
2 | #define RECTANGLE_H_23049366 | ||
3 | |||
4 | #include "vector.h" | ||
5 | |||
6 | template <typename T> | ||
7 | class rect { | ||
8 | public: | ||
9 | |||
10 | using vector_type = vec2<T>; | ||
11 | |||
12 | constexpr rect( | ||
13 | vector_type pos, | ||
14 | vector_type size) : | ||
15 | pos(pos), | ||
16 | size(size) | ||
17 | { | ||
18 | } | ||
19 | |||
20 | const vector_type pos; | ||
21 | const vector_type size; | ||
22 | |||
23 | bool contains(vector_type point) const | ||
24 | { | ||
25 | return ( | ||
26 | point.x() >= pos.x() && | ||
27 | point.x() < pos.x() + size.w() && | ||
28 | point.y() >= pos.y() && | ||
29 | point.y() < pos.y() + size.h()); | ||
30 | } | ||
31 | |||
32 | }; | ||
33 | |||
34 | using rect4s = rect<size_t>; | ||
35 | |||
36 | #endif /* end of include guard: RECTANGLE_H_23049366 */ | ||