Skip to main content

Spring

Struct Spring 

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

A damped spring of unit mass, set by (duration, bounce). The fields are private so the invariants hold: the duration is 0 (no spring, see Spring::NONE) or within Spring::MIN_DURATION..=Spring::MAX_DURATION, and the bounce is within -MAX_BOUNCE..=MAX_BOUNCE.

Implementations§

Source§

impl Spring

Source

pub const MIN_DURATION: f32 = 0.01

The shortest duration of a spring that moves, in seconds.

Source

pub const MAX_DURATION: f32 = 60.0

The longest duration, in seconds.

Source

pub const MAX_BOUNCE: f32 = 0.95

The largest bounce either way.

Source

pub const DEFAULT: Spring

0.3 s without bounce: the default for most interface motion.

Source

pub const NONE: Spring

No spring: values jump to their target (treated like Curve::Instant).

Source

pub const fn new(duration: f32, bounce: f32) -> Spring

A spring of duration seconds and bounce (−0.95..=0.95). Never panics: a NaN duration gives the default 0.3 s, zero or negative gives Spring::NONE, other values are clamped to MIN_DURATION..=MAX_DURATION; a NaN bounce is 0 and others are clamped.

Source

pub const fn from_response(response: f32, damping_ratio: f32) -> Spring

A spring from a response (the duration) and a damping ratio ζ (1 = critical, below 1 bounces). Clamped like Spring::new; a NaN ratio is 1.

Source

pub const fn duration(self) -> f32

The duration in seconds (0 for Spring::NONE).

Source

pub const fn bounce(self) -> f32

The bounce, −0.95..=0.95.

Source

pub const fn is_none(self) -> bool

Whether this is no spring at all (duration 0): values jump.

Source

pub fn damping_ratio(self) -> f32

The damping ratio ζ.

Source

pub fn stiffness(self) -> f32

The stiffness k = ω² for unit mass (0 for Spring::NONE).

Source

pub fn damping(self) -> f32

The damping coefficient c = 2ζω for unit mass (0 for Spring::NONE).

Source

pub fn sample(self, x0: f32, v0: f32, target: f32, t: f32) -> (f32, f32)

Position and velocity t seconds after starting at x0 with velocity v0, pulled to target. Closed form for all three damping regimes. Non-finite inputs are replaced (position by the target, velocity by 0, a bad target by the start), t ≤ 0 returns the start, and the result is always finite.

Source

pub fn settle_time(self, from: f32, v0: f32, target: f32, eps: Eps) -> f32

The time in seconds after which a motion from (from, v0) to target stays within eps (position and velocity) for good. Never earlier than the true settle (it is the last crossing of a bound of the motion), at most MAX_SETTLE, and 0 when already settled.

Source

pub fn settle_time_lanes( self, lanes: impl IntoIterator<Item = (f32, f32, f32)>, eps: Eps, ) -> f32

The settle time of several lanes (from, v0, target) moving together: one bound over all of them (each coefficient of the bound is the largest of any lane’s), so it is never earlier than any lane’s settle and costs one root solve.

Trait Implementations§

Source§

impl Clone for Spring

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 Spring

Source§

impl Debug for Spring

Source§

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

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

impl Default for Spring

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Spring> for Curve

Source§

fn from(s: Spring) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Spring

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Spring

Auto Trait Implementations§

§

impl Forget for Spring

§

impl Freeze for Spring

§

impl Move for Spring

§

impl RefUnwindSafe for Spring

§

impl Send for Spring

§

impl Sync for Spring

§

impl Unpin for Spring

§

impl UnsafeUnpin for Spring

§

impl UnwindSafe for Spring

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.