pub enum Curve {
Spring(Spring),
Tween {
duration: f32,
easing: Easing,
},
Decay {
k: f32,
},
Instant,
}Expand description
How a value moves to its target. Every curve starts from the value’s current position and velocity, so a retarget mid-flight never jumps or snaps its speed.
Variants§
Spring(Spring)
A spring (the default for interface motion).
Tween
A timed curve: duration seconds along easing. A starting velocity fades out over the
duration, so it is kept at the start and the value still lands at duration.
Fields
Decay
Momentum: the value coasts on its velocity and slows at k per second, resting at
x + v / k. The target is ignored (see gesture::project for where it rests).
Fields
Instant
Jump to the target.
Implementations§
Source§impl Curve
impl Curve
Sourcepub const fn tween(duration: f32, easing: Easing) -> Curve
pub const fn tween(duration: f32, easing: Easing) -> Curve
A tween of duration seconds (sanitised like the field docs say).
Sourcepub fn decay(rate_per_ms: f32) -> Curve
pub fn decay(rate_per_ms: f32) -> Curve
Momentum with a per-millisecond deceleration rate (0.998 normal, 0.99 fast; see
gesture::deceleration).
Sourcepub const fn sanitized(self) -> Curve
pub const fn sanitized(self) -> Curve
The same curve with its public fields in range: a zero-length tween or spring becomes
Curve::Instant.
Sourcepub const fn is_instant(self) -> bool
pub const fn is_instant(self) -> bool
Whether the value jumps.
Sourcepub fn rest(self, x0: f32, v0: f32, target: f32) -> f32
pub fn rest(self, x0: f32, v0: f32, target: f32) -> f32
Where a motion from (x0, v0) toward target comes to rest: the target, or for
Curve::Decay the projected point x0 + v0 / k.
Sourcepub fn sample(self, x0: f32, v0: f32, target: f32, t: f32) -> (f32, f32)
pub fn sample(self, x0: f32, v0: f32, target: f32, t: f32) -> (f32, f32)
Position and velocity t seconds into a motion from (x0, v0) toward target. Always
finite; t ≤ 0 (or NaN) is the start.
Sourcepub fn settle_time(self, x0: f32, v0: f32, target: f32, eps: Eps) -> f32
pub fn settle_time(self, x0: f32, v0: f32, target: f32, eps: Eps) -> f32
Seconds until a motion from (x0, v0) toward target stays within eps for good (the
duration for a tween, 0 for instant, at most MAX_SETTLE).
Sourcepub fn settle_time_lanes(
self,
lanes: impl IntoIterator<Item = (f32, f32, f32)>,
eps: Eps,
) -> f32
pub fn settle_time_lanes( self, lanes: impl IntoIterator<Item = (f32, f32, f32)>, eps: Eps, ) -> f32
The settle time of several lanes (x0, v0, target) moving together along this curve:
never earlier than any lane’s (see Spring::settle_time_lanes).