Skip to main content

SpringSpec

Struct SpringSpec 

Source
pub struct SpringSpec {
    pub stiffness: f32,
    pub damping: f32,
    pub mass: f32,
    pub rest_displacement: f32,
    pub rest_velocity: f32,
}
Expand description

Physical spring parameters for an interruptible damped harmonic oscillator.

Fields§

§stiffness: f32§damping: f32§mass: f32§rest_displacement: f32§rest_velocity: f32

Implementations§

Source§

impl SpringSpec

Source

pub fn new(stiffness: f32, damping: f32, mass: f32) -> Self

Creates a sanitized SpringSpec with default settle thresholds.

Source

pub const fn from_raw(stiffness: f32, damping: f32, mass: f32) -> Self

Compile-time constructor for static/const spring presets using default rest thresholds.

Invalid or non-finite values are still sanitized on evaluation by SpringState::step.

Source

pub fn with_rest_thresholds(self, displacement: f32, velocity: f32) -> Self

Configures custom position and velocity settle thresholds.

Source

pub const fn snappy() -> Self

Crisp, responsive UI spring (slight underdamping, zeta ~ 0.75).

Source

pub const fn gentle() -> Self

Smooth, low-overshoot spring for larger layout or sheet transitions (zeta ~ 0.91).

Source

pub const fn bouncy() -> Self

Expressive, bouncy spring with pronounced overshoot (zeta ~ 0.39).

Source

pub const fn stiff() -> Self

Fast, nearly critically damped spring with virtually zero overshoot (zeta ~ 0.98).

Source

pub fn from_omega(omega: f32) -> Self

Critically damped spring (zeta = 1.0, mass = 1.0) from natural angular frequency omega in rad/s (stiffness = omega^2, damping = 2 * omega, clamped to [1e-2, 1e18] so stiffness never overflows f32 or underflows MIN_STIFFNESS).

Source

pub fn from_damping_ratio(damping_ratio: f32, response_s: f32) -> Self

Parameterizes a unit-mass spring from dimensionless damping_ratio (zeta, where 1.0 is critically damped, < 1.0 under-damped, > 1.0 over-damped) and undamped natural period response_s in seconds (clamped to [0.01, 600.0]).

Source

pub fn from_duration_bounce(duration_s: f32, bounce: f32) -> Self

Apple SwiftUI-style intuitive spring parameterization:

  • duration_s: perceptual settle duration in seconds (clamped to [0.01, 600.0]).
  • bounce: bounciness in [-1.0, 1.0] (0.0 = critically damped, > 0.0 = underdamped with overshoot, < 0.0 = overdamped). Clamped internally to [-0.95, 0.99] so damping stays strictly positive and finite.
Source

pub fn angular_frequency(&self) -> f32

Natural angular frequency omega_0 = sqrt(stiffness / mass) in rad/s.

Source

pub fn damping_ratio(&self) -> f32

Dimensionless damping ratio zeta = damping / (2 * sqrt(stiffness * mass)). < 1 is underdamped, == 1 is critically damped, > 1 is overdamped.

Source

pub fn settle_duration_s(&self) -> f32

Time in seconds for a step response envelope to stay within 0.1 % (1e-3) of its target, continuous across all damping ratios zeta (including zeta == 1) and clamped to [0.01, 10].

Trait Implementations§

Source§

impl Clone for SpringSpec

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 SpringSpec

Source§

impl Debug for SpringSpec

Source§

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

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

impl Default for SpringSpec

Source§

fn default() -> Self

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

impl PartialEq for SpringSpec

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 SpringSpec

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.