pub fn sampled_easing(
config: SpringConfig,
epsilon: f32,
) -> (Duration, impl Fn(f32) -> f32)Expand description
Returns the time a spring takes to settle from rest, and an easing that samples it over that time.
The spring starts at rest at zero and moves to 1.0. The easing maps progress 0.0..=1.0
across the settling time, so it fits APIs that take a duration and an easing, such as
Animation::with_easing. The easing can overshoot 1.0.
Retargeting a duration-based animation restarts it. Use SpringConfig::step when keeping
velocity matters.
ยงExamples
use std::time::Duration;
use gpui::{sampled_easing, spring};
let (duration, ease) = sampled_easing(spring(100., 6., 1.), 0.001);
assert!(duration > Duration::ZERO);
assert_eq!(ease(0.0), 0.0);
assert_eq!(ease(1.0), 1.0);
assert!((1..100).any(|step| ease(step as f32 / 100.0) > 1.0));