diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-06 15:54:41 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-06-06 15:54:41 -0400 |
commit | 8ddab49cc13d809ca75dcd7f645661a3d3cb05c4 (patch) | |
tree | ba1e5f3237dbb7cdc939c35e193f5e6e46845a77 /vendor/quadtree/Box.h | |
parent | ac38dd0a5c394eefc39b7a8cf7b96762f18c8b31 (diff) | |
parent | 6f5287b3921c843a6b322ccbdfcbef00a8f16980 (diff) | |
download | lingo-ap-tracker-8ddab49cc13d809ca75dcd7f645661a3d3cb05c4.tar.gz lingo-ap-tracker-8ddab49cc13d809ca75dcd7f645661a3d3cb05c4.tar.bz2 lingo-ap-tracker-8ddab49cc13d809ca75dcd7f645661a3d3cb05c4.zip |
Merge branch 'subway'
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 | ||