pub struct Aabb {
pub min: Vec3,
pub max: Vec3,
}Expand description
An axis-aligned bounding box.
Used for a mesh’s local-space bounds — the box around its vertices as
they sit in the pool, before any instance transform — and for the world-space
box Aabb::transformed produces from one.
Fields§
§min: Vec3Lowest corner.
max: Vec3Highest corner.
Implementations§
Source§impl Aabb
impl Aabb
Sourcepub fn from_points(points: impl IntoIterator<Item = Vec3>) -> Option<Self>
pub fn from_points(points: impl IntoIterator<Item = Vec3>) -> Option<Self>
The box containing every point, or None for an empty iterator.
None rather than an empty-box sentinel: there is no box containing
nothing, and the usual encoding for one — min at +INFINITY, max at
-INFINITY — is a pair of values that survive into a buffer and turn
every later comparison into a NaN.
§A NaN lane is skipped, so this is not a validity check
The fold goes through f32::min/f32::max per lane, which return the
other operand when one side is NaN. An unusable coordinate is
therefore ignored and the box still contains every finite point. Only a
lane with no finite value at all comes out NaN, so a wholly degenerate
mesh is still visible as one. An infinity has a defined ordering, is
real data, and is kept.
It is deliberately not Vec3::min/Vec3::max, and the
difference was a bug rather than a preference. glam 0.33 writes those as
a bare if self.x < rhs.x { self.x } else { rhs.x }; every comparison
against NaN is false, so they yield the incoming point and discard
the accumulator. One NaN vertex followed by one finite vertex produced
a finite box that did not contain the geometry — which culls what is
on screen, the direction this module’s header says a cull must never err
in. a_nan_is_skipped_from_every_position_and_never_shrinks_the_box
covers every position because the defect was positional, and it fails
against the glam form.
What this costs callers is detection: from_points(…).is_some(), and
equally a finiteness test on the box that comes out, cannot tell you the
points were finite. A caller needing that must test the points
themselves before folding — apps/viewer’s model module does.
Sourcepub fn half_extent(&self) -> Vec3
pub fn half_extent(&self) -> Vec3
Half the box’s size along each axis.
Sourcepub fn transformed(&self, transform: Mat4) -> Self
pub fn transformed(&self, transform: Mat4) -> Self
The smallest axis-aligned box this module will claim contains
transform applied to this one.
A rotated box is not a box, so this is the standard conservative
construction (Ericson, Real-Time Collision Detection §4.2.6): the new
centre is the transform applied to the old centre, and the new
half-extent is the element-wise absolute value of the transform’s 3×3
part applied to the old half-extent. Along world axis i the box reaches
Σⱼ |m[i][j]| · e[j], which is the furthest any corner can get once every
combination of ±e is allowed — so the result contains the rotated box,
and for a rotation that is not a multiple of a quarter turn it is
strictly larger.
cull.slang performs exactly this arithmetic, which is why a rotated
instance is one of the cases the e2e places deliberately.