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>
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 builder(from: Value, to: Value) -> SpringBuilder<Value>
pub fn builder(from: Value, to: Value) -> SpringBuilder<Value>
Starts a builder with the default physical parameters and settling threshold.
Sourcepub fn settle_duration(&self) -> Duration
pub fn settle_duration(&self) -> Duration
Returns the conservative time at which the spring reaches its target exactly.