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);Source§impl Cube
impl Cube
Sourcepub fn min_distance<T>(&self, point: &Point3D<T>) -> f64
pub fn min_distance<T>(&self, point: &Point3D<T>) -> f64
Computes the minimum distance from this cube to a given 3D point.
Kept as an inherent method for convenience; the logic lives in
HasMinDistance.
Sourcepub fn min_distance_sq<T>(&self, point: &Point3D<T>) -> f64
pub fn min_distance_sq<T>(&self, point: &Point3D<T>) -> f64
Computes the squared minimum distance from this cube to a given 3D point.
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
self and other.Source§fn intersects(&self, other: &Self) -> bool
fn intersects(&self, other: &Self) -> bool
Source§fn enlargement(&self, other: &Self) -> f64
fn enlargement(&self, other: &Self) -> f64
other in the bounding volume. Read more