Skip to main content

FrictionSimulation

Struct FrictionSimulation 

Source
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

Source

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.

Source

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.

Source

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.

Source

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

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 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 is_done(&self, time: f64) -> bool

Settled once the velocity is within tolerance — or, with a constant deceleration, once that term has cancelled the drag term outright, which a zero velocity tolerance (a Self::through curve asked to arrive stopped) would otherwise never report.

Source§

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

The position at time seconds.
Source§

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

The velocity at time seconds.

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> ErasedDestructor for T
where T: 'static,

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> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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.