MaterialSpringSpec
struct · ferroui-themes-material · v0.5.0
struct MaterialSpringSpec
Parameters of a unit-mass damped spring: x'' + 2 ζ √k x' + k (x-target) = 0.
Members
new
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.
damping_ratio
const fn damping_ratio(self: Self) -> f64
stiffness
const fn stiffness(self: Self) -> f64
sample
fn sample(self: 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.
settling_duration
fn settling_duration(self: 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.
settling_duration_from
fn settling_duration_from(self: 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
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedPropertyValueAnyValueClassDefaultsErasedDestructorIntoEitherCastableFrom<ST, Uninit, Uninit>CastableFrom<ST, Initialized, Initialized>Read<Exclusive, BecauseExclusive>CloneCopyDebugStructuralPartialEqPartialEq
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.