Skip to main content

Aabb

Struct Aabb 

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

An axis-aligned box, or the empty box.

The empty box is a distinct state rather than a degenerate one with reversed bounds: “no points at all” and “a box of zero size at the origin” answer containment questions differently, and conflating them makes an empty shape appear to be at the origin.

Implementations§

Source§

impl Aabb

Source

pub const EMPTY: Self

A box containing nothing.

Source

pub const fn of_point(p: Point) -> Self

A box containing exactly one point.

Source

pub fn of_corners(a: Point, b: Point) -> Self

A box spanning two corners, in either order.

Source

pub fn of_points(points: &[Point]) -> Self

A box containing every point given.

Source

pub const fn is_empty(&self) -> bool

Whether this box contains nothing.

Source

pub fn low(&self) -> Option<Point>

The lower corner, or None if empty.

Source

pub fn high(&self) -> Option<Point>

The upper corner, or None if empty.

Source

pub fn centre(&self) -> Option<Point>

The centre, or None if empty.

Source

pub fn size(&self) -> Vector

The size along each axis, or zero if empty.

Source

pub fn extent_max(&self) -> f64

The length of the longest axis, or zero if empty.

Source

pub fn diagonal(&self) -> f64

The length of the diagonal, or zero if empty.

Source

pub fn volume(&self) -> f64

The enclosed volume, or zero if empty or flat.

Source

pub fn with_point(&self, p: Point) -> Self

This box grown to include p.

Source

pub fn union(&self, other: &Self) -> Self

This box grown to include other.

Source

pub fn expanded(&self, margin: f64) -> Self

This box grown by margin in every direction.

The usual way to account for a tolerance before a rejection test: two shapes whose boxes miss by less than their tolerances may still touch.

Source

pub fn with_tolerance(&self, tol: Tolerances) -> Self

This box grown by the confusion tolerance.

Source

pub fn contains(&self, p: Point) -> bool

Whether p lies inside, boundary included.

Source

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

Whether other lies entirely inside this box.

Source

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

Whether the two boxes share any point.

The rejection test everything else is built on. An empty box intersects nothing.

Source

pub fn intersection(&self, other: &Self) -> Self

The overlap of two boxes, or empty if they do not meet.

Source

pub fn distance_to(&self, p: Point) -> f64

The shortest distance from p to this box, zero if inside.

Source

pub fn distance_to_box(&self, other: &Self) -> f64

A lower bound on the distance between two boxes, zero if they meet.

A bound, not the distance between the shapes inside them, which is why it is only ever useful for rejection: if this exceeds a threshold the shapes certainly do too.

Source

pub fn corners(&self) -> Vec<Point>

The eight corners, or an empty list if the box is empty.

Source

pub fn transformed(&self, t: &Transform) -> Self

This box transformed, as the box of the transformed corners.

The result contains the transformed box but is generally larger than the tightest one: a rotated box is not axis-aligned, and its bounding box must cover the rotation. Erring outward is the safe direction, and repeatedly transforming a box therefore inflates it; transform the geometry and re-bound instead of chaining this.

Trait Implementations§

Source§

impl Clone for Aabb

Source§

fn clone(&self) -> Aabb

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 Default for Aabb

Source§

fn default() -> Self

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

impl Display for Aabb

Source§

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

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

impl FromIterator<Point> for Aabb

Source§

fn from_iter<I: IntoIterator<Item = Point>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Aabb

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 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,

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.