Skip to main content

aabb Struct Template

Axis-Aligned Bounding Box for spatial culling and collision detection. More...

Declaration

template <helios::math::concepts::IsNumeric T> struct helios::math::aabb<T> { ... }

Public Constructors Index

template <helios::math::concepts::IsNumeric T>
constexpraabb () noexcept

Constructs an empty AABB with inverted min/max values. More...

template <helios::math::concepts::IsNumeric T>
constexpraabb (const T minX, const T minY, const T minZ, const T maxX, const T maxY, const T maxZ) noexcept

Constructs an AABB from individual component values. More...

template <helios::math::concepts::IsNumeric T>
constexpraabb (const helios::math::vec3< T > min, const helios::math::vec3< T > max) noexcept

Constructs an AABB from two corner points. More...

Public Member Functions Index

template <helios::math::concepts::IsNumeric T>
auto min () const noexcept -> constexpr const helios::math::vec3< T > &

Returns the minimum corner point of the AABB. More...

template <helios::math::concepts::IsNumeric T>
auto max () const noexcept -> constexpr const helios::math::vec3< T > &

Returns the maximum corner point of the AABB. More...

template <helios::math::concepts::IsNumeric T>
auto center () const noexcept -> constexpr helios::math::vec3< T >

Computes the center point of the AABB. More...

template <helios::math::concepts::IsNumeric T>
auto extent () const noexcept -> constexpr helios::math::vec3< T >

Returns the half-extent of the AABB, i.e. the vector from the center to the max corner. More...

template <helios::math::concepts::IsNumeric T>
auto size () const noexcept -> constexpr helios::math::vec3< T >

Computes the size of the AABB over all axes. More...

template <helios::math::concepts::IsNumeric T>
constexpr boolcontains (const helios::math::aabb< T > &box) const noexcept

Checks if this AABB fully contains another AABB. More...

template <helios::math::concepts::IsNumeric T>
constexpr boolcontains (const helios::math::vec3< T > &point) const noexcept
template <helios::math::concepts::IsNumeric T>
constexpr boolintersects (const helios::math::aabb< T > &box) const noexcept

Checks if this AABB intersects or touches another AABB. More...

template <helios::math::concepts::IsNumeric T>
auto translate (const helios::math::vec3< T > &v) const noexcept -> constexpr helios::math::aabb< T >

Translates the AABB by a given vector. More...

template <helios::math::concepts::IsNumeric T>
voidadd (const helios::math::vec3< T > &point) noexcept

Expands the AABB to include a given point. More...

template <helios::math::concepts::IsNumeric T>
auto applyTransform (const mat4< T > &mat) const noexcept -> aabb< T >

Transforms the AABB by a 4x4 transformation matrix. More...

Private Member Attributes Index

template <helios::math::concepts::IsNumeric T>
helios::math::vec3< T >min_

Minimum corner point of the bounding box. More...

template <helios::math::concepts::IsNumeric T>
helios::math::vec3< T >max_

Maximum corner point of the bounding box. More...

Description

Axis-Aligned Bounding Box for spatial culling and collision detection.

An AABB is defined by two corner points: a minimum and maximum point in 3D space. Depending on the use case, the box is aligned to the world or local coordinate axes.

Common use cases include frustum culling, broad-phase collision detection, and spatial partitioning in scene graphs.

Template Parameters
T

The numeric type of the vector components (typically float or double).

See Also

[Gla95, pp. 548-550] Glassner, A. (1995). Graphics Gems

See Also

[DP11, pp. 304-311] Dunn, F., & Parberry, I. (2011). 3D Math Primer for Graphics and Game Development

Definition at line 34 of file aabb.ixx.

Public Constructors

aabb()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::aabb< T >::aabb ()
inline constexpr noexcept

Constructs an empty AABB with inverted min/max values.

The AABB is initialized with min set to the maximum representable value and max set to the minimum representable value. This allows the first add() call to properly establish the initial bounds.

Definition at line 60 of file aabb.ixx.

60 constexpr aabb() noexcept
61 : min_{std::numeric_limits<T>::max(), std::numeric_limits<T>::max(), std::numeric_limits<T>::max()},
62 max_{std::numeric_limits<T>::lowest(), std::numeric_limits<T>::lowest(), std::numeric_limits<T>::lowest()}
63 {}

aabb()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::aabb< T >::aabb (const T minX, const T minY, const T minZ, const T maxX, const T maxY, const T maxZ)
inline constexpr noexcept

Constructs an AABB from individual component values.

Parameters
minX

Minimum X coordinate.

minY

Minimum Y coordinate.

minZ

Minimum Z coordinate.

maxX

Maximum X coordinate.

maxY

Maximum Y coordinate.

maxZ

