Skip to main content

aabb Struct Template

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

Declaration

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

Public Constructors Index

template <helios::math::Numeric T>
constexpraabb () noexcept

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

template <helios::math::Numeric 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::Numeric 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::Numeric T>
constexpr auto min () const noexcept -> const helios::math::vec3< T > &

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

template <helios::math::Numeric 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::Numeric T>
helios::math::vec3< T >min_

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

template <helios::math::Numeric 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::Numeric T>
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 {}

Referenced by helios::math::aabb< float >::applyTransform.

aabb()

template <helios::math::Numeric T>
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::Numeric T>
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::Numeric 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 209 of file aabb.ixx.

209 void add(const helios::math::vec3<T>& point) noexcept {
210 min_[0] = std::min(min_[0], point[0]);
211 min_[1] = std::min(min_[1], point[1]);
212 min_[2] = std::min(min_[2], point[2]);
213
214 max_[0] = std::max(max_[0], point[0]);
215 max_[1] = std::max(max_[1], point[1]);
216 max_[2] = std::max(max_[2], point[2]);
217 }

applyTransform()

template <helios::math::Numeric T>
aabb< T > helios::math::aabb< T >::applyTransform (const mat4< T > & mat)
inline nodiscard 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 235 of file aabb.ixx.

235 [[nodiscard]] aabb<T> applyTransform(const mat4<T>& mat) const noexcept {
236
237 const T translationX = static_cast<T>(mat(0, 3));
238 const T translationY = static_cast<T>(mat(1, 3));
239 const T translationZ = static_cast<T>(mat(2, 3));
240
241 vec3<T> newMin = {translationX, translationY, translationZ};
242 vec3<T> newMax = newMin;
243
244 for (int i = 0; i < 3; ++i) {
245 for (int j = 0; j < 3; ++j) {
246
247 T val = static_cast<T>(mat(j, i));
248
249 T e = val * min_[i];
250 T f = val * max_[i];
251
252 if (e < f) {
253 newMin[j] += e;
254 newMax[j] += f;
255 } else {
256 newMin[j] += f;
257 newMax[j] += e;
258 }
259 }
260 }
261
262 return aabb<T>(newMin, newMax);
263 }

center()

template <helios::math::Numeric T>
helios::math::vec3< T > helios::math::aabb< T >::center ()
inline nodiscard 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::Numeric T>
bool helios::math::aabb< T >::contains (const helios::math::aabb< T > & box)
inline nodiscard 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 137 of file aabb.ixx.

137 [[nodiscard]] constexpr bool contains(const helios::math::aabb<T>& box) const noexcept {
138
139 auto v_min = box.min();
140 auto v_max = box.max();
141
142 return v_min[0] >= min_[0] && v_min[1] >= min_[1] && v_min[2] >= min_[2] &&
143 v_max[0] <= max_[0] && v_max[1] <= max_[1] && v_max[2] <= max_[2];
144
145 }

Referenced by helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::getPosition.

contains()

template <helios::math::Numeric T>
bool helios::math::aabb< T >::contains (const helios::math::vec3< T > & point)
inline nodiscard 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 154 of file aabb.ixx.

154 [[nodiscard]] constexpr bool contains(const helios::math::vec3<T>& point) const noexcept {
155 return point[0] >= min_[0] && point[1] >= min_[1] && point[2] >= min_[2] &&
156 point[0] <= max_[0] && point[1] <= max_[1] && point[2] <= max_[2];
157 }

intersects()

template <helios::math::Numeric T>
bool helios::math::aabb< T >::intersects (const helios::math::aabb< T > & box)
inline nodiscard 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 166 of file aabb.ixx.

166 [[nodiscard]] constexpr bool intersects(const helios::math::aabb<T>& box) const noexcept {
167
168 if (max_[0] < box.min()[0] || min_[0] > box.max()[0]) {
169 return false;
170 }
171 if (max_[1] < box.min()[1] || min_[1] > box.max()[1]) {
172 return false;
173 }
174 if (max_[2] < box.min()[2] || min_[2] > box.max()[2]) {
175 return false;
176 }
177 return true;
178 }

Referenced by helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::solveCell.

max()

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

min()

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

size()

template <helios::math::Numeric T>
helios::math::vec3< T > helios::math::aabb< T >::size ()
inline nodiscard 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 123 of file aabb.ixx.

123 [[nodiscard]] constexpr helios::math::vec3<T> size() const noexcept {
124 return max_ - min_;
125 }

Referenced by helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::getPosition and helios::engine::runtime::spawn::behavior::placements::ColumnSpawnPlacer::getPosition.

translate()

template <helios::math::Numeric T>
helios::math::aabb< T > helios::math::aabb< T >::translate (const helios::math::vec3< T > & v)
inline nodiscard 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 191 of file aabb.ixx.

191 [[nodiscard]] constexpr helios::math::aabb<T> translate(const helios::math::vec3<T>& v) const noexcept {
193 min_ + v, max_ + v
194 };
195 }

Referenced by helios::engine::runtime::spawn::behavior::placements::AxisSpawnPlacer::getPosition and helios::math::operator+.

Private Member Attributes

max_

template <helios::math::Numeric 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::Numeric 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.15.0.