LeviLamina
Loading...
Searching...
No Matches
BoundingBox.h
1#pragma once
2
3#include "ll/api/coro/Generator.h"
4#include "mc/_HeaderOutputPredefine.h"
5#include "mc/world/level/BlockPos.h"
6
7// auto generated inclusion list
8#include "mc/util/Rotation.h"
9
10// auto generated forward declare list
11// clang-format off
12class BlockPos;
13// clang-format on
14
15
16class AABB;
17
18class BoundingBox : public ll::math::CommutativeGroup<BoundingBox, BlockPos, BlockPos> {
19public:
20 union {
21 BlockPos min, x, r, s;
22 };
23 union {
24 BlockPos max, y, g, t, z, b, p;
25 };
26
27 [[nodiscard]] constexpr BoundingBox() noexcept : min(0), max(0) {}
28 [[nodiscard]] constexpr BoundingBox(class BoundingBox const& k) noexcept = default;
29 constexpr BoundingBox& operator=(class BoundingBox const& k) noexcept = default;
30 [[nodiscard]] constexpr BoundingBox(BlockPos const& min, BlockPos const& max) noexcept : min(min), max(max) {}
31
32 ll::coro::Generator<BlockPos> forEachPos() const {
33 for (int dy = min.y; dy <= max.y; ++dy)
34 for (int dx = min.x; dx <= max.x; ++dx)
35 for (int dz = min.z; dz <= max.z; ++dz) {
36 co_yield BlockPos{dx, dy, dz};
37 }
38 }
39
40 constexpr BoundingBox& merge(BoundingBox const& a) noexcept {
41 *this = BoundingBox{ll::math::min(a.min, min), ll::math::max(a.max, max)};
42 return *this;
43 }
44
45 constexpr BoundingBox& merge(BlockPos const& a) noexcept {
46 *this = BoundingBox{ll::math::min(a, min), ll::math::max(a, max)};
47 return *this;
48 }
49
50 template <typename T, size_t N>
51 [[nodiscard]] constexpr T& get() noexcept {
52 if constexpr (N == 0) {
53 return x;
54 } else if constexpr (N == 1) {
55 return y;
56 } else {
57 static_assert(ll::traits::always_false<T>);
58 }
59 }
60
61 template <typename T, size_t N>
62 [[nodiscard]] constexpr T const& get() const noexcept {
63 if constexpr (N == 0) {
64 return x;
65 } else if constexpr (N == 1) {
66 return y;
67 } else {
68 static_assert(ll::traits::always_false<T>);
69 }
70 }
71
72 [[nodiscard]] bool contains(BlockPos const& a) const noexcept { return a.ge(min).all() && a.le(max).all(); }
73
74 [[nodiscard]] bool contains(BoundingBox const& a) const noexcept {
75 return a.min.ge(min).all() && a.max.le(max).all();
76 }
77
78 [[nodiscard]] BlockPos getSideLength() const noexcept { return max - min + 1; }
79
80 LLNDAPI operator class AABB() const;
81
82public:
83 // member functions
84 // NOLINTBEGIN
85 MCAPI BoundingBox(int _x0, int _y0, int _z0, int _x1, int _y1, int _z1);
86
87 MCAPI void applyTransformation(::BlockPos const& pivot, ::Rotation rotationXZ, bool mirrorX, bool mirrorZ);
88
89 MCAPI bool isValid() const;
90 // NOLINTEND
91
92public:
93 // static functions
94 // NOLINTBEGIN
95 MCAPI static ::std::optional<::BoundingBox> intersect(::BoundingBox const& lhs, ::BoundingBox const& rhs);
96
97 MCAPI static ::BoundingBox orientBox(
98 int footX,
99 int footY,
100 int footZ,
101 int offX,
102 int offY,
103 int width,
104 int height,
105 int depth,
106 int orientation,
107 int offZ
108 );
109 // NOLINTEND
110
111public:
112 // constructor thunks
113 // NOLINTBEGIN
114 MCFOLD void* $ctor();
115
116 MCAPI void* $ctor(int _x0, int _y0, int _z0, int _x1, int _y1, int _z1);
117 // NOLINTEND
118};
Definition AABB.h:16
Definition BlockPos.h:18
Definition BoundingBox.h:18
Definition Generator.h:13
Definition CommutativeGroup.h:17