summary refs log tree commit diff stats
path: root/src/rectangle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/rectangle.h')
-rw-r--r--src/rectangle.h36
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
6template <typename T>
7class rect {
8public:
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
34using rect4s = rect<size_t>;
35
36#endif /* end of include guard: RECTANGLE_H_23049366 */