Skip to main content

Aabb

Struct Aabb 

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

Axis-aligned bounding box for broad-phase collision detection.

Fields§

§min: Vec3

Minimum corner of the bounding box.

§max: Vec3

Maximum corner of the bounding box.

Implementations§

Source§

impl Aabb

Source

pub fn new(min: Vec3, max: Vec3) -> Self

Create a new AABB from min and max corners.

Source

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

Check whether this AABB intersects another.

Source

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

Merge this AABB with another, returning the smallest AABB containing both.

Source

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

Check if a point is inside the AABB.

Source

pub fn expand(&self, margin: Real) -> Self

Expand the AABB by a margin in all directions.

Source

pub fn center(&self) -> Vec3

Center of the AABB.

Source

pub fn half_extents(&self) -> Vec3

Half-extents of the AABB.

Source

pub fn surface_area(&self) -> Real

Surface area of the AABB.

Source

pub fn volume(&self) -> Real

Volume of the AABB.

Source§

impl Aabb

Source

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

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

Source

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

Create an AABB enclosing a set of points.

Source

pub fn longest_axis(&self) -> usize

Longest axis (0=x, 1=y, 2=z).

Source

pub fn diagonal(&self) -> f64

Diagonal length of the AABB.

Source§

impl Aabb

Source

pub fn ray_intersect(&self, ray: &Ray) -> Option<RayAabbHit>

Test whether ray intersects this AABB using the slab method.

Returns Some(hit) with the entry/exit t values if the ray hits, or None if it misses. Handles degenerate (zero-direction) rays.

Source

pub fn ray_hit_t(&self, ray: &Ray) -> Option<Real>

Test ray against AABB and return just the entry t (simpler API).

Source

pub fn swept_aabb(half_extents: Vec3, from: &Transform, to: &Transform) -> Aabb

Compute the AABB of the swept volume as the box moves from transform_a to transform_b (uses the merge of two oriented boxes).

Source

pub fn oriented_box_aabb(half_extents: Vec3, transform: &Transform) -> Aabb

Compute the AABB enclosing an oriented box (defined by half-extents and a transform).

Source

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

Compute the intersection (overlap) AABB of two boxes.

Returns None if the boxes do not overlap.

Source

pub fn sq_distance_to_point(&self, point: &Vec3) -> Real

Compute the squared distance from a point to the nearest point on the AABB surface.

Returns 0 if the point is inside the AABB.

Source

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

Return the closest point on (or inside) the AABB to point.

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

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> 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.