diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-12 18:45:21 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-12 18:45:21 -0400 |
| commit | e3fbcc9f29a1b1c83b23a4cef3819631fd3117d0 (patch) | |
| tree | ececdc789eda39a9d07da037a839a9906591864e /vendor/quadtree/Box.h | |
| parent | 00658b38bd65e2cb81a502bd72e98ad9c411a7b4 (diff) | |
| download | lingo-ap-tracker-e3fbcc9f29a1b1c83b23a4cef3819631fd3117d0.tar.gz lingo-ap-tracker-e3fbcc9f29a1b1c83b23a4cef3819631fd3117d0.tar.bz2 lingo-ap-tracker-e3fbcc9f29a1b1c83b23a4cef3819631fd3117d0.zip | |
Subway map hover detection with a quadtree
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 | ||
