pub enum Shape<const D: usize> {
Ball {
radius: f32,
},
Box {
half_extents: [f32; D],
},
}Variants§
Implementations§
Source§impl<const D: usize> Shape<D>
impl<const D: usize> Shape<D>
Sourcepub fn sweep_ball(
self,
center: [f32; D],
origin: [f32; D],
radius: f32,
displacement: [f32; D],
) -> Result<Option<SweepHit<D>>, PhysicsError>
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());