pub struct Spring {
pub stiffness: f64,
pub damping: f64,
pub mass: f64,
}Expand description
A damped spring: what pulls a value toward its target.
Fields§
§stiffness: f64How hard it pulls. Higher is faster.
damping: f64How much it resists motion. Lower overshoots more.
mass: f64The weight it moves. Higher is slower and overshoots more.
Implementations§
Source§impl Spring
impl Spring
Sourcepub const fn new(stiffness: f64, damping: f64) -> Spring
pub const fn new(stiffness: f64, damping: f64) -> Spring
A spring of mass 1 with this stiffness and damping.
Sourcepub fn from_response(response: f64, ratio: f64) -> Spring
pub fn from_response(response: f64, ratio: f64) -> Spring
The spring an AnimSpec::spring of this response (the period of the undamped
oscillation, in seconds) and damping ratio describes, with a mass of 1: the same
motion on the frame-driven path as a native spring animation of that spec.
Sourcepub fn curve(self) -> Curve
pub fn curve(self) -> Curve
The spring as an animation curve: its response and damping ratio, for
AnimSpec. AnimSpec::spring(response, ratio) with these two is the native
animation that matches this spring released at rest.
Sourcepub fn step(self, state: &mut SpringState, target: f64, dt: f64)
pub fn step(self, state: &mut SpringState, target: f64, dt: f64)
Advances state toward target by dt seconds. A long frame is split into steps of at
most a millisecond, so a stiff spring stays stable when the display stalls.
Sourcepub fn settled(self, state: SpringState, target: f64) -> bool
pub fn settled(self, state: SpringState, target: f64) -> bool
Whether state has come to rest on target: both its distance and its speed are below
what a display can show.
Trait Implementations§
impl Copy for Spring
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> 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,
impl<T> ErasedDestructor for Twhere
T: 'static,
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