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