Lodestone.Level
Loading...
Searching...
No Matches
Bounds2.h
Go to the documentation of this file.
1//
2// Created by DexrnZacAttack on 10/16/25 using zPc-i2.
3//
4#ifndef LODESTONE_BOUNDS2I_H
5#define LODESTONE_BOUNDS2I_H
6
7#include <format>
8
11
13 template <typename T>
17
18 std::string toString() const override {
19 return std::format("Bounds2[min={}, max={}]", min.toString(),
20 max.toString());
21 };
22
23 constexpr Bounds2(const Vec2<T> &min, const Vec2<T> &max)
24 : min(min), max(max) {};
25
26 constexpr Bounds2(const int x0, const int z0, const int x1,
27 const int z1)
28 : min({x0, z0}), max({x1, z1}) {};
29
30 constexpr bool operator==(const Bounds2 &rhs) const {
31 return min == rhs.min && max == rhs.max;
32 }
33
34 constexpr Bounds2 operator+(const int v) const {
35 return {min + v, max + v};
36 }
37
38 constexpr Bounds2 operator-(const int v) const {
39 return {min - v, max - v};
40 }
41
42 constexpr Bounds2 operator*(const int v) const {
43 return {min * v, max * v};
44 }
45
46 constexpr Bounds2 operator/(const int v) const {
47 return {min / v, max / v};
48 }
49
50 constexpr Bounds2 operator+(const Bounds2 &rhs) const {
51 return {rhs.min * min, rhs.max * max};
52 }
53
54 constexpr Bounds2 operator-(const Bounds2 &rhs) const {
55 return {rhs.min - min, rhs.max - max};
56 }
57
58 constexpr Bounds2 operator*(const Bounds2 &rhs) const {
59 return {rhs.min * min, rhs.max * max};
60 }
61
62 constexpr Bounds2 operator/(const Bounds2 &rhs) const {
63 return {rhs.min / min, rhs.max / max};
64 }
65
66 constexpr bool contains(const Vec2<T> &vec) const noexcept {
67 return vec.x >= min.x && vec.x <= max.x && vec.y >= min.y &&
68 vec.y <= max.y;
69 }
70
71 constexpr bool empty() const noexcept {
72 return max.x < min.x || max.y < min.y;
73 }
74
75 constexpr bool intersects(const Bounds2 &rhs) const noexcept {
76 if (empty() || rhs.empty())
77 return false;
78
79 return !(rhs.max.x < min.x || rhs.min.x > max.x ||
80 rhs.max.y < min.y || rhs.min.y > max.y);
81 }
82
83 constexpr int getWidth() const noexcept {
84 return empty() ? 0 : (max.x - min.x + 1);
85 }
86
87 constexpr int getLength() const noexcept {
88 return empty() ? 0 : (max.y - min.y + 1);
89 }
90 };
91
95} // namespace lodestone::level::types
96
97#endif // LODESTONE_BOUNDS2I_H
#define LODESTONE_API
Definition Bounds2.h:12
Bounds2< double > Bounds2d
Definition Bounds2.h:94
Bounds2< float > Bounds2f
Definition Bounds2.h:93
Bounds2< int > Bounds2i
Definition Bounds2.h:92
Definition Bounds2.h:14
constexpr Bounds2 operator*(const int v) const
Definition Bounds2.h:42
std::string toString() const override
Definition Bounds2.h:18
constexpr Bounds2(const int x0, const int z0, const int x1, const int z1)
Definition Bounds2.h:26
constexpr Bounds2 operator+(const Bounds2 &rhs) const
Definition Bounds2.h:50
constexpr Bounds2 operator+(const int v) const
Definition Bounds2.h:34
constexpr int getLength() const noexcept
Definition Bounds2.h:87
constexpr Bounds2 operator-(const int v) const
Definition Bounds2.h:38
constexpr bool intersects(const Bounds2 &rhs) const noexcept
Definition Bounds2.h:75
constexpr Bounds2(const Vec2< T > &min, const Vec2< T > &max)
Definition Bounds2.h:23
Vec2< int > min
Definition Bounds2.h:15
constexpr bool operator==(const Bounds2 &rhs) const
Definition Bounds2.h:30
constexpr Bounds2 operator/(const int v) const
Definition Bounds2.h:46
constexpr Bounds2 operator-(const Bounds2 &rhs) const
Definition Bounds2.h:54
constexpr bool contains(const Vec2< T > &vec) const noexcept
Definition Bounds2.h:66
constexpr Bounds2 operator*(const Bounds2 &rhs) const
Definition Bounds2.h:58
constexpr int getWidth() const noexcept
Definition Bounds2.h:83
Vec2< int > max
Definition Bounds2.h:16
constexpr Bounds2 operator/(const Bounds2 &rhs) const
Definition Bounds2.h:62
constexpr bool empty() const noexcept
Definition Bounds2.h:71
Definition Vec2.h:12