Skip to main content

Aabb

Struct Aabb 

Source
pub struct Aabb {
    pub min: Vec3A,
    pub max: Vec3A,
}
Expand description

Axis-Aligned Bounding Box (AABB) represented by min/max corners.

Uses Vec3A (16-byte aligned SIMD vector) for performance. An “empty” AABB has min = +INF, max = -INF and represents no volume.

Fields§

§min: Vec3A§max: Vec3A

Implementations§

Source§

impl Aabb

Source

pub fn new(min: impl Into<Vec3A>, max: impl Into<Vec3A>) -> Aabb

Creates an AABB from explicit min/max corners. Caller is responsible for ensuring min <= max on all axes.

Source

pub fn empty() -> Aabb

Creates the canonical empty/invalid AABB (min = +INF, max = -INF).

Source

pub fn from_center_half_extents( center: impl Into<Vec3A>, half_extents: impl Into<Vec3A>, ) -> Aabb

Creates an AABB from a center point and half-extents.

Source

pub fn from_points(points: impl IntoIterator<Item = impl Into<Vec3A>>) -> Aabb

Creates an AABB that contains all the provided points. Returns Aabb::empty() if the iterator is empty.

Source

pub fn is_empty(self) -> bool

Returns true if the AABB has no valid volume and is strictly invalid (min > max on any axis). Note: A degenerate point where min == max is NOT considered empty. This is a deliberate design choice so zero-volume points can still overlap with frustums or other shapes. To check for zero volume, use is_degenerate().

Source

pub fn is_degenerate(self) -> bool

Returns true if the AABB has zero volume (min >= max on any axis). This includes both strictly empty AABBs and degenerate points, lines, or planes.

Source

pub fn is_valid(self) -> bool

Returns true if the AABB has a valid volume.

Source

pub fn center(self) -> Vec3A

Returns the center of the AABB.

Source

pub fn half_extents(self) -> Vec3A

Returns the half-extents (half the size on each axis).

Source

pub fn size(self) -> Vec3A

Returns the full size (extent) on each axis.

Source

pub fn volume(self) -> f32

Returns the total volume of the AABB. Returns 0.0 for an empty AABB.

Source

pub fn surface_area(self) -> f32

Returns the surface area of the AABB. Useful for SAH-based BVH construction. Returns 0.0 for an empty AABB.

Source

pub fn diagonal(self) -> f32

Returns the length of the diagonal of the AABB.

Source

pub fn contains_point(self, pt: impl Into<Vec3A>) -> bool

Returns true if the point lies inside or on the boundary of this AABB.

Source

pub fn contains_aabb(self, other: Aabb) -> bool

Returns true if other is entirely contained within this AABB.

Source

pub fn closest_point(self, pt: impl Into<Vec3A>) -> Vec3A

Returns the closest point on (or inside) the AABB to the given point.

Source

pub fn distance_sq_to_point(self, pt: impl Into<Vec3A>) -> f32

Returns the squared distance from the point to the AABB surface. Returns 0.0 if the point is inside the AABB.

Source

pub fn distance_to_point(self, pt: impl Into<Vec3A>) -> f32

Returns the distance from the point to the AABB surface. Returns 0.0 if the point is inside the AABB.

Source

pub fn intersects(self, other: Aabb) -> bool

Returns true if this AABB overlaps other. Edge/face-touching counts as intersection.

Source

pub fn intersects_exclusive(self, other: Aabb) -> bool

Returns true if this AABB strictly overlaps other. Edge/face-touching does NOT count as intersection.

Source

pub fn intersection(self, other: Aabb) -> Option<Aabb>

Returns the intersection volume as an Aabb, or None if they do not overlap. Edge/face-touching yields a degenerate AABB (zero volume on at least one axis).

Source

pub fn extend(&mut self, pt: impl Into<Vec3A>)

Expands this AABB to include the given point.

Source

pub fn merge(self, other: Aabb) -> Aabb

Returns a new AABB that is the union of self and other.

Source

pub fn expand(self, amount: f32) -> Aabb

Returns a new AABB expanded (inflated) outward by amount on every face. A negative amount shrinks the AABB. If shrinking causes inversion, returns empty.

Source

pub fn transform(self, mat: &Mat4) -> Aabb

Transforms this AABB by a Mat4, returning a new world-space AABB.

Uses Arvo’s method: applies the 3×3 rotation/scale part column-by-column, so only 3 iterations instead of 8 corner transforms.

Reference: James Arvo, “Transforming Axis-Aligned Bounding Boxes”, Graphics Gems, 1990.

Source

pub fn corners(self) -> [Vec3A; 8]

Returns all 8 corners of the AABB in a fixed order. Order: — -+- +– ++- –+ -++ +-+ +++ (xyz sign pattern)

Trait Implementations§

Source§

impl Clone for Aabb

Source§

fn clone(&self) -> Aabb

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 Debug for Aabb

Source§

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

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

impl Default for Aabb

Source§

fn default() -> Aabb

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

impl Display for Aabb

Source§

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

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

impl PartialEq for Aabb

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Aabb

Source§

impl StructuralPartialEq for Aabb

Auto Trait Implementations§

§

impl Freeze 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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,