Maximum Z coordinate.

Definition at line 75 of file aabb.ixx.

75 constexpr aabb(const T minX, const T minY, const T minZ, const T maxX, const T maxY, const T maxZ) noexcept
76 : min_{minX, minY, minZ},
77 max_{maxX, maxY, maxZ}
78 {}

aabb()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::aabb< T >::aabb (const helios::math::vec3< T > min, const helios::math::vec3< T > max)
inline constexpr noexcept

Constructs an AABB from two corner points.

Parameters
min

The minimum corner point (smallest x, y, z).

max

The maximum corner point (largest x, y, z).

Definition at line 86 of file aabb.ixx.

86 constexpr aabb(const helios::math::vec3<T> min, const helios::math::vec3<T> max) noexcept
87 : min_(min),
88 max_(max)
89 {}

Public Member Functions

add()

template <helios::math::concepts::IsNumeric T>
void helios::math::aabb< T >::add (const helios::math::vec3< T > & point)
inline noexcept

Expands the AABB to include a given point.

Updates the minimum and maximum bounds to ensure the specified point lies within the AABB. Each component is compared independently:

  • If a component of the point is smaller than the current minimum, the minimum is updated.
  • If a component of the point is larger than the current maximum, the maximum is updated.
Parameters
point

The 3D point to include in the bounding box.

Definition at line 220 of file aabb.ixx.

220 void add(const helios::math::vec3<T>& point) noexcept {
221 min_[0] = std::min(min_[0], point[0]);
222 min_[1] = std::min(min_[1], point[1]);
223 min_[2] = std::min(min_[2], point[2]);
224
225 max_[0] = std::max(max_[0], point[0]);
226 max_[1] = std::max(max_[1], point[1]);
227 max_[2] = std::max(max_[2], point[2]);
228 }

applyTransform()

template <helios::math::concepts::IsNumeric T>
aabb< T > helios::math::aabb< T >::applyTransform (const mat4< T > & mat)
inline noexcept

Transforms the AABB by a 4x4 transformation matrix.

Applies a transformation matrix to the AABB and returns a new axis-aligned bounding box that fully contains the transformed original. This method preserves the axis-aligned property by computing new min/max bounds from the transformed corners.

The algorithm efficiently transforms only the min/max corners instead of all 8 vertices, using Arvo's optimization technique from Graphics Gems.

Parameters
mat

The 4x4 transformation matrix to apply.

Returns

A new AABB that fully contains the transformed bounding box.

See Also

[Gla95, pp. 548-550] "Transforming Axis-Aligned Bounding Boxes" by James Arvo

Definition at line 246 of file aabb.ixx.

246 [[nodiscard]] aabb<T> applyTransform(const mat4<T>& mat) const noexcept {
247
248 const T translationX = static_cast<T>(mat(0, 3));
249 const T translationY = static_cast<T>(mat(1, 3));
250 const T translationZ = static_cast<T>(mat(2, 3));
251
252 vec3<T> newMin = {translationX, translationY, translationZ};
253 vec3<T> newMax = newMin;
254
255 for (int i = 0; i < 3; ++i) {
256 for (int j = 0; j < 3; ++j) {
257
258 T val = static_cast<T>(mat(j, i));
259
260 T e = val * min_[i];
261 T f = val * max_[i];
262
263 if (e < f) {
264 newMin[j] += e;
265 newMax[j] += f;
266 } else {
267 newMin[j] += f;
268 newMax[j] += e;
269 }
270 }
271 }
272
273 return aabb<T>(newMin, newMax);
274 }

center()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::vec3< T > helios::math::aabb< T >::center ()
inline constexpr noexcept

Computes the center point of the AABB.

Returns

The center point, calculated as (min + max) / 2.

Definition at line 114 of file aabb.ixx.

114 [[nodiscard]] constexpr helios::math::vec3<T> center() const noexcept {
115 return (min_ + max_) * static_cast<T>(0.5);
116 }

contains()

template <helios::math::concepts::IsNumeric T>
constexpr bool helios::math::aabb< T >::contains (const helios::math::aabb< T > & box)
inline constexpr noexcept

Checks if this AABB fully contains another AABB.

Tests whether all corners of the specified bounding box lie within the bounds of this AABB. Both minimum and maximum corners must be contained.

Parameters
box

The AABB to test for containment.

Returns

True if the specified box is fully contained within this AABB, false otherwise.

Definition at line 148 of file aabb.ixx.

148 [[nodiscard]] constexpr bool contains(const helios::math::aabb<T>& box) const noexcept {
149
150 auto v_min = box.min();
151 auto v_max = box.max();
152
153 return v_min[0] >= min_[0] && v_min[1] >= min_[1] && v_min[2] >= min_[2] &&
154 v_max[0] <= max_[0] && v_max[1] <= max_[1] && v_max[2] <= max_[2];
155
156 }

