utility 2026.1.9
A comprehensive C++ utilities library tailored for the development of modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
utility::math::Aabb< T > Class Template Reference

Axis-aligned bounding box (AABB) in 3D space. More...

#include <headers/utility/math/aabb.hpp>

Public Member Functions

 Aabb (void)
 Default constructor creating an empty (inverted) box.
 
 Aabb (const Vector< T, 3 > &min, const Vector< T, 3 > &max)
 Construct from explicit minimum and maximum corners.
 
void include (const Vector< T, 3 > &point) noexcept
 Grow the box to contain a point.
 
void include (const Aabb &other) noexcept
 Grow the box to contain another box (union).
 
Vector< T, 3 > center (void) const noexcept
 Get the center of the box.
 
Vector< T, 3 > extents (void) const noexcept
 Get the full size of the box along each axis.
 
Vector< T, 3 > halfSize (void) const noexcept
 Get half the size of the box along each axis.
 
radius (void) const noexcept
 Get the radius of the bounding sphere around the box.
 
Vector< T, 3 > positiveVertex (const Vector< T, 3 > &normal) const noexcept
 Get the corner farthest along a direction (the "p-vertex").
 
bool contains (const Vector< T, 3 > &point) const noexcept
 Test whether a point lies inside the box (boundaries included).
 
bool intersects (const Aabb &other) const noexcept
 Test whether two boxes overlap (touching counts).
 
bool isEmpty (void) const noexcept
 Test whether the box is empty (inverted).
 
Vector< T, 3 > getMin (void) const noexcept
 Get the minimum corner.
 
Vector< T, 3 > getMax (void) const noexcept
 Get the maximum corner.
 

Static Public Member Functions

template<std::input_iterator Iterator, std::sentinel_for< Iterator > Sentinel>
static Aabb fromPoints (Iterator first, Sentinel last)
 Build the tightest box containing a range of 3D points.
 
static Aabb fromPoints (std::span< const Vector< T, 3 > > points)
 Build the tightest box containing a contiguous range of points.
 

Detailed Description

template<CanBeVectorComponent T>
class utility::math::Aabb< T >

Axis-aligned bounding box (AABB) in 3D space.

Stores the two opposite corners of a box whose faces are aligned with the coordinate axes. The default-constructed box is "empty" (inverted, min > max on at least one axis) so that it can be grown with include(); consumers must check isEmpty() before treating an instance as a valid bound.

Template Parameters
TFloating-point component type (e.g. float or double).

Definition at line 53 of file aabb.hpp.

Constructor & Destructor Documentation

◆ Aabb() [1/2]

template<CanBeVectorComponent T>
utility::math::Aabb< T >::Aabb ( void  )
inline

Default constructor creating an empty (inverted) box.

The box has no valid bounds until include() or assignment from fromPoints(). isEmpty() returns true.

Definition at line 66 of file aabb.hpp.

◆ Aabb() [2/2]

template<CanBeVectorComponent T>
utility::math::Aabb< T >::Aabb ( const Vector< T, 3 > &  min,
const Vector< T, 3 > &  max 
)
inline

Construct from explicit minimum and maximum corners.

Parameters
minThe minimum corner.
maxThe maximum corner.

Definition at line 77 of file aabb.hpp.

Member Function Documentation

◆ center()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::center ( void  ) const
inlinenoexcept

Get the center of the box.

Computed by halving each corner before summing so that boxes with very large coordinates do not overflow.

Returns
The center point.

Definition at line 153 of file aabb.hpp.

◆ contains()

template<CanBeVectorComponent T>
bool utility::math::Aabb< T >::contains ( const Vector< T, 3 > &  point) const
inlinenoexcept

Test whether a point lies inside the box (boundaries included).

Parameters
pointThe point to test.
Returns
True if the point is contained, false otherwise (also false for an empty box).

Definition at line 214 of file aabb.hpp.

Here is the call graph for this function:

◆ extents()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::extents ( void  ) const
inlinenoexcept

Get the full size of the box along each axis.

Returns
max - min, or a zero vector when the box is empty.

