Skip to main content

Aabb

Struct Aabb 

Source
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: Vec3

Lowest corner.

§max: Vec3

Highest corner.

Implementations§

Source§

impl Aabb

Source

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.

Source

pub fn center(&self) -> Vec3

The box’s centre.

Source

pub fn half_extent(&self) -> Vec3

Half the box’s size along each axis.

Source

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.

Trait Implementations§

Source§

impl Clone for Aabb

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Aabb

Source§

impl Debug for Aabb

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Aabb

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Aabb

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Aabb

Auto Trait Implementations§

§

impl Forget for Aabb

§

impl Freeze for Aabb

§

impl Move for Aabb

§

impl RefUnwindSafe for Aabb

§

impl Send for Aabb

§

impl Sync for Aabb

§

impl Unpin for Aabb

§

impl UnsafeUnpin for Aabb

§

impl UnwindSafe for Aabb

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.