Skip to main content

Spring

Struct Spring 

Source
pub struct Spring<Value> { /* private fields */ }
Expand description

A finite physical spring between arbitrary interpolatable values.

Initial velocity is in endpoint distances per second. The default mass is one, stiffness 100, damping 10 and initial velocity zero. Duration is the conservative displacement-envelope settling time at threshold 0.001, rounded up to ticks. Values at/before zero and at/after duration are exact stored endpoints.

SpringBuilder::build validates the complete configuration at once. Nonfinite or nonpositive physical parameters, an unrepresentable response or settling time, and invalid thresholds are reported as errors. Zero damping is rejected because this type promises a finite settling duration. Use a signal for undamped oscillation.

use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let movement = Spring::builder(Point::ORIGIN, Point::new(100.0, 40.0))
    .damping(20.0)
    .settling_threshold(0.0001)
    .build()?;
let end = movement.settle_duration();
assert_eq!(movement.sample(end.after_origin()), Point::new(100.0, 40.0));
assert_eq!(movement.sample(Time::ZERO - 1.seconds()), Point::ORIGIN);

Implementations§

Source§

impl<Value> Spring<Value>

Source

pub fn new(from: Value, to: Value) -> Self

Creates a spring with the default physical parameters and settling threshold.

Source

pub fn builder(from: Value, to: Value) -> SpringBuilder<Value>

Starts a builder with the default physical parameters and settling threshold.

Source

pub fn settle_duration(&self) -> Duration

Returns the conservative time at which the spring reaches its target exactly.

Trait Implementations§

Source§

impl<Value: Clone> Clone for Spring<Value>

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<Value: Debug> Debug for Spring<Value>

Source§

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

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

impl Default for Spring<f64>

Source§

fn default() -> Self

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

impl<Value: Interpolate + Send + Sync> Signal<Value> for Spring<Value>

Source§

fn sample(&self, time: Time) -> Value

Samples without advancing a clock or changing playback state.
Source§

fn sample_at(&self, elapsed: Duration) -> Value

Samples elapsed after the time origin, shorthand for sample(elapsed.after_origin()). Read more
Source§

fn map<Output, Function>(self, function: Function) -> Map<Self, Function, Value>
where Self: Sized, Function: Fn(Value) -> Output + Send + Sync,

Transforms values without changing timing.
Source§

fn zip<OtherValue, Other>(self, other: Other) -> Zip<Self, Other>
where Self: Sized, Other: Signal<OtherValue>,

Samples in parallel; the result is finite only if both inputs are finite.
Source§

fn boxed(self) -> Arc<dyn Signal<Value>> ⓘ
where Self: Sized + 'static,

Shares a type-erased signal.

Auto Trait Implementations§

§

impl<Value> Forget for Spring<Value>

§

impl<Value> Freeze for Spring<Value>
where Value: Freeze,

§

impl<Value> Move for Spring<Value>

§

impl<Value> RefUnwindSafe for Spring<Value>
where Value: RefUnwindSafe,

§

impl<Value> Send for Spring<Value>
where Value: Send,

§

impl<Value> Sync for Spring<Value>
where Value: Sync,

§

impl<Value> Unpin for Spring<Value>
where Value: Unpin,

§

impl<Value> UnsafeUnpin for Spring<Value>
where Value: UnsafeUnpin,

§

impl<Value> UnwindSafe for Spring<Value>
where Value: UnwindSafe,

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.