pub struct FrictionSimulation { /* private fields */ }Expand description
Exponential drag decay: the iOS-style fling curve, and the friction phase of
BouncingScrollSimulation.
drag is the fraction of velocity surviving one second and must sit in
(0, 1). An optional constant deceleration subtracts a linear velocity term
on top of the drag, for a caller that wants a fling to stop sooner than pure
drag would; at 0.0 the curve is pure drag and only ever approaches
FrictionSimulation::final_x.
Implementations§
Source§impl FrictionSimulation
impl FrictionSimulation
Sourcepub fn new(
drag: f64,
position: f64,
velocity: f64,
tolerance: Tolerance,
constant_deceleration: f64,
) -> Self
pub fn new( drag: f64, position: f64, velocity: f64, tolerance: Tolerance, constant_deceleration: f64, ) -> Self
A drag curve from position at velocity px/s.
constant_deceleration is 0.0 for pure drag; a nonzero value is
re-signed against velocity internally, so callers pass a magnitude.
Sourcepub fn through(
start_x: f64,
end_x: f64,
start_velocity: f64,
end_velocity: f64,
) -> Self
pub fn through( start_x: f64, end_x: f64, start_velocity: f64, end_velocity: f64, ) -> Self
The drag curve that passes through both endpoints: at start_x moving
start_velocity, at end_x moving end_velocity (Flutter’s
FrictionSimulation.through, whose _dragFor is the exponential
below). Settles within end_velocity, the speed the caller asked to
arrive at.
Sourcepub fn final_x(&self) -> f64
pub fn final_x(&self) -> f64
Where the curve ends up: the drag asymptote under pure drag, the position at the final time once a constant deceleration stops it early.
Sourcepub fn time_at_x(&self, x: f64) -> f64
pub fn time_at_x(&self, x: f64) -> f64
The time at which the curve reaches x, or f64::INFINITY if it
never does (wrong side of the start, or beyond Self::final_x).
Inverts the pure-drag position, so with a nonzero constant deceleration
the answer is an over-estimate of how far the curve actually gets — the
same approximation Flutter’s timeAtX makes, and harmless for its one
caller (BouncingScrollSimulation finding its edge crossing).