20 #ifndef ANTKEEPER_GEOM_PRIMITIVES_HYPERRECTANGLE_HPP
21 #define ANTKEEPER_GEOM_PRIMITIVES_HYPERRECTANGLE_HPP
27 namespace primitives {
35 template <
class T, std::
size_t N>
56 for (std::size_t i = 0; i < N; ++i)
75 for (std::size_t i = 0; i < N; ++i)
77 if (other.min[i] <
min[i] || other.max[i] >
max[i])
135 for (std::size_t i = 0; i < N; ++i)
137 if (other.min[i] >
max[i] || other.max[i] <
min[i])
154 return size() / T{2};
162 for (std::size_t i = 0; i < N; ++i)
174 [[nodiscard]] constexpr T
volume() const noexcept
177 for (std::size_t i = 1; i < N; ++i)
193 for (std::size_t i = 0; i < N; ++i)
195 p[i] = ((index >> ((N - 1) - i)) & 1) ?
max[i] :
min[i];
204 using namespace primitives;
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
T length(const quaternion< T > &q)
Calculates the length of a quaternion.
constexpr vector< T, N > abs(const vector< T, N > &x)
Returns the absolute values of each element.
constexpr vector< T, N > min(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the minimum elements of two vectors.
n-dimensional axis-aligned rectangle.
vector_type min
Minimum extent of the hyperrectangle.
constexpr bool intersects(const hyperrectangle &other) const noexcept
Tests whether another hyperrectangle intersects this hyperrectangle.
constexpr bool contains(const hyperrectangle &other) const noexcept
Tests whether another hyperrectangle is contained within this hyperrectangle.
constexpr bool contains(const vector_type &point) const noexcept
Tests whether a point is contained within this hyperrectangle.
constexpr vector_type extents() const noexcept
Calculates the extents of the hyperrectangle.
vector_type max
Maximum extent of the hyperrectangle.
void extend(const vector_type &point) noexcept
Extends the hyperrectangle to include a point.
constexpr bool degenerate() const noexcept
Returns true if any coordinates of min are greater than max, false otherwise.
constexpr T volume() const noexcept
Calculates the volume of the hyperrectangle.
constexpr vector_type center() const noexcept
Returns the center position of the hyperrectangle.
constexpr vector_type corner(std::size_t index) const noexcept
Returns the nth corner of the hyperrectangle.
constexpr vector_type size() const noexcept
Calculates the size of the hyperrectangle.
T distance(const vector_type &point) const noexcept
Calculates the signed distance from the hyperrectangle to a point.
void extend(const hyperrectangle &other) noexcept
Extends the hyperrectangle to include another hyperrectangle.
static constexpr vector zero() noexcept
Returns a zero vector, where every element is equal to zero.