Skip to main content

BoundingBox3D

Struct BoundingBox3D 

Source
pub struct BoundingBox3D {
    pub min_x: f64,
    pub min_y: f64,
    pub min_z: f64,
    pub max_x: f64,
    pub max_y: f64,
    pub max_z: f64,
}
Expand description

An axis-aligned 3-D bounding box.

Invariant: min_x ≤ max_x, min_y ≤ max_y, min_z ≤ max_z. This invariant is enforced by BoundingBox3D::new.

Fields§

§min_x: f64

Minimum X coordinate.

§min_y: f64

Minimum Y coordinate.

§min_z: f64

Minimum Z coordinate.

§max_x: f64

Maximum X coordinate.

§max_y: f64

Maximum Y coordinate.

§max_z: f64

Maximum Z coordinate.

Implementations§

Source§

impl BoundingBox3D

Source

pub fn new( min_x: f64, min_y: f64, min_z: f64, max_x: f64, max_y: f64, max_z: f64, ) -> Option<Self>

Construct a new bounding box.

Returns None if any min > max invariant is violated.

Source

pub fn from_points(points: &[Point3D]) -> Option<Self>

Build the tightest bounding box that contains every point in points.

Returns None when points is empty.

Source

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

Return true when p is strictly inside or on the boundary.

Source

pub fn intersects_2d(&self, other: &BoundingBox3D) -> bool

Return true when the XY footprints of self and other overlap (or touch).

Source

pub fn intersects_3d(&self, other: &BoundingBox3D) -> bool

Return true when self and other share any volume (or face).

Source

pub fn center(&self) -> (f64, f64, f64)

Centre point of the box as (cx, cy, cz).

Source

pub fn diagonal(&self) -> f64

Length of the space diagonal (3-D).

Source

pub fn expand_by(&self, delta: f64) -> Self

Return a box expanded symmetrically in every direction by delta.

If delta is negative the box may collapse; the result will still satisfy the min ≤ max invariant because f64 arithmetic naturally produces equal values when expansion < 0 produces min > max (the caller should validate the result if that matters).

Source

pub fn volume(&self) -> f64

Volume of the box.

Source

pub fn split_octants(&self) -> [BoundingBox3D; 8]

Subdivide the box into eight equal octant children.

Children are ordered by (x_high, y_high, z_high) bits: index 0 = (lo, lo, lo), index 7 = (hi, hi, hi).

Trait Implementations§

Source§

impl Clone for BoundingBox3D

Source§

fn clone(&self) -> BoundingBox3D

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 Debug for BoundingBox3D

Source§

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

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

impl PartialEq for BoundingBox3D

Source§

fn eq(&self, other: &BoundingBox3D) -> 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 StructuralPartialEq for BoundingBox3D

Auto Trait Implementations§

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