added new methods

This commit is contained in:
2026-04-19 23:20:29 +03:00
parent dfd18e96fb
commit 1c0619ff7b
2 changed files with 161 additions and 31 deletions

View File

@@ -7,6 +7,8 @@
namespace omath::primitives
{
enum class UpAxis { X, Y, Z };
template<class Type>
struct Aabb final
{
@@ -24,6 +26,37 @@ namespace omath::primitives
{
return (max - min) / static_cast<Type>(2);
}
template<UpAxis Up = UpAxis::Y>
[[nodiscard]]
constexpr Vector3<Type> top() const noexcept
{
const auto aabb_center = center();
if constexpr (Up == UpAxis::Z)
return {aabb_center.x, aabb_center.y, max.z};
else if constexpr (Up == UpAxis::X)
return {max.x, aabb_center.y, aabb_center.z};
else if constexpr (Up == UpAxis::Y)
return {aabb_center.x, max.y, aabb_center.z};
else
std::unreachable();
}
template<UpAxis Up = UpAxis::Y>
[[nodiscard]]
constexpr Vector3<Type> bottom() const noexcept
{
const auto aabb_center = center();
if constexpr (Up == UpAxis::Z)
return {aabb_center.x, aabb_center.y, min.z};
else if constexpr (Up == UpAxis::X)
return {min.x, aabb_center.y, aabb_center.z};
else if constexpr (Up == UpAxis::Y)
return {aabb_center.x, min.y, aabb_center.z};
else
std::unreachable();
}
[[nodiscard]]
constexpr bool is_collide(const Aabb& other) const noexcept
{