pub struct SpringSpec {
pub duration: f32,
pub bounce: f32,
}Expand description
A spring described the way designers tune one: how long it takes to settle, and how much it bounces.
duration is the period of the undamped spring in seconds, which is
close to how long the motion reads as taking. bounce runs from -1 to
1: 0 settles as fast as possible without overshooting, positive values
overshoot and oscillate, and negative values approach more gently.
Fields§
§duration: f32§bounce: f32Implementations§
Source§impl SpringSpec
impl SpringSpec
Sourcepub const SMOOTH: SpringSpec
pub const SMOOTH: SpringSpec
Settles without overshoot.
Sourcepub const SNAPPY: SpringSpec
pub const SNAPPY: SpringSpec
Quick, with a hint of overshoot.
Sourcepub const BOUNCY: SpringSpec
pub const BOUNCY: SpringSpec
Visibly overshoots and settles back.
Sourcepub const REST_THRESHOLD: f64 = 1.0e-3
pub const REST_THRESHOLD: f64 = 1.0e-3
How far from rest, as a share of the distance travelled, a spring counts as settled.
pub const fn new(duration: f32, bounce: f32) -> SpringSpec
Sourcepub fn from_physics(stiffness: f32, damping: f32) -> SpringSpec
pub fn from_physics(stiffness: f32, damping: f32) -> SpringSpec
The spec matching a unit-mass spring with this stiffness and
damping.
Sourcepub fn damping_ratio(self) -> f32
pub fn damping_ratio(self) -> f32
The damping ratio: below 1 oscillates, 1 is critically damped.
Sourcepub fn progress(self, elapsed: f64) -> f32
pub fn progress(self, elapsed: f64) -> f32
Progress from 0 to 1 after elapsed seconds of a spring released
from rest. Bouncy springs overshoot past 1 before settling.
Sourcepub fn settling_duration(self) -> f64
pub fn settling_duration(self) -> f64
Seconds until a spring released from rest stays within
SpringSpec::REST_THRESHOLD of its target.
Trait Implementations§
Source§impl Clone for SpringSpec
impl Clone for SpringSpec
Source§fn clone(&self) -> SpringSpec
fn clone(&self) -> SpringSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more