Skip to main content

Aabb

Struct Aabb 

Source
pub struct Aabb {
    pub min: [f64; 3],
    pub max: [f64; 3],
}
Expand description

The axis-aligned box around a set of points: min ≤ max on every axis, both finite. A box is never empty; an empty point set has no box.

use arris_math::Aabb;

let b = Aabb::of_points(&[[0.0, 0.0, 0.0], [2.0, -1.0, 3.0]]).unwrap();
assert_eq!(b.min, [0.0, -1.0, 0.0]);
assert_eq!(b.max, [2.0, 0.0, 3.0]);
assert_eq!(b.extent(), [2.0, 1.0, 3.0]);
assert_eq!(b.center(), [1.0, -0.5, 1.5]);

Fields§

§min: [f64; 3]

The smallest coordinate on each axis.

§max: [f64; 3]

The largest coordinate on each axis.

Implementations§

Source§

impl Aabb

Source

pub fn of_points<'a>( points: impl IntoIterator<Item = &'a [f64; 3]>, ) -> Option<Aabb>

The box around points, or None for no points.

Source

pub fn union(self, other: Aabb) -> Aabb

The smallest box containing both.

Source

pub fn extent(&self) -> [f64; 3]

max - min per axis.

Source

pub fn center(&self) -> [f64; 3]

The midpoint.

Source

pub fn diagonal(&self) -> f64

The length of the box’s diagonal: the scale of what it contains.

Source

pub fn of_point(p: Point3) -> Aabb

The box holding one point, of zero extent.

use arris_math::{Aabb, Point3};

let b = Aabb::of_point(Point3::new(1.0, 2.0, 3.0));
assert_eq!(b.min, b.max);
assert_eq!(b.extent(), [0.0; 3]);
Source

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

true when the two boxes share a point, touching included: the cheap reject before a face pair is intersected. Boxes that only touch on a face intersect, so a caller that needs a margin Aabb::inflated one of them by its tolerance first.

use arris_math::Aabb;

let a = Aabb { min: [0.0; 3], max: [1.0; 3] };
let touching = Aabb { min: [1.0, 0.0, 0.0], max: [2.0, 1.0, 1.0] };
let clear = Aabb { min: [1.5, 0.0, 0.0], max: [2.0, 1.0, 1.0] };
assert!(a.intersects(&touching));
assert!(!a.intersects(&clear));
Source

pub fn inflated(&self, by: f64) -> Aabb

The box grown by by on every side; a negative by shrinks it, and never past a point — the centre holds.

use arris_math::Aabb;

let b = Aabb { min: [0.0; 3], max: [2.0; 3] };
assert_eq!(b.inflated(0.5).min, [-0.5; 3]);
assert_eq!(b.inflated(-5.0).extent(), [0.0; 3], "never past a point");

Trait Implementations§

Source§

impl Clone for Aabb

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Aabb

Source§

impl Debug for Aabb

Source§

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

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

impl PartialEq for Aabb

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Aabb

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

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.