contains()

template <helios::math::concepts::IsNumeric T>
constexpr bool helios::math::aabb< T >::contains (const helios::math::vec3< T > & point)
inline constexpr noexcept

Checks if this AABB fully contains the specified point.

Parameters
point

The vec3 to test for containment.

Returns

True if the specified point is fully contained within this AABB, otherwise false.

Definition at line 165 of file aabb.ixx.

165 [[nodiscard]] constexpr bool contains(const helios::math::vec3<T>& point) const noexcept {
166 return point[0] >= min_[0] && point[1] >= min_[1] && point[2] >= min_[2] &&
167 point[0] <= max_[0] && point[1] <= max_[1] && point[2] <= max_[2];
168 }

extent()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::vec3< T > helios::math::aabb< T >::extent ()
inline constexpr noexcept

Returns the half-extent of the AABB, i.e. the vector from the center to the max corner.

Returns

The extension of the AABB, based on it's center point.

Definition at line 124 of file aabb.ixx.

124 [[nodiscard]] constexpr helios::math::vec3<T> extent() const noexcept {
125 return (max_ - min_) * static_cast<T>(0.5);
126 }

intersects()

template <helios::math::concepts::IsNumeric T>
constexpr bool helios::math::aabb< T >::intersects (const helios::math::aabb< T > & box)
inline constexpr noexcept

Checks if this AABB intersects or touches another AABB.

Parameters
box

The AABB to test for intersection.

Returns

True if the specified box intersects this AABB, false otherwise.

Definition at line 177 of file aabb.ixx.

177 [[nodiscard]] constexpr bool intersects(const helios::math::aabb<T>& box) const noexcept {
178
179 if (max_[0] < box.min()[0] || min_[0] > box.max()[0]) {
180 return false;
181 }
182 if (max_[1] < box.min()[1] || min_[1] > box.max()[1]) {
183 return false;
184 }
185 if (max_[2] < box.min()[2] || min_[2] > box.max()[2]) {
186 return false;
187 }
188 return true;
189 }

max()

template <helios::math::concepts::IsNumeric T>
constexpr const helios::math::vec3< T > & helios::math::aabb< T >::max ()
inline constexpr noexcept

Returns the maximum corner point of the AABB.

Returns

Const reference to the maximum corner point.

Definition at line 105 of file aabb.ixx.

105 [[nodiscard]] constexpr const helios::math::vec3<T>& max() const noexcept {
106 return max_;
107 }

Referenced by helios::math::operator*.

min()

template <helios::math::concepts::IsNumeric T>
constexpr const helios::math::vec3< T > & helios::math::aabb< T >::min ()
inline constexpr noexcept

Returns the minimum corner point of the AABB.

Returns

Const reference to the minimum corner point.

Definition at line 96 of file aabb.ixx.

96 [[nodiscard]] constexpr const helios::math::vec3<T>& min() const noexcept {
97 return min_;
98 }

Referenced by helios::math::operator*.

size()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::vec3< T > helios::math::aabb< T >::size ()
inline constexpr noexcept

Computes the size of the AABB over all axes.

Returns

A vector representing the width, height, and depth of the AABB.

Definition at line 134 of file aabb.ixx.

134 [[nodiscard]] constexpr helios::math::vec3<T> size() const noexcept {
135 return max_ - min_;
136 }

translate()

template <helios::math::concepts::IsNumeric T>
constexpr helios::math::aabb< T > helios::math::aabb< T >::translate (const helios::math::vec3< T > & v)
inline constexpr noexcept

Translates the AABB by a given vector.

Creates a new AABB by adding the components of the given translation vector to the minimum and maximum corner points of the current AABB.

Parameters
v

The translation vector to apply to the AABB.

Returns

A new AABB translated by the given vector.

Definition at line 202 of file aabb.ixx.

202 [[nodiscard]] constexpr helios::math::aabb<T> translate(const helios::math::vec3<T>& v) const noexcept {
204 min_ + v, max_ + v
205 };
206 }

Referenced by helios::math::operator+.

Private Member Attributes

max_

template <helios::math::concepts::IsNumeric T>
helios::math::vec3<T> helios::math::aabb< T >::max_

Maximum corner point of the bounding box.

Contains the largest x, y, and z coordinates across all points within the AABB.

Definition at line 49 of file aabb.ixx.

min_

template <helios::math::concepts::IsNumeric T>
helios::math::vec3<T> helios::math::aabb< T >::min_

Minimum corner point of the bounding box.

Contains the smallest x, y, and z coordinates across all points within the AABB.

Definition at line 42 of file aabb.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.