pub struct SpringConfig {
pub stiffness: f32,
pub damping: f32,
pub mass: f32,
}Expand description
The physical parameters of a damped harmonic oscillator.
stiffness and mass must be finite and positive. damping must be finite
and non-negative.
Fields§
§stiffness: f32The spring stiffness, conventionally written as $k$.
damping: f32The viscous damping coefficient, conventionally written as $c$.
mass: f32The moving mass, conventionally written as $m$.
Implementations§
Source§impl SpringConfig
impl SpringConfig
Sourcepub const fn new(stiffness: f32, damping: f32, mass: f32) -> Self
pub const fn new(stiffness: f32, damping: f32, mass: f32) -> Self
Creates a spring from its physical parameters.
Sourcepub fn canonical(&self) -> (f32, f32)
pub fn canonical(&self) -> (f32, f32)
Returns the natural angular frequency and damping ratio $(\omega_0, \zeta)$.
Sourcepub fn step(
&self,
state: SpringState,
target: f32,
delta_time: f32,
) -> SpringState
pub fn step( &self, state: SpringState, target: f32, delta_time: f32, ) -> SpringState
Advances a spring toward a target that remains fixed for delta_time.
This analytic step is independent of frame rate and preserves velocity, allowing an interrupted spring to be retargeted without restarting it.
Sourcepub fn step_ramp(
&self,
state: SpringState,
target: f32,
target_velocity: f32,
delta_time: f32,
) -> SpringState
pub fn step_ramp( &self, state: SpringState, target: f32, target_velocity: f32, delta_time: f32, ) -> SpringState
Advances a spring toward a target moving at a constant velocity.
A first-order hold avoids the frame-rate-dependent lag introduced by treating a dragged target as stationary between frames.
Sourcepub fn propagator(&self, delta_time: f32) -> [[f32; 2]; 2]
pub fn propagator(&self, delta_time: f32) -> [[f32; 2]; 2]
Returns the exact state-transition matrix for a constant target.
Materializing this matrix is useful when many springs share the same configuration and frame delta. A matrix must not be reused when the frame delta changes.
Sourcepub fn is_settled(&self, state: SpringState, target: f32, epsilon: f32) -> bool
pub fn is_settled(&self, state: SpringState, target: f32, epsilon: f32) -> bool
Tests both displacement and velocity against a positional tolerance.
Velocity is compared with epsilon * natural_frequency, giving it the
corresponding animated-units-per-second scale.
Sourcepub fn settle_time(
&self,
state: SpringState,
target: f32,
epsilon: f32,
) -> Duration
pub fn settle_time( &self, state: SpringState, target: f32, epsilon: f32, ) -> Duration
Returns a conservative time after which the spring remains settled.
An undamped spring has no finite settling time and returns
Duration::MAX.
Trait Implementations§
Source§impl Clone for SpringConfig
impl Clone for SpringConfig
Source§fn clone(&self) -> SpringConfig
fn clone(&self) -> SpringConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SpringConfig
Source§impl Debug for SpringConfig
impl Debug for SpringConfig
Source§impl PartialEq for SpringConfig
impl PartialEq for SpringConfig
impl StructuralPartialEq for SpringConfig
Auto Trait Implementations§
impl Freeze for SpringConfig
impl RefUnwindSafe for SpringConfig
impl Send for SpringConfig
impl Sync for SpringConfig
impl Unpin for SpringConfig
impl UnsafeUnpin for SpringConfig
impl UnwindSafe for SpringConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more