Struct AABB

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

Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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));
Source

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)));
Source

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));
Source

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>

Source

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));
Source

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>

Source

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));
Source

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

Source

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<T: Clone + Scalar + PartialOrd> Clone for AABB<T>

Source§

fn clone(&self) -> AABB<T>

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<T: Debug + Scalar + PartialOrd> Debug for AABB<T>

Source§

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

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

impl<U: Into<Point3<f64>>> FromIterator<U> for AABB<f64>

Source§

fn from_iter<V: IntoIterator<Item = U>>(iter: V) -> Self

Creates a value from an iterator. Read more
Source§

impl<T: PartialEq + Scalar + PartialOrd> PartialEq for AABB<T>

Source§

fn eq(&self, other: &AABB<T>) -> 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<T: Copy + Scalar + PartialOrd> Copy for AABB<T>

Source§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
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> Scalar for T
where T: 'static + Clone + PartialEq + Debug,