Struct AABB

Struct Documentation

struct AABB

Axis-aligned bounding box.

Stores component-wise minima/maxima and provides helpers for:

  • Union/expansion with points or other AABBs.

  • Longest axis query (for BVH splitting).

  • Robust ray-box intersection (slabs method).

  • XY containment with and without Z tolerance.

Public Functions

inline void expand(const Vec3 &p)

Expand the box to include a point p.

Parameters:

p – Point to merge into this AABB.

inline void expand(const AABB &b)

Expand the box to include another box b (component-wise union).

Parameters:

b – Other AABB to merge.

inline int longest_axis() const

Return the index of the longest axis (0=x, 1=y, 2=z).

Returns:

Axis index with the largest extent.

inline bool intersects_ray(const Vec3 &o, const Vec3 &d, float tmax = 1e30f) const

Robust ray-box intersection (slabs method).

Intersects ray (o + t * d) against the box. Handles zero components in direction d by checking slab containment on that axis.

Parameters:
  • oRay origin.

  • dRay direction.

  • tmax – Upper bound for t interval (can be +inf).

Returns:

True if the ray intersects the box with some t in [0, tmax].

inline bool contains_xy(const Vec3 &p, float z_eps) const

2D containment test on XY with tolerance in Z.

Checks if point p lies inside the XY rectangle and within a vertical band around [min.z, max.z] expanded by z_eps.

Parameters:
  • p – Query point.

  • z_eps – Extra vertical half-thickness tolerance.

Returns:

True if inside XY and |z - [min.z,max.z]| <= z_eps.

inline bool contains_xy_only(const Vec3 &p) const

2D containment test on XY only (no Z check).

Parameters:

p – Query point.

Returns:

True if inside XY rectangle [min,max].

Public Members

Vec3 min = {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()}

Minimum corner (x_min, y_min, z_min). Initialized to +inf.

Vec3 max = {-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()}

Maximum corner (x_max, y_max, z_max). Initialized to -inf.