Skip to main content

Cube

Struct Cube 

Source
pub struct Cube {
    pub x: f64,
    pub y: f64,
    pub z: f64,
    pub width: f64,
    pub height: f64,
    pub depth: f64,
}
Expand description

Represents a cube (or cuboid) in 3D space.

Fields§

§x: f64

The x-coordinate of the cube’s top-left-front corner.

§y: f64

The y-coordinate of the cube’s top-left-front corner.

§z: f64

The z-coordinate of the cube’s top-left-front corner.

§width: f64

The width of the cube.

§height: f64

The height of the cube.

§depth: f64

The depth of the cube.

Implementations§

Source§

impl Cube

Source

pub fn contains<T>(&self, point: &Point3D<T>) -> bool

Determines if the cube contains the given 3D point.

§Arguments
  • point - The 3D point to test.
§Examples
use spart::geometry::{Cube, Point3D};
let cube = Cube { x: 0.0, y: 0.0, z: 0.0, width: 10.0, height: 10.0, depth: 10.0 };
let pt: Point3D<()> = Point3D::new(5.0, 5.0, 5.0, None);
assert!(cube.contains(&pt));
Source

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

Determines whether this cube intersects with another cube.

§Arguments
  • other - The other cube.
§Examples
use spart::geometry::Cube;
let a = Cube { x: 0.0, y: 0.0, z: 0.0, width: 5.0, height: 5.0, depth: 5.0 };
let b = Cube { x: 3.0, y: 3.0, z: 3.0, width: 5.0, height: 5.0, depth: 5.0 };
assert!(a.intersects(&b));
Source

pub fn area(&self) -> f64

Computes the volume of the cube.

§Examples
use spart::geometry::Cube;
let cube = Cube { x: 0.0, y: 0.0, z: 0.0, width: 2.0, height: 3.0, depth: 4.0 };
assert_eq!(cube.area(), 24.0);
Source

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

Computes the union of this cube with another.

The union is defined as the smallest cube that completely contains both cubes.

§Arguments
  • other - The other cube.
§Examples
use spart::geometry::Cube;
let a = Cube { x: 0.0, y: 0.0, z: 0.0, width: 3.0, height: 3.0, depth: 3.0 };
let b = Cube { x: 2.0, y: 2.0, z: 2.0, width: 3.0, height: 3.0, depth: 3.0 };
let union_cube = a.union(&b);
assert_eq!(union_cube.x, 0.0);
Source

pub fn enlargement(&self, other: &Cube) -> f64

Computes the enlargement needed to include another cube.

The enlargement is defined as the difference between the volume of the union and the volume of this cube.

§Arguments
  • other - The other cube.
§Examples
use spart::geometry::Cube;
let a = Cube { x: 0.0, y: 0.0, z: 0.0, width: 2.0, height: 2.0, depth: 2.0 };
let b = Cube { x: 1.0, y: 1.0, z: 1.0, width: 2.0, height: 2.0, depth: 2.0 };
let enlargement = a.enlargement(&b);
assert!(enlargement >= 0.0);
Source§

impl Cube

Source

pub fn min_distance<T>(&self, point: &Point3D<T>) -> f64

Computes the minimum distance from this cube to a given 3D point.

Trait Implementations§

Source§

impl BSPBounds for Cube

Source§

const DIM: usize = 3

The number of dimensions supported.
Source§

fn center(&self, dim: usize) -> Result<f64, SpartError>

Returns the center coordinate along the specified dimension. Read more
Source§

fn extent(&self, dim: usize) -> Result<f64, SpartError>

Returns the extent (width, height, or depth) along the specified dimension. Read more
Source§

impl BoundingVolume for Cube

Source§

fn area(&self) -> f64

Returns the area (or volume for 3D objects) of the bounding volume.
Source§

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

Returns the smallest bounding volume that contains both self and other.
Source§

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

Determines whether the bounding volume intersects with another.
Source§

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

Computes the overlap between two bounding volumes
Source§

fn margin(&self) -> f64

Computes the margin of a bounding box
Source§

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

Computes the enlargement required to include other in the bounding volume. Read more
Source§

impl<T> BoundingVolumeFromPoint<Point3D<T>> for Cube

Source§

fn from_point_radius(query: &Point3D<T>, radius: f64) -> Self

Creates a bounding volume that encapsulates a point with the specified radius.
Source§

impl Clone for Cube

Source§

fn clone(&self) -> Cube

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 Cube

Source§

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

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

impl<T> HasMinDistance<Point3D<T>> for Cube

Source§

fn min_distance(&self, point: &Point3D<T>) -> f64

Computes the minimum distance from the bounding volume to the given query.

Auto Trait Implementations§

§

impl Freeze for Cube

§

impl RefUnwindSafe for Cube

§

impl Send for Cube

§

impl Sync for Cube

§

impl Unpin for Cube

§

impl UnsafeUnpin for Cube

§

impl UnwindSafe for Cube

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more