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: f64The x-coordinate of the cube’s top-left-front corner.
y: f64The y-coordinate of the cube’s top-left-front corner.
z: f64The z-coordinate of the cube’s top-left-front corner.
width: f64The width of the cube.
height: f64The height of the cube.
depth: f64The depth of the cube.
Implementations§
Source§impl Cube
impl Cube
Sourcepub fn contains<T>(&self, point: &Point3D<T>) -> bool
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));Sourcepub fn intersects(&self, other: &Cube) -> bool
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));Sourcepub fn area(&self) -> f64
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);Sourcepub fn union(&self, other: &Cube) -> Cube
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);Sourcepub fn enlargement(&self, other: &Cube) -> f64
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);Trait Implementations§
Source§impl BSPBounds for Cube
impl BSPBounds for Cube
Source§impl BoundingVolume for Cube
impl BoundingVolume for Cube
Source§fn union(&self, other: &Self) -> Self
fn union(&self, other: &Self) -> Self
Returns the smallest bounding volume that contains both
self and other.Source§fn intersects(&self, other: &Self) -> bool
fn intersects(&self, other: &Self) -> bool
Determines whether the bounding volume intersects with another.
Source§fn enlargement(&self, other: &Self) -> f64
fn enlargement(&self, other: &Self) -> f64
Computes the enlargement required to include
other in the bounding volume. Read moreSource§impl<T> BoundingVolumeFromPoint<Point3D<T>> for Cube
impl<T> BoundingVolumeFromPoint<Point3D<T>> for Cube
Source§fn from_point_radius(query: &Point3D<T>, radius: f64) -> Self
fn from_point_radius(query: &Point3D<T>, radius: f64) -> Self
Creates a bounding volume that encapsulates a point with the specified radius.
Source§impl<T> HasMinDistance<Point3D<T>> for Cube
impl<T> HasMinDistance<Point3D<T>> for Cube
Source§fn min_distance(&self, point: &Point3D<T>) -> f64
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more