pub struct MaterialSpringSpec { /* private fields */ }Expand description
Parameters of a unit-mass damped spring: x'' + 2 ζ √k x' + k (x-target) = 0.
Implementations§
Source§impl MaterialSpringSpec
impl MaterialSpringSpec
Sourcepub const fn new(damping_ratio: f64, stiffness: f64) -> Self
pub const fn new(damping_ratio: f64, stiffness: f64) -> Self
Creates a spring. Stiffness must be positive and finite; damping must be finite and nonnegative. A zero-damping spring oscillates forever and has no settling duration.
pub const fn damping_ratio(self) -> f64
pub const fn stiffness(self) -> f64
Sourcepub fn sample(
self,
elapsed: f64,
from: f64,
target: f64,
initial_velocity: f64,
) -> MaterialSpringSample
pub fn sample( self, elapsed: f64, from: f64, target: f64, initial_velocity: f64, ) -> MaterialSpringSample
Evaluates both position and velocity analytically, independent of display refresh rate.
All three damping regimes are supported. The overdamped case uses a stable slow root
and expm1 to avoid subtracting nearly equal exponentials near critical damping.
The underdamped case uses sinc, so its limit at critical damping is also well behaved.
A negative/NaN elapsed time leaves the initial state unchanged; positive infinity is
treated as the settled state. Initial and target values must be finite.
Sourcepub fn settling_duration(self) -> f64
pub fn settling_duration(self) -> f64
A conservative finite tail for the unit step, with position tolerance 0.001 and
velocity tolerance 0.001 * sqrt(stiffness). Returns infinity for an undamped spring.
Sourcepub fn settling_duration_from(
self,
displacement: f64,
velocity: f64,
position_threshold: f64,
velocity_threshold: f64,
) -> f64
pub fn settling_duration_from( self, displacement: f64, velocity: f64, position_threshold: f64, velocity_threshold: f64, ) -> f64
A conservative settling time for an arbitrary interrupted spring, in seconds.
Both the position and velocity stay below their respective tolerances after this time. Unlike the unit-step adapter, this accounts for momentum when the new target is very close to the current position. Bounds are analytical exponential envelopes; this does not advance a simulation or mistake an oscillation’s zero crossing for rest.
Trait Implementations§
Source§impl Clone for MaterialSpringSpec
impl Clone for MaterialSpringSpec
impl Copy for MaterialSpringSpec
Source§impl Debug for MaterialSpringSpec
impl Debug for MaterialSpringSpec
Source§impl PartialEq for MaterialSpringSpec
impl PartialEq for MaterialSpringSpec
impl StructuralPartialEq for MaterialSpringSpec
Auto Trait Implementations§
impl Freeze for MaterialSpringSpec
impl RefUnwindSafe for MaterialSpringSpec
impl Send for MaterialSpringSpec
impl Sync for MaterialSpringSpec
impl Unpin for MaterialSpringSpec
impl UnsafeUnpin for MaterialSpringSpec
impl UnwindSafe for MaterialSpringSpec
Blanket Implementations§
Source§impl<T> AnyValue for Twhere
T: PartialEq + 'static,
impl<T> AnyValue for Twhere
T: PartialEq + 'static,
fn any_value_as_any(&self) -> &(dyn Any + 'static)
fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool
fn any_value_type_name(&self) -> &'static str
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more