pub struct Cuboid { /* private fields */ }Expand description
A cuboid (rectangular box) shape centered at the origin.
A cuboid is a three-dimensional rectangular box with six rectangular faces. It’s one of the most commonly used shapes in physics engines for representing boxes, containers, and general rectangular objects.
The cuboid is centered at the origin (0, 0, 0) with its edges aligned to the coordinate axes.
§Examples
use phys_geom::shape::Cuboid;
// Create a cuboid with dimensions 2x3x1
let cuboid = Cuboid::new([2.0, 3.0, 1.0]);
assert_eq!(cuboid.length(), [2.0, 3.0, 1.0]);
assert_eq!(cuboid.half_length(), [1.0, 1.5, 0.5]);
// Create a unit cube
let unit_cube = Cuboid::UNIT;
assert_eq!(unit_cube.length(), [1.0, 1.0, 1.0]);§Dimensions
half_length: Half-lengths along each axis (x, y, z)- Total dimensions:
[x, y, z] = [2 * half_length[0], 2 * half_length[1], 2 * half_length[2]]
§Construction
The cuboid can be constructed from:
- An array of three lengths:
Cuboid::new([x, y, z]) - Individual components:
Cuboid::new_xyz(x, y, z)
Implementations§
Source§impl Cuboid
impl Cuboid
Sourcepub const UNIT: Cuboid
pub const UNIT: Cuboid
A unit cube with side length 1.0.
This is useful as a reference size for normalized shapes. The cube extends from -0.5 to +0.5 along each axis.
Sourcepub fn new(length: impl Into<[Real; 3]>) -> Cuboid
pub fn new(length: impl Into<[Real; 3]>) -> Cuboid
Creates a new cuboid with the given dimensions.
§Arguments
length- The dimensions of the cuboid as a 3-element array [x, y, z]
§Returns
A new Cuboid instance.
§Panics
Panics if any component of length is not positive.
§Examples
use phys_geom::shape::Cuboid;
// Create from array
let cuboid1 = Cuboid::new([2.0, 3.0, 1.0]);
// Create from tuple (via Into trait)
let cuboid2 = Cuboid::new((2.0, 3.0, 1.0));
assert_eq!(cuboid1.length(), cuboid2.length());Sourcepub fn new_xyz(x: Real, y: Real, z: Real) -> Cuboid
pub fn new_xyz(x: Real, y: Real, z: Real) -> Cuboid
Creates a new cuboid with individual x, y, z dimensions.
This is a convenience method equivalent to Cuboid::new([x, y, z]).
§Arguments
x- Length along the X-axisy- Length along the Y-axisz- Length along the Z-axis
§Returns
A new Cuboid instance.
§Examples
use phys_geom::shape::Cuboid;
let cuboid = Cuboid::new_xyz(2.0, 3.0, 1.0);
assert_eq!(cuboid.length(), [2.0, 3.0, 1.0]);Sourcepub fn half_length(&self) -> [Real; 3]
pub fn half_length(&self) -> [Real; 3]
Returns the half-lengths of the cuboid.
Returns an array [x/2, y/2, z/2] representing the distance from the center to each face along the respective axes.
§Returns
An array of three Real values [x/2, y/2, z/2].
§Examples
use phys_geom::shape::Cuboid;
let cuboid = Cuboid::new([2.0, 3.0, 1.0]);
assert_eq!(cuboid.half_length(), [1.0, 1.5, 0.5]);Sourcepub fn set_length(&mut self, length: impl Into<[Real; 3]>)
pub fn set_length(&mut self, length: impl Into<[Real; 3]>)
Sets the dimensions of the cuboid.
§Arguments
length- The new dimensions as a 3-element array [x, y, z]
§Panics
Panics if any component of length is not positive.
§Examples
use phys_geom::shape::Cuboid;
let mut cuboid = Cuboid::new([1.0, 1.0, 1.0]);
cuboid.set_length([2.0, 3.0, 1.0]);
assert_eq!(cuboid.length(), [2.0, 3.0, 1.0]);Trait Implementations§
Source§impl ComputeAabb3 for Cuboid
impl ComputeAabb3 for Cuboid
Source§fn compute_aabb(&self) -> Aabb3
fn compute_aabb(&self) -> Aabb3
Source§impl ComputeVolume for Cuboid
impl ComputeVolume for Cuboid
Source§fn compute_volume(&self) -> Real
fn compute_volume(&self) -> Real
Source§impl<'de> Deserialize<'de> for Cuboid
impl<'de> Deserialize<'de> for Cuboid
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Cuboid
impl StructuralPartialEq for Cuboid
Auto Trait Implementations§
impl Freeze for Cuboid
impl RefUnwindSafe for Cuboid
impl Send for Cuboid
impl Sync for Cuboid
impl Unpin for Cuboid
impl UnwindSafe for Cuboid
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.