pub struct SpringState {
pub value: f32,
pub velocity: f32,
pub target: f32,
}Expand description
Live scalar spring state (value, velocity, target).
Fields§
§value: f32§velocity: f32§target: f32Implementations§
Source§impl SpringState
impl SpringState
Sourcepub const fn settled(value: f32) -> Self
pub const fn settled(value: f32) -> Self
Creates an already-settled spring at value (velocity = 0.0, target = value).
Sourcepub const fn new(value: f32, target: f32) -> Self
pub const fn new(value: f32, target: f32) -> Self
Creates a spring starting at value with zero initial velocity moving toward target.
Sourcepub const fn with_velocity(value: f32, velocity: f32, target: f32) -> Self
pub const fn with_velocity(value: f32, velocity: f32, target: f32) -> Self
Creates a spring with explicit initial value, velocity, and target.
Sourcepub fn retarget(&mut self, new_target: f32)
pub fn retarget(&mut self, new_target: f32)
Retargets this spring mid-flight to new_target while preserving exact value and
velocity (zero jump, full physical momentum conservation).
Sourcepub fn snap_to_target(&mut self)
pub fn snap_to_target(&mut self)
Snaps immediately to target with zero velocity.
Sourcepub fn is_settled(&self, spec: &SpringSpec) -> bool
pub fn is_settled(&self, spec: &SpringSpec) -> bool
Returns true when displacement from target and velocity are both within spec’s
rest thresholds, allowing hosts/display-links to drop to 0% idle CPU/GPU.
Sourcepub fn evaluate(&self, spec: &SpringSpec, dt_s: f32) -> (f32, f32)
pub fn evaluate(&self, spec: &SpringSpec, dt_s: f32) -> (f32, f32)
Evaluates (value, velocity) after dt_s seconds without mutating self.
Sourcepub fn step(&mut self, spec: &SpringSpec, dt_s: f32) -> bool
pub fn step(&mut self, spec: &SpringSpec, dt_s: f32) -> bool
Advances the spring analytically by dt_s seconds under spec, snapping cleanly to
(target, 0.0) once settled. Returns true when settled after this step.
Sourcepub fn step_or_snap(
&mut self,
spec: &SpringSpec,
dt_s: f32,
instant: bool,
) -> bool
pub fn step_or_snap( &mut self, spec: &SpringSpec, dt_s: f32, instant: bool, ) -> bool
Convenience helper: snaps immediately to target when instant is true (e.g. reduced
motion active), otherwise advances via Self::step.