42#ifndef UFO_GEOMETRY_AABB_HPP
43#define UFO_GEOMETRY_AABB_HPP
46#include <ufo/numeric/vec.hpp>
69template <std::
size_t Dim = 3, std::
floating_po
int T =
float>
86 constexpr AABB() noexcept = default;
121 template <std::convertible_to<T> U>
123 :
min(other.min),
max(other.max)
131 [[nodiscard]]
static constexpr std::size_t
dimension() noexcept {
return Dim; }
167 [[nodiscard]]
constexpr T
volume() const noexcept
171 for (std::size_t i = 1; i < Dim; ++i) {
181 [[nodiscard]]
constexpr AABB aabb() const noexcept {
return *
this; }
205template <std::
size_t Dim, std::
floating_po
int T>
208template <std::
size_t Dim, std::
floating_po
int T>
217template <std::
size_t Dim, std::
floating_po
int T>
220 return out <<
"Min: [" << aabb.
min <<
"], Max: [" << aabb.
max <<
"]";
223template <std::
floating_po
int T>
224using AABB1 = AABB<1, T>;
225template <std::
floating_po
int T>
226using AABB2 = AABB<2, T>;
227template <std::
floating_po
int T>
228using AABB3 = AABB<3, T>;
229template <std::
floating_po
int T>
230using AABB4 = AABB<4, T>;
232using AABB1f = AABB<1, float>;
233using AABB2f = AABB<2, float>;
234using AABB3f = AABB<3, float>;
235using AABB4f = AABB<4, float>;
237using AABB1d = AABB<1, double>;
238using AABB2d = AABB<2, double>;
239using AABB3d = AABB<3, double>;
240using AABB4d = AABB<4, double>;
248template <std::
size_t Dim, std::
floating_po
int T>
249 requires std::formattable<T, char>
250struct std::formatter<
ufo::AABB<Dim, T>> {
251 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
255 return std::format_to(ctx.out(),
"Min: [{}], Max: [{}]", aabb.
min, aabb.
max);
All vision-related classes and functions.
constexpr bool any(Vec< Dim, bool > const &v) noexcept
Returns true if at least one component of a bool vector is true.
constexpr T length(Vec< Dim, T > const &v) noexcept
Computes the Euclidean length (magnitude) of a vector.
Axis-Aligned Bounding Box (AABB) in Dim-dimensional space.
constexpr AABB() noexcept=default
Default constructor.
constexpr Vec< Dim, T > center() const noexcept
Returns the center of the AABB.
Vec< Dim, T > min
The minimum point.
constexpr AABB(Vec< Dim, T > const ¢er, T half_length) noexcept
Constructs an AABB from a center point and a half-length.
constexpr T volume() const noexcept
Returns the volume of the AABB.
constexpr AABB aabb() const noexcept
Returns the AABB of the AABB.
constexpr bool isDegenerate() const noexcept
Returns whether the AABB is degenerate.
constexpr T diagonal() const noexcept
Returns the diagonal length of the AABB.
constexpr Vec< Dim, T > length() const noexcept
Returns the length (extent) of the AABB in each dimension.
constexpr Vec< Dim, T > halfLength() const noexcept
Returns the half-length (extent) of the AABB in each dimension.
constexpr AABB(AABB const &) noexcept=default
Copy constructor.
Vec< Dim, T > max
The maximum point.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the AABB.
bool operator==(AABB const &) const =default
Equality operator.
constexpr AABB(AABB< Dim, U > const &other) noexcept
Converting constructor from an AABB with a different scalar type.
A fixed-size arithmetic vector of up to 4 dimensions.