Skip to main content

FrictionSimulation

Struct FrictionSimulation 

Source
pub struct FrictionSimulation { /* private fields */ }
Expand description

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

Source

pub fn new( drag: f32, position: f32, velocity: f32, tolerance: Tolerance, ) -> Self

Friction from position at velocity, with the coefficient drag.

Source

pub fn with_constant_deceleration( drag: f32, position: f32, velocity: f32, tolerance: Tolerance, constant_deceleration: f32, ) -> Self

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.

Source

pub fn through( start: f32, end: f32, start_velocity: f32, end_velocity: f32, tolerance: Tolerance, ) -> Self

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₁)).

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for FrictionSimulation

Source§

impl Debug for FrictionSimulation

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Simulation for FrictionSimulation

Source§

fn x(&self, time: f32) -> f32

The position at instant time.
Source§

fn dx(&self, time: f32) -> f32

The velocity — the derivative of position — at instant time.
Source§

fn is_done(&self, time: f32) -> bool

true once the motion has finished, within the tolerances.
Source§

fn tolerance(&self) -> Tolerance

The stopping thresholds.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.