Skip to main content

MaterialSpringSpec

Struct MaterialSpringSpec 

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

Parameters of a unit-mass damped spring: x'' + 2 ζ √k x' + k (x-target) = 0.

Implementations§

Source§

impl MaterialSpringSpec

Source

pub const fn new(damping_ratio: f64, stiffness: f64) -> Self

Creates a spring. Stiffness must be positive and finite; damping must be finite and nonnegative. A zero-damping spring oscillates forever and has no settling duration.

Source

pub const fn damping_ratio(self) -> f64

Source

pub const fn stiffness(self) -> f64

Source

pub fn sample( self, elapsed: f64, from: f64, target: f64, initial_velocity: f64, ) -> MaterialSpringSample

Evaluates both position and velocity analytically, independent of display refresh rate.

All three damping regimes are supported. The overdamped case uses a stable slow root and expm1 to avoid subtracting nearly equal exponentials near critical damping. The underdamped case uses sinc, so its limit at critical damping is also well behaved. A negative/NaN elapsed time leaves the initial state unchanged; positive infinity is treated as the settled state. Initial and target values must be finite.

Source

pub fn settling_duration(self) -> f64

A conservative finite tail for the unit step, with position tolerance 0.001 and velocity tolerance 0.001 * sqrt(stiffness). Returns infinity for an undamped spring.

Source

pub fn settling_duration_from( self, displacement: f64, velocity: f64, position_threshold: f64, velocity_threshold: f64, ) -> f64

A conservative settling time for an arbitrary interrupted spring, in seconds.

Both the position and velocity stay below their respective tolerances after this time. Unlike the unit-step adapter, this accounts for momentum when the new target is very close to the current position. Bounds are analytical exponential envelopes; this does not advance a simulation or mistake an oscillation’s zero crossing for rest.

Trait Implementations§

Source§

impl Clone for MaterialSpringSpec

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 MaterialSpringSpec

Source§

impl Debug for MaterialSpringSpec

Source§

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

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

impl PartialEq for MaterialSpringSpec

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 MaterialSpringSpec

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> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). 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> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.