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.
Builders validate the complete candidate configuration immediately. Nonfinite or nonpositive physical parameters, an unrepresentable response or settling time, and invalid thresholds panic. 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, ResourcePool, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let movement = Spring::new(Point::ORIGIN, Point::new(100.0, 40.0))
.damping(20.0)
.settling_threshold(0.0001);
let end = movement.duration().unwrap();
assert_eq!(movement.sample(end), Point::new(100.0, 40.0));
assert_eq!(movement.sample((-1).seconds()), Point::ORIGIN);Implementations§
Source§impl<Value> Spring<Value>
impl<Value> Spring<Value>
Sourcepub fn new(from: Value, to: Value) -> Self
pub fn new(from: Value, to: Value) -> Self
Creates a spring with the default physical parameters and settling threshold.
Sourcepub fn mass(self, mass: f64) -> Self
pub fn mass(self, mass: f64) -> Self
Sets finite positive mass and recomputes the finite response immediately.
Sourcepub fn stiffness(self, stiffness: f64) -> Self
pub fn stiffness(self, stiffness: f64) -> Self
Sets finite positive stiffness and recomputes the response immediately.
Sourcepub fn damping(self, damping: f64) -> Self
pub fn damping(self, damping: f64) -> Self
Sets finite strictly positive damping. Zero has no finite settling time.
Sourcepub fn initial_velocity(self, velocity: f64) -> Self
pub fn initial_velocity(self, velocity: f64) -> Self
Sets finite normalized velocity towards the target; negative moves away. Units are endpoint distances per second, not pixels per second.
Sourcepub fn settling_threshold(self, threshold: f64) -> Self
pub fn settling_threshold(self, threshold: f64) -> Self
Sets a finite relative displacement-envelope threshold strictly between zero and one. This is not a pixel tolerance or a velocity threshold.
Trait Implementations§
Source§impl<Value: Interpolate + Send + Sync> Animation<Value> for Spring<Value>
impl<Value: Interpolate + Send + Sync> Animation<Value> for Spring<Value>
Source§fn sample(&self, time: Time) -> Value
fn sample(&self, time: Time) -> Value
Source§fn duration(&self) -> Option<Duration>
fn duration(&self) -> Option<Duration>
None for an unbounded signal.Source§fn map<Output, Function>(self, function: Function) -> Map<Self, Function, Value>
fn map<Output, Function>(self, function: Function) -> Map<Self, Function, Value>
Source§fn zip<OtherValue, Other>(self, other: Other) -> Zip<Self, Other>
fn zip<OtherValue, Other>(self, other: Other) -> Zip<Self, Other>
Source§fn delay(self, offset: Duration) -> Delay<Self>where
Self: Sized,
fn delay(self, offset: Duration) -> Delay<Self>where
Self: Sized,
Source§fn speed(self, factor: f64) -> Speed<Self>where
Self: Sized,
fn speed(self, factor: f64) -> Speed<Self>where
Self: Sized,
Source§fn then<Next: Animation<Value>>(self, next: Next) -> Then<Self, Next>where
Self: Sized,
fn then<Next: Animation<Value>>(self, next: Next) -> Then<Self, Next>where
Self: Sized,
Source§fn reverse(self) -> Reverse<Self>where
Self: Sized,
fn reverse(self) -> Reverse<Self>where
Self: Sized,
Source§fn repeat(self, count: u32) -> Repeat<Self>where
Self: Sized,
fn repeat(self, count: u32) -> Repeat<Self>where
Self: Sized,
count times. Intermediate boundaries restart;
the final boundary holds the target. Zero repeats hold the initial value.
Infinite sources or duration overflow panic at construction.