Definition at line 162 of file aabb.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromPoints() [1/2]

template<CanBeVectorComponent T>
template<std::input_iterator Iterator, std::sentinel_for< Iterator > Sentinel>
static Aabb utility::math::Aabb< T >::fromPoints ( Iterator  first,
Sentinel  last 
)
inlinestatic

Build the tightest box containing a range of 3D points.

If the range is empty, the resulting box is empty (isEmpty()).

Template Parameters
IteratorInput iterator type.
SentinelSentinel type matching Iterator.
Parameters
firstIterator to the first point.
lastSentinel marking the end of the range.
Returns
The bounding box of all points in the range.

Definition at line 95 of file aabb.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromPoints() [2/2]

template<CanBeVectorComponent T>
static Aabb utility::math::Aabb< T >::fromPoints ( std::span< const Vector< T, 3 > >  points)
inlinestatic

Build the tightest box containing a contiguous range of points.

Accepts any contiguous range implicitly convertible to std::span<const Vector<T, 3>> (e.g. std::vector, std::array). If the range is empty, the resulting box is empty.

Parameters
pointsThe points to bound.
Returns
The bounding box of all points.

Definition at line 114 of file aabb.hpp.

Here is the call graph for this function:

◆ getMax()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::getMax ( void  ) const
inlinenoexcept

Get the maximum corner.

Returns
The maximum corner.

Definition at line 273 of file aabb.hpp.

◆ getMin()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::getMin ( void  ) const
inlinenoexcept

Get the minimum corner.

Returns
The minimum corner.

Definition at line 264 of file aabb.hpp.

◆ halfSize()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::halfSize ( void  ) const
inlinenoexcept

Get half the size of the box along each axis.

Returns
extents() * 0.5.

Definition at line 171 of file aabb.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ include() [1/2]

template<CanBeVectorComponent T>
void utility::math::Aabb< T >::include ( const Aabb< T > &  other)
inlinenoexcept

Grow the box to contain another box (union).

Including an empty box is a no-op.

Parameters
otherThe box that must be contained.

Definition at line 137 of file aabb.hpp.

Here is the call graph for this function:

◆ include() [2/2]

template<CanBeVectorComponent T>
void utility::math::Aabb< T >::include ( const Vector< T, 3 > &  point)
inlinenoexcept

Grow the box to contain a point.

Parameters
pointThe point that must be contained.

Definition at line 123 of file aabb.hpp.

Here is the caller graph for this function:

◆ intersects()

template<CanBeVectorComponent T>
bool utility::math::Aabb< T >::intersects ( const Aabb< T > &  other) const
inlinenoexcept

Test whether two boxes overlap (touching counts).

Parameters
otherThe box to test against.
Returns
True if the boxes intersect, false otherwise (also false if either box is empty).

Definition at line 233 of file aabb.hpp.

Here is the call graph for this function:

◆ isEmpty()

template<CanBeVectorComponent T>
bool utility::math::Aabb< T >::isEmpty ( void  ) const
inlinenoexcept

Test whether the box is empty (inverted).

Returns
True if min > max on at least one axis.

Definition at line 250 of file aabb.hpp.

Here is the caller graph for this function:

◆ positiveVertex()

template<CanBeVectorComponent T>
Vector< T, 3 > utility::math::Aabb< T >::positiveVertex ( const Vector< T, 3 > &  normal) const
inlinenoexcept

Get the corner farthest along a direction (the "p-vertex").

For each axis the component of normal selects the maximum when non-negative and the minimum otherwise. This is the support point used by the standard AABB-vs-plane frustum test.

Parameters
normalThe direction to search along.
Returns
The corner of the box farthest along normal.

Definition at line 198 of file aabb.hpp.

◆ radius()

template<CanBeVectorComponent T>
T utility::math::Aabb< T >::radius ( void  ) const
inlinenoexcept

Get the radius of the bounding sphere around the box.

Useful for cheap distance culling.

Returns
The length of halfSize() (zero for an empty box).

Definition at line 182 of file aabb.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following file: