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