Enum Shape

Source
pub enum Shape<const D: usize> {
    Ball {
        radius: f32,
    },
    Box {
        half_extents: [f32; D],
    },
}

Variants§

§

Ball

Fields

§radius: f32
§

Box

Fields

§half_extents: [f32; D]

Implementations§

Source§

impl<const D: usize> Shape<D>

Source

pub fn sweep_ball( self, center: [f32; D], origin: [f32; D], radius: f32, displacement: [f32; D], ) -> Result<Option<SweepHit<D>>, PhysicsError>

Sweep a ball against this stationary shape at center.

displacement is the complete translation, not a direction or velocity. Zero movement still reports initial overlap/touch; a separated stationary ball returns Ok(None). Initial contacts take precedence over later hits, even when moving away. Tangencies and endpoint hits are included. This geometric query does not apply the world’s sliding/CCD contact policy.

Shapes/radius and all coordinates use the existing world limits: radii and half extents in [1e-5, 1_000_000], and center, origin and displacement components in [-1_000_000, 1_000_000]. Invalid/nonfinite inputs return PhysicsError::InvalidBody; dimensions other than 2/3 return PhysicsError::InvalidDimension. Intermediates use f64, with results rounded to f32; this is not an exact-arithmetic predicate.

use ferravex_dynamics::Shape;
let wall = Shape::cuboid([1., 1.]);
let hit = wall.sweep_ball([0., 0.], [-3., 0.], 0.5, [4., 0.])?
    .unwrap();
assert_eq!(hit.fraction, 0.375);
assert_eq!(hit.normal, [-1., 0.]);
let overlap = wall.sweep_ball([0., 0.], [0., 0.], 0.5, [0., 0.])?
    .unwrap();
assert_eq!(overlap.fraction, 0.);
assert!(wall.sweep_ball([0., 0.], [-3., 0.], 0.5, [0., 0.])?.is_none());
Source§

impl<const D: usize> Shape<D>

Source

pub const fn ball(radius: f32) -> Shape<D>

Source

pub const fn cuboid(half_extents: [f32; D]) -> Shape<D>

All sizes are half extents, not full dimensions.

Trait Implementations§

Source§

impl<const D: usize> Clone for Shape<D>

Source§

fn clone(&self) -> Shape<D>

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<const D: usize> Debug for Shape<D>

Source§

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

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

impl<const D: usize> PartialEq for Shape<D>

Source§

fn eq(&self, other: &Shape<D>) -> 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<const D: usize> Copy for Shape<D>

Source§

impl<const D: usize> StructuralPartialEq for Shape<D>

Auto Trait Implementations§

§

impl<const D: usize> Freeze for Shape<D>

§

impl<const D: usize> RefUnwindSafe for Shape<D>

§

impl<const D: usize> Send for Shape<D>

§

impl<const D: usize> Sync for Shape<D>

§

impl<const D: usize> Unpin for Shape<D>

§

impl<const D: usize> UnwindSafe for Shape<D>

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> 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.