Cuboid

Struct Cuboid 

Source
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

Source

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.

Source

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());
Source

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-axis
  • y - Length along the Y-axis
  • z - 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]);
Source

pub fn length(&self) -> [Real; 3]

Returns the full dimensions of the cuboid.

Returns an array [x, y, z] representing the total length along each axis.

§Returns

An array of three Real values [x, y, z].

§Examples
use phys_geom::shape::Cuboid;

let cuboid = Cuboid::new([2.0, 3.0, 1.0]);
assert_eq!(cuboid.length(), [2.0, 3.0, 1.0]);
Source

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]);
Source

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 Clone for Cuboid

Source§

fn clone(&self) -> Cuboid

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 ComputeAabb3 for Cuboid

Source§

fn compute_aabb(&self) -> Aabb3

Compute the AABB in local space.
Source§

impl ComputeVolume for Cuboid

Source§

fn compute_volume(&self) -> Real

Computes the volume of this shape. Read more
Source§

impl Debug for Cuboid

Source§

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

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

impl Default for Cuboid

Source§

fn default() -> Cuboid

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Cuboid

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Cuboid

Source§

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

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Cuboid

Source§

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

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,