pub struct SpringSpec {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
pub rest_displacement: f32,
pub rest_velocity: f32,
}Expand description
Physical spring parameters for an interruptible damped harmonic oscillator.
Fields§
§stiffness: f32§damping: f32§mass: f32§rest_displacement: f32§rest_velocity: f32Implementations§
Source§impl SpringSpec
impl SpringSpec
Sourcepub fn new(stiffness: f32, damping: f32, mass: f32) -> Self
pub fn new(stiffness: f32, damping: f32, mass: f32) -> Self
Creates a sanitized SpringSpec with default settle thresholds.
Sourcepub const fn from_raw(stiffness: f32, damping: f32, mass: f32) -> Self
pub const fn from_raw(stiffness: f32, damping: f32, mass: f32) -> Self
Compile-time constructor for static/const spring presets using default rest thresholds.
Invalid or non-finite values are still sanitized on evaluation by SpringState::step.
Sourcepub fn with_rest_thresholds(self, displacement: f32, velocity: f32) -> Self
pub fn with_rest_thresholds(self, displacement: f32, velocity: f32) -> Self
Configures custom position and velocity settle thresholds.
Sourcepub const fn gentle() -> Self
pub const fn gentle() -> Self
Smooth, low-overshoot spring for larger layout or sheet transitions (zeta ~ 0.91).
Sourcepub const fn bouncy() -> Self
pub const fn bouncy() -> Self
Expressive, bouncy spring with pronounced overshoot (zeta ~ 0.39).
Sourcepub const fn stiff() -> Self
pub const fn stiff() -> Self
Fast, nearly critically damped spring with virtually zero overshoot (zeta ~ 0.98).
Sourcepub fn from_omega(omega: f32) -> Self
pub fn from_omega(omega: f32) -> Self
Critically damped spring (zeta = 1.0, mass = 1.0) from natural angular frequency
omega in rad/s (stiffness = omega^2, damping = 2 * omega, clamped to
[1e-2, 1e18] so stiffness never overflows f32 or underflows MIN_STIFFNESS).
Sourcepub fn from_damping_ratio(damping_ratio: f32, response_s: f32) -> Self
pub fn from_damping_ratio(damping_ratio: f32, response_s: f32) -> Self
Parameterizes a unit-mass spring from dimensionless damping_ratio (zeta, where 1.0 is
critically damped, < 1.0 under-damped, > 1.0 over-damped) and undamped natural period
response_s in seconds (clamped to [0.01, 600.0]).
Sourcepub fn from_duration_bounce(duration_s: f32, bounce: f32) -> Self
pub fn from_duration_bounce(duration_s: f32, bounce: f32) -> Self
Apple SwiftUI-style intuitive spring parameterization:
duration_s: perceptual settle duration in seconds (clamped to[0.01, 600.0]).bounce: bounciness in[-1.0, 1.0](0.0= critically damped,> 0.0= underdamped with overshoot,< 0.0= overdamped). Clamped internally to[-0.95, 0.99]so damping stays strictly positive and finite.
Sourcepub fn angular_frequency(&self) -> f32
pub fn angular_frequency(&self) -> f32
Natural angular frequency omega_0 = sqrt(stiffness / mass) in rad/s.
Sourcepub fn damping_ratio(&self) -> f32
pub fn damping_ratio(&self) -> f32
Dimensionless damping ratio zeta = damping / (2 * sqrt(stiffness * mass)).
< 1 is underdamped, == 1 is critically damped, > 1 is overdamped.
Sourcepub fn settle_duration_s(&self) -> f32
pub fn settle_duration_s(&self) -> f32
Time in seconds for a step response envelope to stay within 0.1 % (1e-3) of its
target, continuous across all damping ratios zeta (including zeta == 1) and clamped
to [0.01, 10].