pub struct Spring { /* private fields */ }Expand description
The animation vocabulary: the shell-fed frame clock (FrameTime)
plus the pure easing/interpolation/spring math a widget or app advances it
through, flat-re-exported from frust-core::anim. Time enters from the
shell during paint (PaintCtx::frame_time); nothing here reads a clock.
The analytic response of a SpringDesc released from an initial
displacement + velocity toward equilibrium at 0.
Positions returned by Spring::position are displacements from
equilibrium (the target), so equilibrium is always 0. The closed-form
solution branches on the damping regime; all three are exact (no numerical
integration), which is what lets a fling be evaluated at an arbitrary frame
time without accumulating step error.
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn new(desc: SpringDesc, x0: f64, v0: f64) -> Spring
pub fn new(desc: SpringDesc, x0: f64, v0: f64) -> Spring
Solve the spring released from displacement x0 (relative to
equilibrium) with initial velocity v0.
Degenerate parameters (non-positive mass/stiffness) fall back to a
critically-damped unit spring so the constructor never produces NaN.
Sourcepub fn position(&self, t: f64) -> f64
pub fn position(&self, t: f64) -> f64
The displacement from equilibrium at elapsed time t (seconds).
Sourcepub fn velocity(&self, t: f64) -> f64
pub fn velocity(&self, t: f64) -> f64
The velocity (d displacement / d t) at elapsed time t (seconds).
Sourcepub fn is_at_rest(&self, t: f64, epsilon: f64) -> bool
pub fn is_at_rest(&self, t: f64, epsilon: f64) -> bool
Whether the spring has effectively settled at equilibrium by time t:
both |position| and |velocity| are below epsilon.
Trait Implementations§
Auto Trait Implementations§
impl Freeze 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.