diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-09 22:43:20 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-09 22:43:20 -0400 |
commit | 475b7a38f66071ad5713f6f00a49c4e1399e0613 (patch) | |
tree | 4dcb76d5bb9e1dbabe19dcbd0cc9676c31f715e6 /vendor/quadtree/Box.h | |
parent | 829bb6ba7fdbef5c4e6fb9e4eabc0c2f962325ae (diff) | |
parent | 14d075e02007aeb53dbadd6c629564ee467cd7b2 (diff) | |
download | lingo-ap-tracker-475b7a38f66071ad5713f6f00a49c4e1399e0613.tar.gz lingo-ap-tracker-475b7a38f66071ad5713f6f00a49c4e1399e0613.tar.bz2 lingo-ap-tracker-475b7a38f66071ad5713f6f00a49c4e1399e0613.zip |
Merge branch 'main' into panels
Diffstat (limited to 'vendor/quadtree/Box.h')
-rw-r--r-- | vendor/quadtree/Box.h | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/vendor/quadtree/Box.h b/vendor/quadtree/Box.h new file mode 100644 index 0000000..65182bf --- /dev/null +++ b/vendor/quadtree/Box.h | |||
@@ -0,0 +1,67 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "Vector2.h" | ||
4 | |||
5 | namespace quadtree | ||
6 | { | ||
7 | |||
8 | template<typename T> | ||
9 | class Box | ||
10 | { | ||
11 | public: | ||
12 | T left; | ||
13 | T top; | ||
14 | T width; // Must be positive | ||
15 | T height; // Must be positive | ||
16 | |||
17 | constexpr Box(T Left = 0, T Top = 0, T Width = 0, T Height = 0) noexcept : | ||
18 | left(Left), top(Top), width(Width), height(Height) | ||
19 | { | ||
20 | |||
21 | } | ||
22 | |||
23 | constexpr Box(const Vector2<T>& position, const Vector2<T>& size) noexcept : | ||
24 | left(position.x), top(position.y), width(size.x), height(size.y) | ||
25 | { | ||
26 | |||
27 | } | ||
28 | |||
29 | constexpr T getRight() const noexcept | ||
30 | { | ||
31 | return left + width; | ||
32 | } | ||
33 | |||
34 | constexpr T getBottom() const noexcept | ||
35 | { | ||
36 | return top + height; | ||
37 | } | ||
38 | |||
39 | constexpr Vector2<T> getTopLeft() const noexcept | ||
40 | { | ||
41 | return Vector2<T>(left, top); | ||
42 | } | ||
43 | |||
44 | constexpr Vector2<T> getCenter() const noexcept | ||
45 | { | ||
46 | return Vector2<T>(left + width / 2, top + height / 2); | ||
47 | } | ||
48 | |||
49 | constexpr Vector2<T> getSize() const noexcept | ||
50 | { | ||
51 | return Vector2<T>(width, height); | ||
52 | } | ||
53 | |||
54 | constexpr bool contains(const Box<T>& box) const noexcept | ||
55 | { | ||
56 | return left <= box.left && box.getRight() <= getRight() && | ||
57 | top <= box.top && box.getBottom() <= getBottom(); | ||
58 | } | ||
59 | |||
60 | constexpr bool intersects(const Box<T>& box) const noexcept | ||
61 | { | ||
62 | return !(left >= box.getRight() || getRight() <= box.left || | ||
63 | top >= box.getBottom() || getBottom() <= box.top); | ||
64 | } | ||
65 | }; | ||
66 | |||
67 | } \ No newline at end of file | ||