Struct Aabb

Source
#[repr(C)]
pub struct Aabb { pub min: Vec3, pub max: Vec3, }
Expand description

Represents an Axis-Aligned Bounding Box (AABB).

An AABB is a rectangular prism aligned with the coordinate axes, defined by its minimum and maximum corner points. It is a simple but highly efficient volume for broad-phase collision detection and visibility culling.

Fields§

§min: Vec3

The corner of the box with the smallest coordinates on all axes.

§max: Vec3

The corner of the box with the largest coordinates on all axes.

Implementations§

Source§

impl Aabb

Source

pub const INVALID: Self

An invalid Aabb where min components are positive infinity and max are negative infinity.

This is useful as a neutral starting point for merging operations. Merging any valid Aabb with INVALID will result in that valid Aabb.

Source

pub fn from_min_max(min_pt: Vec3, max_pt: Vec3) -> Self

Creates a new Aabb from two corner points.

This constructor automatically ensures that the min field holds the component-wise minimum and max holds the component-wise maximum, regardless of the order the points are passed in.

Source

pub fn from_center_half_extents(center: Vec3, half_extents: Vec3) -> Self

Creates a new Aabb from a center point and its half-extents.

The half-extents represent the distance from the center to the faces of the box. The provided half_extents will be made non-negative.

Source

pub fn from_point(point: Vec3) -> Self

Creates a degenerate Aabb containing a single point (min and max are the same).

Source

pub fn from_points(points: &[Vec3]) -> Option<Self>

Creates an Aabb that tightly encloses a given set of points.

§Returns

Returns Some(Aabb) if the input slice is not empty, otherwise None.

Source

pub fn center(&self) -> Vec3

Calculates the center point of the Aabb.

Source

pub fn half_extents(&self) -> Vec3

Calculates the half-extents (half the size on each axis) of the Aabb.

Source

pub fn size(&self) -> Vec3

Calculates the full size (width, height, depth) of the Aabb.

Source

pub fn is_valid(&self) -> bool

Checks if the Aabb is valid (i.e., min <= max on all axes). Degenerate boxes where min == max are considered valid.

Source

pub fn contains_point(&self, point: Vec3) -> bool

Checks if a point is contained within or on the boundary of the Aabb.

Source

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

Checks if this Aabb intersects with another Aabb.

Two Aabbs intersect if they overlap on all three axes. Boxes that only touch at the boundary are considered to be intersecting.

Source

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

Creates a new Aabb that encompasses both this Aabb and another one.

Source

pub fn merged_with_point(&self, point: Vec3) -> Self

Creates a new Aabb that encompasses both this Aabb and an additional point.

Source

pub fn transform(&self, matrix: &Mat4) -> Self

Computes the bounding box that encloses this Aabb after a transformation.

This method is more efficient than transforming all 8 corners of the box for affine transformations. It works by transforming the center of the box and then calculating the new extents by projecting the original extents onto the axes of the transformed space.

§Note

This method is designed for affine transformations (like rotation, translation, scale). It may not produce the tightest-fitting box for transformations involving perspective.

Trait Implementations§

Source§

impl Clone for Aabb

Source§

fn clone(&self) -> Aabb

Returns a duplicate of the value. Read more
1.0.0 · 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

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

impl Default for Aabb

Source§

fn default() -> Self

Returns the default Aabb, which is Aabb::INVALID.

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 · 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 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, 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 = 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.