Skip to main content

Shape

Enum Shape 

Source
pub enum Shape {
    Box {
        half_extents: Vec3Fix,
    },
    Cylinder {
        radius: Fix128,
        half_height: Fix128,
    },
    Cone {
        radius: Fix128,
        half_height: Fix128,
    },
    Ellipsoid {
        radii: Vec3Fix,
    },
    Wedge {
        width: Fix128,
        height: Fix128,
        depth: Fix128,
    },
    Torus {
        major_radius: Fix128,
        minor_radius: Fix128,
    },
}
Expand description

A solid, by its dimensions.

Dimensions are lengths and must be positive; Shape::validate says whether they are. The pose is not part of a shape: it is the body’s.

Variants§

§

Box

A box of the given half-extents along X, Y, Z.

Fields

§half_extents: Vec3Fix

Half the side length along each local axis.

§

Cylinder

A solid cylinder along Y.

Fields

§radius: Fix128

Radius of the circular section.

§half_height: Fix128

Half the length along Y.

§

Cone

A solid cone along Y, apex at +half_height, base at −half_height.

Fields

§radius: Fix128

Radius of the base.

§half_height: Fix128

Half the height, from the geometric centre to the apex or the base.

§

Ellipsoid

A solid ellipsoid with the given semi-axes.

Fields

§radii: Vec3Fix

Semi-axes along X, Y, Z.

§

Wedge

A triangular prism: an isosceles triangle in the XY plane (base width at −height / 2, apex at +height / 2) extruded depth along Z.

Fields

§width: Fix128

Base of the triangle, along X.

§height: Fix128

Height of the triangle, along Y.

§depth: Fix128

Extrusion length, along Z.

§

Torus

A solid torus around Y.

Fields

§major_radius: Fix128

Distance from the axis to the centre of the tube.

§minor_radius: Fix128

Radius of the tube.

Implementations§

Source§

impl Shape

Source

pub fn validate(&self) -> Result<(), ShapeError>

Whether every dimension is positive (and a torus has a hole).

Source

pub fn volume(&self) -> Fix128

Volume.

Meaningful for a shape that passes Self::validate and whose size is representable; for an enormous one Fix128 wraps, which is why PhysicsWorld::add_shaped_body(crate::solver::PhysicsWorld::add_shaped_body) checks the magnitude first.

Source

pub fn center_of_mass_offset(&self) -> Vec3Fix

Offset of the centre of mass from the geometric centre, in the shape’s local frame: zero for the shapes symmetric about their centre, and along Y for the cone (−half_height / 2) and the wedge (−height / 6).

Source

pub fn inertia_diagonal(&self, mass: Fix128) -> Vec3Fix

Diagonal of the inertia tensor about the centre of mass, for a given mass, in the shape’s local frame.

Source

pub fn bounding_radius(&self) -> Fix128

Radius of the smallest sphere about the centre of mass that encloses the solid.

Source

pub fn mass_and_inertia( &self, density: Fix128, ) -> Result<(Fix128, Vec3Fix), ShapeError>

The mass of this shape at density, with the principal inertia about its centre of mass; refuses what cannot be a body.

§Errors

ShapeError::NonPositiveDensity, ShapeError::DegenerateShape (from Self::validate), and ShapeError::MassNotRepresentable when the mass times the square of the longest dimension — the scale of the inertia — does not fit comfortably in Fix128, or the arithmetic came out non-positive anyway.

Trait Implementations§

Source§

impl Clone for Shape

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Shape

Source§

impl Debug for Shape

Source§

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

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

impl Eq for Shape

Source§

impl PartialEq for Shape

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnsafeUnpin for Shape

§

impl UnwindSafe for Shape

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.