pub struct Spring {
pub stiffness: f64,
pub damping: f64,
pub mass: f64,
pub initial_velocity: f64,
pub epsilon: f64,
}Expand description
A damped spring.
Springs are described by how they feel — how stiff, how damped, how heavy — rather than by a duration, and they settle when they settle. That is why they are worth having next to the fixed-duration curves: a window flung by a gesture should carry the gesture’s velocity into its animation, which no amount of easing curve can express.
Fields§
§stiffness: f64How hard it pulls toward the target. Higher is faster and snappier.
damping: f64How much it resists moving. Higher settles sooner with less overshoot.
mass: f64How heavy the thing being moved is. Higher is slower and more sluggish.
initial_velocity: f64Velocity at the start, in fractions of the distance per second. A gesture’s throw speed goes here.
epsilon: f64How close counts as arrived.
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn value_at(&self, seconds: f64) -> f64
pub fn value_at(&self, seconds: f64) -> f64
The fraction of the way to the target at seconds.
Solved in closed form rather than integrated step by step, so the value depends only on the time asked for. A stepped simulation would give different answers at different frame rates, which is precisely the bug that makes an animation feel different on a 60 Hz screen than on a 260 Hz one.
Sourcepub fn settle_time(&self) -> Duration
pub fn settle_time(&self) -> Duration
Roughly when it stops moving, so a caller knows when to stop asking.
Found by walking forward rather than solved, because the exact answer needs the Lambert W function and this is only ever used to decide when to drop an animation.