fix(animator): start the underdamped spring from rest - #224
Closed
LeadcodeDev wants to merge 1 commit into
Closed
LeadcodeDev wants to merge 1 commit into
LeadcodeDev wants to merge 1 commit into
Conversation
LeadcodeDev
force-pushed
the
fix/layer-bounds-outset-shadow
branch
from
September 21, 2026 23:39
baafd53 to
7c9e21a
Compare
LeadcodeDev
force-pushed
the
fix/spring-step-response
branch
from
September 21, 2026 23:39
4c92d97 to
42a83b8
Compare
53 tasks
LeadcodeDev
force-pushed
the
fix/layer-bounds-outset-shadow
branch
from
September 22, 2026 06:09
fcbc3cf to
ee0e0e8
Compare
LeadcodeDev
force-pushed
the
fix/spring-step-response
branch
from
September 22, 2026 06:09
5a808bd to
d414df5
Compare
LeadcodeDev
force-pushed
the
fix/layer-bounds-outset-shadow
branch
from
September 22, 2026 08:33
ee0e0e8 to
6890377
Compare
LeadcodeDev
force-pushed
the
fix/spring-step-response
branch
from
September 22, 2026 08:33
d414df5 to
bdc887f
Compare
LeadcodeDev
force-pushed
the
fix/layer-bounds-outset-shadow
branch
from
September 22, 2026 08:43
6890377 to
7aa0de5
Compare
The closed-form underdamped step response is 1 - e^(-zeta*omega*t) * [cos(omega_d*t) + (zeta*omega/omega_d)*sin(omega_d*t)]. The code feeds zeta*omega*t/omega_d into sin() instead of omega_d*t — the t was multiplied into the coefficient instead of the phase. I verified this numerically against a 400k-step ODE integration of m*x'' + c*x' + k*x = k: the correct formula matches the integrator to 5 decimals, the repo formula does not. With the shipped defaults (damping 15, stiffness 100, mass 1, zeta = 0.75), at the first 60fps frame after the start (t = 0.0167 s) the solver reports 0.10416 of the travel where the physics gives 0.01282 — 8x. Initial velocity is 6.21/s instead of 0, so the element visibly snaps on frame 1 rather than easing out of rest, and the overshoot peak is wrong too (1.0194 vs 1.0284). This affects every spring path in the engine: EasingType::Spring keyframes, the bounce_in preset (kf_anim_spring, zeta = 0.6, animator.rs:2092), elastic_in (kf_anim_spring_underdamped, zeta = 0.274, animator.rs:2106), and every author-supplied spring override applied through apply_spring_to_motion. spring_settle_time/spring_rest_time (what rustmotion info reports and what the spring.duration remap divides by) are derived from the same wrong curve. Fix: Change the sine argument to (omega_d * t).sin(), keeping the (zeta * omega / omega_d) coefficient: 1.0 - decay * ((omega_d * t).sin() * (zeta * omega / omega_d) + (omega_d * t).cos()). Add a regression test asserting the derivative at t=0 is ~0 (a step response starts at rest) and comparing a few samples against a numerically integrated reference. Refs #220
LeadcodeDev
force-pushed
the
fix/spring-step-response
branch
from
September 22, 2026 08:43
bdc887f to
1cde354
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Severity Medium, category correctness. Location:
crates/rustmotion-core/src/engine/animator.rs:504Impact
The closed-form underdamped step response is
1 - e^(-zeta*omega*t) * [cos(omega_d*t) + (zeta*omega/omega_d)*sin(omega_d*t)]. The code feedszeta*omega*t/omega_dintosin()instead ofomega_d*t— thetwas multiplied into the coefficient instead of the phase. I verified this numerically against a 400k-step ODE integration ofm*x'' + c*x' + k*x = k: the correct formula matches the integrator to 5 decimals, the repo formula does not. With the shipped defaults (damping 15, stiffness 100, mass 1, zeta = 0.75), at the first 60fps frame after the start (t = 0.0167 s) the solver reports 0.10416 of the travel where the physics gives 0.01282 — 8x. Initial velocity is 6.21/s instead of 0, so the element visibly snaps on frame 1 rather than easing out of rest, and the overshoot peak is wrong too (1.0194 vs 1.0284). This affects every spring path in the engine:EasingType::Springkeyframes, thebounce_inpreset (kf_anim_spring, zeta = 0.6, animator.rs:2092),elastic_in(kf_anim_spring_underdamped, zeta = 0.274, animator.rs:2106), and every author-suppliedspringoverride applied throughapply_spring_to_motion.spring_settle_time/spring_rest_time(whatrustmotion inforeports and what thespring.durationremap divides by) are derived from the same wrong curve.Fix
Change the sine argument to
(omega_d * t).sin(), keeping the(zeta * omega / omega_d)coefficient:1.0 - decay * ((omega_d * t).sin() * (zeta * omega / omega_d) + (omega_d * t).cos()). Add a regression test asserting the derivative at t=0 is ~0 (a step response starts at rest) and comparing a few samples against a numerically integrated reference.Evidence the audit read
Part of the September 2026 audit remediation chantier. Refs #220 (RM-09).