Skip to content

Commit

Permalink
fix: fix boxes' get
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Dec 31, 2024
1 parent 3fd1026 commit 939edc6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 21 deletions.
28 changes: 17 additions & 11 deletions src/mc/world/level/levelgen/structure/BoundingBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,26 @@ class BoundingBox : public ll::math::CommutativeGroup<BoundingBox, BlockPos, Blo
return *this;
}

template <typename T>
[[nodiscard]] constexpr T& get(size_t index) noexcept {
if (index == 1) {
return (T&)z;
template <typename T, size_t N>
[[nodiscard]] constexpr T& get() noexcept {
if constexpr (N == 0) {
return x;
} else if constexpr (N == 1) {
return y;
} else {
static_assert(ll::traits::always_false<T>);
}
return (T&)x;
}

template <typename T>
[[nodiscard]] constexpr T const& get(size_t index) const noexcept {
if (index == 1) {
return (T const&)z;
template <typename T, size_t N>
[[nodiscard]] constexpr T const& get() const noexcept {
if constexpr (N == 0) {
return x;
} else if constexpr (N == 1) {
return y;
} else {
static_assert(ll::traits::always_false<T>);
}
return (T const&)x;
}

[[nodiscard]] bool contains(BlockPos const& a) const noexcept { return a.ge(min).all() && a.le(max).all(); }
Expand Down Expand Up @@ -99,4 +105,4 @@ class BoundingBox : public ll::math::CommutativeGroup<BoundingBox, BlockPos, Blo

MCAPI void* $ctor(::BlockPos const& min, ::BlockPos const& size, ::Rotation rotation);
// NOLINTEND
};
}
27 changes: 17 additions & 10 deletions src/mc/world/phys/AABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,26 @@ class AABB : public ll::math::CommutativeGroup<AABB, Vec3, Vec3> {
return *this;
}

template <typename T>
[[nodiscard]] constexpr T& get(size_t index) noexcept {
if (index == 1) {
return (T&)z;
template <typename T, size_t N>
[[nodiscard]] constexpr T& get() noexcept {
if constexpr (N == 0) {
return x;
} else if constexpr (N == 1) {
return y;
} else {
static_assert(ll::traits::always_false<T>);
}
return (T&)x;
}
template <typename T>
[[nodiscard]] constexpr T const& get(size_t index) const noexcept {
if (index == 1) {
return (T const&)z;

template <typename T, size_t N>
[[nodiscard]] constexpr T const& get() const noexcept {
if constexpr (N == 0) {
return x;
} else if constexpr (N == 1) {
return y;
} else {
static_assert(ll::traits::always_false<T>);
}
return (T const&)x;
}

[[nodiscard]] constexpr bool contains(Vec3 const& a) const noexcept { return a.ge(min).all() && a.le(max).all(); }
Expand Down

0 comments on commit 939edc6

Please sign in to comment.