pub struct FrictionSimulation { /* private fields */ }Expand description
The shared animation layer — physics, curves, driver — see
frus_core::animation. Re-exported here so applications can reach it through
frus_widgets without depending on frus-core directly.
Friction deceleration — scroll and fling momentum — in closed form.
drag ∈ (0, 1): the closer to 1, the longer the motion keeps rolling.
Implementations§
Source§impl FrictionSimulation
impl FrictionSimulation
Sourcepub fn new(
drag: f32,
position: f32,
velocity: f32,
tolerance: Tolerance,
) -> FrictionSimulation
pub fn new( drag: f32, position: f32, velocity: f32, tolerance: Tolerance, ) -> FrictionSimulation
Friction from position at velocity, with the coefficient drag.
Sourcepub fn with_constant_deceleration(
drag: f32,
position: f32,
velocity: f32,
tolerance: Tolerance,
constant_deceleration: f32,
) -> FrictionSimulation
pub fn with_constant_deceleration( drag: f32, position: f32, velocity: f32, tolerance: Tolerance, constant_deceleration: f32, ) -> FrictionSimulation
Friction with a constant deceleration on top of the drag.
constant_deceleration is given unsigned and applied against the direction
of travel. Nought gives exactly Self::new; anything else brings the
motion to a stop in finite time, which drag alone never does.
The closed forms stop working here. With drag alone, dx(t) = v₀·D^t is
invertible and the instant the motion passes a given point can be written
down; add −c·t and neither the stopping time nor the crossing time has a
closed form at all. Both are found by Newton’s method, which is what the
reference does and for the same reason.
Sourcepub fn through(
start: f32,
end: f32,
start_velocity: f32,
end_velocity: f32,
tolerance: Tolerance,
) -> FrictionSimulation
pub fn through( start: f32, end: f32, start_velocity: f32, end_velocity: f32, tolerance: Tolerance, ) -> FrictionSimulation
A friction calibrated to pass through start (at start_velocity) and
stop at end (at end_velocity), deriving drag from that.
drag = e^((v₀ − v₁)/(x₀ − x₁)).
Sourcepub fn final_x(&self) -> f32
pub fn final_x(&self) -> f32
The final position — the limit as t → ∞, or the place the motion
actually stops when a constant deceleration gives it an end.
Sourcepub fn time_at_x(&self, x: f32) -> f32
pub fn time_at_x(&self, x: f32) -> f32
The instant at which the motion passes through x, or ∞ when it never
does — because it starts the wrong way round, or because x lies beyond
Self::final_x. Inverting x(t) is what lets a fling hand over to a spring
exactly at the edge of the content.
Trait Implementations§
Source§impl Clone for FrictionSimulation
impl Clone for FrictionSimulation
Source§fn clone(&self) -> FrictionSimulation
fn clone(&self) -> FrictionSimulation
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more