pub struct AABB<T: Scalar + PartialOrd> { /* private fields */ }
Expand description
3D axis-aligned bounding box
Implementations§
Source§impl<T: Scalar + ClosedSub + PartialOrd + Copy> AABB<T>
impl<T: Scalar + ClosedSub + PartialOrd + Copy> AABB<T>
Sourcepub fn from_min_max(min: Point3<T>, max: Point3<T>) -> Self
pub fn from_min_max(min: Point3<T>, max: Point3<T>) -> Self
Creates a new AABB from the given minimum and maximum coordinates. Panics if the minimum position is not less than or equal to the maximum position
let bounds = AABB::from_min_max(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
Sourcepub fn from_min_max_unchecked(min: Point3<T>, max: Point3<T>) -> Self
pub fn from_min_max_unchecked(min: Point3<T>, max: Point3<T>) -> Self
Creates a new AABB from the given minimum and maximum coordinates. Similar to from_min_max but performs no checks that min <= max. If you know that min <= max, prefer this function over from_min_max
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
Sourcepub fn min(&self) -> &Point3<T>
pub fn min(&self) -> &Point3<T>
Returns the minimum point of this AABB
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(-1.0, -1.0, -1.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
assert_eq!(*bounds.min(), nalgebra::Point3::new(-1.0, -1.0, -1.0));
Sourcepub fn max(&self) -> &Point3<T>
pub fn max(&self) -> &Point3<T>
Returns the maximum point of this AABB
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(-1.0, -1.0, -1.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
assert_eq!(*bounds.max(), nalgebra::Point3::new(1.0, 1.0, 1.0));
Sourcepub fn extent(&self) -> Vector3<T>
pub fn extent(&self) -> Vector3<T>
Returns the extent of this AABB. The extent is the size between the minimum and maximum position of this AABB
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
assert_eq!(bounds.extent(), nalgebra::Vector3::new(1.0, 1.0, 1.0));
Sourcepub fn intersects(&self, other: &AABB<T>) -> bool
pub fn intersects(&self, other: &AABB<T>) -> bool
Performs an intersection test between this AABB and the given AABB. Returns true if the two bounding boxes intersect. If one of the boxes is fully contained within the other, this also counts as an intersection
let bounds_a = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
let bounds_b = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.5, 0.5, 0.5), nalgebra::Point3::new(1.5, 1.5, 1.5));
assert!(bounds_a.intersects(&bounds_b));
Sourcepub fn contains(&self, point: &Point3<T>) -> bool
pub fn contains(&self, point: &Point3<T>) -> bool
Returns true if the given point is contained within this AABB. Points right on the boundary of this AABB (e.g. point.x == self.max.x or self.min.x) will return true as well.
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
assert!(bounds.contains(&nalgebra::Point3::new(0.5, 0.5, 0.5)));
Sourcepub fn union(a: &AABB<T>, b: &AABB<T>) -> Self
pub fn union(a: &AABB<T>, b: &AABB<T>) -> Self
Computes the union of the given bounding boxes. The union of two bounding boxes a and b is defined as the smallest AABB that fully contains both a and b.
let bounds_a = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
let bounds_b = AABB::from_min_max_unchecked(nalgebra::Point3::new(2.0, 2.0, 2.0), nalgebra::Point3::new(3.0, 3.0, 3.0));
let merged_bounds = AABB::union(&bounds_a, &bounds_b);
assert_eq!(*merged_bounds.min(), nalgebra::Point3::new(0.0, 0.0, 0.0));
assert_eq!(*merged_bounds.max(), nalgebra::Point3::new(3.0, 3.0, 3.0));
Sourcepub fn extend_with_point(bounds: &AABB<T>, point: &Point3<T>) -> AABB<T>
pub fn extend_with_point(bounds: &AABB<T>, point: &Point3<T>) -> AABB<T>
Extends the given AABB so that it contains the given point.
let bounds = AABB::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 1.0, 1.0));
let extended_bounds = AABB::extend_with_point(&bounds, &nalgebra::Point3::new(2.0, 2.0, 2.0));
assert_eq!(*extended_bounds.min(), nalgebra::Point3::new(0.0, 0.0, 0.0));
assert_eq!(*extended_bounds.max(), nalgebra::Point3::new(2.0, 2.0, 2.0));
Source§impl AABB<f32>
impl AABB<f32>
Sourcepub fn center(&self) -> Point3<f32>
pub fn center(&self) -> Point3<f32>
Returns the center point of this AABB.
let bounds = AABB::<f32>::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 2.0, 3.0));
assert_eq!(bounds.center(), nalgebra::Point3::new(0.5, 1.0, 1.5));
Sourcepub fn as_cubic(&self) -> AABB<f32>
pub fn as_cubic(&self) -> AABB<f32>
Returns a cubic version of the associated AABB
. For this, the shortest two axes of the bounds
are elongated symmetrically from the center of the bounds so that all axis are of equal length
let bounds = AABB::<f32>::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 2.0, 4.0));
let cubic_bounds = AABB::<f32>::from_min_max_unchecked(nalgebra::Point3::new(-1.5, -1.0, 0.0), nalgebra::Point3::new(2.5, 3.0, 4.0));
assert_eq!(bounds.as_cubic().min(), cubic_bounds.min());
assert_eq!(bounds.as_cubic().max(), cubic_bounds.max());
Source§impl AABB<f64>
impl AABB<f64>
Sourcepub fn center(&self) -> Point3<f64>
pub fn center(&self) -> Point3<f64>
Returns the center point of this AABB.
let bounds = AABB::<f64>::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 2.0, 3.0));
assert_eq!(bounds.center(), nalgebra::Point3::new(0.5, 1.0, 1.5));
Sourcepub fn contains_approx(&self, point: &Point3<f64>, epsilon: f64) -> bool
pub fn contains_approx(&self, point: &Point3<f64>, epsilon: f64) -> bool
Like contains
, but performs epsilon comparison on floating point values using the given epsilon
value
Sourcepub fn as_cubic(&self) -> AABB<f64>
pub fn as_cubic(&self) -> AABB<f64>
Returns a cubic version of the associated AABB
. For this, the shortest two axes of the bounds
are elongated symmetrically from the center of the bounds so that all axis are of equal length
let bounds = AABB::<f64>::from_min_max_unchecked(nalgebra::Point3::new(0.0, 0.0, 0.0), nalgebra::Point3::new(1.0, 2.0, 4.0));
let cubic_bounds = AABB::<f64>::from_min_max_unchecked(nalgebra::Point3::new(-1.5, -1.0, 0.0), nalgebra::Point3::new(2.5, 3.0, 4.0));
assert_eq!(bounds.as_cubic().min(), cubic_bounds.min());
assert_eq!(bounds.as_cubic().max(), cubic_bounds.max());
Trait Implementations§
Source§impl<U: Into<Point3<f64>>> FromIterator<U> for AABB<f64>
impl<U: Into<Point3<f64>>> FromIterator<U> for AABB<f64>
Source§fn from_iter<V: IntoIterator<Item = U>>(iter: V) -> Self
fn from_iter<V: IntoIterator<Item = U>>(iter: V) -> Self
impl<T: Copy + Scalar + PartialOrd> Copy for AABB<T>
impl<T: Scalar + PartialOrd> StructuralPartialEq for AABB<T>
Auto Trait Implementations§
impl<T> Freeze for AABB<T>where
T: Freeze,
impl<T> RefUnwindSafe for AABB<T>where
T: RefUnwindSafe,
impl<T> Send for AABB<T>where
T: Send,
impl<T> Sync for AABB<T>where
T: Sync,
impl<T> Unpin for AABB<T>where
T: Unpin,
impl<T> UnwindSafe for AABB<T>where
T: UnwindSafe,
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> 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<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.