Aabb3

Struct Aabb3 

Source
pub struct Aabb3 { /* private fields */ }
Expand description

An axis-aligned bounding box in 3D space.

An AABB is the smallest rectangular box that contains a set of points, with its faces aligned to the coordinate axes. It’s defined by two 3D points:

  • min: The corner with minimum coordinate values
  • max: The corner with maximum coordinate values

AABBs are fundamental in physics engines for:

  • Broad-phase collision detection
  • Spatial partitioning and culling
  • Bounding volume hierarchies
  • Ray casting and intersection testing

§Examples

use phys_geom::{Aabb3, math::Point3};

// Create an AABB from two points
let aabb = Aabb3::new(
    Point3::new(-1.0, -1.0, -1.0),
    Point3::new(1.0, 1.0, 1.0)
);

// Use special constants
let empty_aabb = Aabb3::ANTI_INFINITE;
let zero_aabb = Aabb3::ZERO;

§Invariants

For a valid AABB, the following must hold: min.x <= max.x, min.y <= max.y, min.z <= max.z

§Memory Layout

The struct uses #[repr(C)] for FFI compatibility and contains exactly two Point3 values.

Implementations§

Source§

impl Aabb3

Source

pub const ANTI_INFINITE: Self

An empty/invalid AABB used as initial value for union operations.

This special AABB has min = [MAX, MAX, MAX] and max = [MIN, MIN, MIN], making it the identity element for union operations. Any AABB unioned with ANTI_INFINITE will result in the original AABB.

§Examples
use phys_geom::{Aabb3, math::Point3};

let mut aabb = Aabb3::ANTI_INFINITE;
aabb.grow(Point3::new(1.0, 2.0, 3.0));
aabb.grow(Point3::new(-1.0, -2.0, -3.0));

assert_eq!(aabb.min(), Point3::new(-1.0, -2.0, -3.0));
assert_eq!(aabb.max(), Point3::new(1.0, 2.0, 3.0));
Source

pub const ZERO: Aabb3

A zero-sized AABB located at the origin.

Both min and max points are at the origin (0, 0, 0), resulting in an AABB with zero volume. This is useful as a starting point for incremental bounding box computation.

Source

pub fn new(p1: impl Into<[Real; 3]>, p2: impl Into<[Real; 3]>) -> Aabb3

Source

pub fn new_unchecked(min: impl Into<Point3>, max: impl Into<Point3>) -> Self

Create AABB bound with min and max point. Different from new method, the new_unchecked won’t compare min and max point, and will assign them to AABB directly. It means user should be ensure that min point is actually smaller than max point.

Source

pub fn from_array_unchecked(values: [Real; 6]) -> Self

Source

pub fn from_center_extents( center: impl Into<Point3>, extents: impl Into<Vec3>, ) -> Self

Create AABB from center and extents.

Source

pub fn min(&self) -> Point3

Returns the minimum point of the AABB.

Source

pub fn max(&self) -> Point3

Returns the maximum point of the AABB.

Source

pub fn get_interval(&self, axis: usize) -> Interval

Get the interval of the AABB along the given axis.

§Panics

Panics if axis is greater than 2.

Source

pub fn set_min_at(&mut self, axis: usize, value: Real)

Set the minimum value of the AABB at the given axis.

§Panics

Panics if the set value is large than max[axis]

Source

pub fn set_max_at(&mut self, axis: usize, value: Real)

Set the maximum value of the AABB at the given axis.

§Panics

Panics if the set value is smaller than min[axis]

Source

pub fn grow(&mut self, p: impl Into<Point3>)

Grow the aabb to include the given point.

Source

pub fn merge(&mut self, other: &Self)

Source

pub fn expand(&mut self, margin: Real)

Source

pub fn offset(&mut self, offset: impl Into<[Real; 3]>)

Offset the AABB by the given vector.

Source

pub fn with_offset(self, offset: impl Into<[Real; 3]>) -> Self

Offset the AABB by the given vector, returning the modified AABB.

Source

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

Source

pub fn with_margin(&self, margin: impl Into<[Real; 3]>) -> Self

Extend AABB with margin.

Source

pub fn transform(&self, transform: impl Into<Isometry3>) -> Self

TODO: maybe we have more more efficient method (issue #1243)

Source

pub fn center(&self) -> Point3

Get the center point of the AABB

Source

pub fn size(&self) -> Vec3

Get the size of the AABB (Excludes cases where the end points are equal)

Source

pub fn get_extents(&self) -> Vec3

Source

pub fn overlap_test(&self, rhs: &Aabb3) -> bool

Overlap test two AABB.

Source

pub fn raycast(&self, ray: Ray, max_distance: Real) -> bool

Source

pub fn raycast_by_one_over_direction( &self, origin: impl Into<[Real; 3]>, one_over_direction: impl Into<[Real; 3]>, max_distance: Real, ) -> bool

§Examples
use phys_geom::{Aabb3, Ray};
use phys_geom::{math::Point3, math::Vec3};
let ray = Ray::new_with_vec3(Point3::origin(), Vec3::new(0.0, 0.0, 1.0));
let aabb = Aabb3::new(Point3::origin(), Point3::new(1.0, 1.0, 1.0));
aabb.raycast_by_one_over_direction(ray.origin, ray.one_over_direction(), 1.0);
Source

pub fn raycast_by_one_over_direction_impl( &self, origin: impl Into<[Real; 3]>, one_over_direction: impl Into<[Real; 3]>, max_distance: Real, ) -> Option<(Vec3, Real)>

Raycast the AABB with one over direction. Return:

  • distance vector to each entry side of the AABB,
  • entry distance
Source

pub fn xz(&self) -> Aabb2

Source

pub fn xy(&self) -> Aabb2

Source

pub fn yz(&self) -> Aabb2

Trait Implementations§

Source§

impl Add<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3

Source§

type Output = Aabb3

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec3) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3

Source§

fn add_assign(&mut self, rhs: Vec3)

Performs the += operation. Read more
Source§

impl Clone for Aabb3

Source§

fn clone(&self) -> Aabb3

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 Aabb3

Source§

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

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

impl Default for Aabb3

Source§

fn default() -> Aabb3

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

impl<'de> Deserialize<'de> for Aabb3

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Aabb3

Source§

fn eq(&self, other: &Aabb3) -> 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 Serialize for Aabb3

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3

Source§

type Output = Aabb3

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec3) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3

Source§

fn sub_assign(&mut self, rhs: Vec3)

Performs the -= operation. Read more
Source§

impl Copy for Aabb3

Source§

impl StructuralPartialEq for Aabb3

Auto Trait Implementations§

§

impl Freeze for Aabb3

§

impl RefUnwindSafe for Aabb3

§

impl Send for Aabb3

§

impl Sync for Aabb3

§

impl Unpin for Aabb3

§

impl UnwindSafe for Aabb3

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

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

Source§

impl<T, Right> ClosedSub<Right> for T
where T: Sub<Right, Output = T> + SubAssign<Right>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,