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: Vec3AImplementations§
Source§impl Aabb
impl Aabb
Sourcepub fn new(min: impl Into<Vec3A>, max: impl Into<Vec3A>) -> Aabb
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.
Sourcepub fn from_center_half_extents(
center: impl Into<Vec3A>,
half_extents: impl Into<Vec3A>,
) -> Aabb
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.
Sourcepub fn from_points(points: impl IntoIterator<Item = impl Into<Vec3A>>) -> Aabb
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.
Sourcepub fn is_empty(self) -> bool
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().
Sourcepub fn is_degenerate(self) -> bool
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.
Sourcepub fn half_extents(self) -> Vec3A
pub fn half_extents(self) -> Vec3A
Returns the half-extents (half the size on each axis).
Sourcepub fn volume(self) -> f32
pub fn volume(self) -> f32
Returns the total volume of the AABB.
Returns 0.0 for an empty AABB.
Sourcepub fn surface_area(self) -> f32
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.
Sourcepub fn contains_point(self, pt: impl Into<Vec3A>) -> bool
pub fn contains_point(self, pt: impl Into<Vec3A>) -> bool
Returns true if the point lies inside or on the boundary of this AABB.
Sourcepub fn contains_aabb(self, other: Aabb) -> bool
pub fn contains_aabb(self, other: Aabb) -> bool
Returns true if other is entirely contained within this AABB.
Sourcepub fn closest_point(self, pt: impl Into<Vec3A>) -> Vec3A
pub fn closest_point(self, pt: impl Into<Vec3A>) -> Vec3A
Returns the closest point on (or inside) the AABB to the given point.
Sourcepub fn distance_sq_to_point(self, pt: impl Into<Vec3A>) -> f32
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.
Sourcepub fn distance_to_point(self, pt: impl Into<Vec3A>) -> f32
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.
Sourcepub fn intersects(self, other: Aabb) -> bool
pub fn intersects(self, other: Aabb) -> bool
Returns true if this AABB overlaps other.
Edge/face-touching counts as intersection.
Sourcepub fn intersects_exclusive(self, other: Aabb) -> bool
pub fn intersects_exclusive(self, other: Aabb) -> bool
Returns true if this AABB strictly overlaps other.
Edge/face-touching does NOT count as intersection.
Sourcepub fn intersection(self, other: Aabb) -> Option<Aabb>
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).
Sourcepub fn merge(self, other: Aabb) -> Aabb
pub fn merge(self, other: Aabb) -> Aabb
Returns a new AABB that is the union of self and other.
Sourcepub fn expand(self, amount: f32) -> Aabb
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.
Sourcepub fn transform(self, mat: &Mat4) -> Aabb
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.
Trait Implementations§
impl Copy for Aabb
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().