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 valuesmax: 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
impl Aabb3
Sourcepub const ANTI_INFINITE: Self
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));Sourcepub const ZERO: Aabb3
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.
pub fn new(p1: impl Into<[Real; 3]>, p2: impl Into<[Real; 3]>) -> Aabb3
Sourcepub fn new_unchecked(min: impl Into<Point3>, max: impl Into<Point3>) -> Self
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.
pub fn from_array_unchecked(values: [Real; 6]) -> Self
Sourcepub fn from_center_extents(
center: impl Into<Point3>,
extents: impl Into<Vec3>,
) -> Self
pub fn from_center_extents( center: impl Into<Point3>, extents: impl Into<Vec3>, ) -> Self
Create AABB from center and extents.
Sourcepub fn get_interval(&self, axis: usize) -> Interval
pub fn get_interval(&self, axis: usize) -> Interval
Sourcepub fn set_min_at(&mut self, axis: usize, value: Real)
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]
Sourcepub fn set_max_at(&mut self, axis: usize, value: Real)
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]
pub fn merge(&mut self, other: &Self)
pub fn expand(&mut self, margin: Real)
Sourcepub fn with_offset(self, offset: impl Into<[Real; 3]>) -> Self
pub fn with_offset(self, offset: impl Into<[Real; 3]>) -> Self
Offset the AABB by the given vector, returning the modified AABB.
pub fn corners(&self) -> [Point3; 8]
Sourcepub fn with_margin(&self, margin: impl Into<[Real; 3]>) -> Self
pub fn with_margin(&self, margin: impl Into<[Real; 3]>) -> Self
Extend AABB with margin.
Sourcepub fn transform(&self, transform: impl Into<Isometry3>) -> Self
pub fn transform(&self, transform: impl Into<Isometry3>) -> Self
TODO: maybe we have more more efficient method (issue #1243)
Sourcepub fn size(&self) -> Vec3
pub fn size(&self) -> Vec3
Get the size of the AABB (Excludes cases where the end points are equal)
pub fn get_extents(&self) -> Vec3
Sourcepub fn overlap_test(&self, rhs: &Aabb3) -> bool
pub fn overlap_test(&self, rhs: &Aabb3) -> bool
Overlap test two AABB.
pub fn raycast(&self, ray: Ray, max_distance: Real) -> bool
Sourcepub fn raycast_by_one_over_direction(
&self,
origin: impl Into<[Real; 3]>,
one_over_direction: impl Into<[Real; 3]>,
max_distance: Real,
) -> bool
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);Sourcepub 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)>
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
pub fn xz(&self) -> Aabb2
pub fn xy(&self) -> Aabb2
pub fn yz(&self) -> Aabb2
Trait Implementations§
Source§impl AddAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3
impl AddAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3
Source§fn add_assign(&mut self, rhs: Vec3)
fn add_assign(&mut self, rhs: Vec3)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Aabb3
impl<'de> Deserialize<'de> for Aabb3
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl SubAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3
impl SubAssign<Matrix<f64, Const<3>, Const<1>, ArrayStorage<f64, 3, 1>>> for Aabb3
Source§fn sub_assign(&mut self, rhs: Vec3)
fn sub_assign(&mut self, rhs: Vec3)
-= operation. Read moreimpl Copy for Aabb3
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> 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<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.