Conversation
…an#286) `RigidBody::state_derivative` answers a state whose four orientation numbers normalize to nothing with an all-zero derivative, and an integrator reads that as a body at rest — so the run quietly freezes in place and keeps going rather than stopping. A state this broken is not a case to paper over. `try_state_derivative` is the checked twin: the same arithmetic, with the reason coming back as `DynamicsError::DegenerateOrientation`. The infallible call keeps its signature and its zeros, now delegating to the checked one, and both its doc and the loop example spell out what a degenerate state does there and point at the checked twin — the note sits in the example a caller copies, not only in the prose above it. The suite pins the error on exact zeros and on a subnormal whose squared norm underflows to nothing, pins the infallible zeros for the same state, and asserts the two variants agree element-wise on five valid states, including one whose orientation numbers have drifted off unit length.
This branch has not been deployed
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.
Closes #286.
RigidBody::state_derivativeanswers a state whose four orientation numbers normalize to nothing with an all-zero derivative, and an integrator reads that as a body at rest — the run quietly freezes in place and keeps going rather than stopping.The API.
DynamicsError::DegenerateOrientation(#[non_exhaustive], so additive), with itsDisplayarm.try_state_derivativecarries the same arithmetic, a# Errorssection, and an example pinning both the valid path and the error.state_derivativekeeps its signature and its zeros, now delegating to the checked one. Its doc and its integrator example say explicitly what a degenerate state does there — the note sits in the loop example a caller copies, not only in the prose above it — and point at the checked twin.Numeric path unchanged by construction: the valid-state computation moved verbatim into the checked variant; the only new branch is the error return. The existing goldens (
a_free_tumble…,stepped_agrees…) pass untouched.Tests (
tests/suite/dynamics/rigid_body.rs, 3 new): the error on exact zeros and on1e-320(a subnormal whose squared norm underflows to nothing, so it normalizes to no direction just the same), the infallible zeros for that same state, and element-wise agreement between the two variants on five valid states — the ones the file already runs, plus one whose orientation numbers have drifted 1.1× off unit length, which both scale back before reading.Evidence. With the error path temporarily stubbed back to
Ok(zeros)the pinning test fails (left: Ok([…0.0…]),right: Err(DegenerateOrientation)) and the doctest fails; restored,cargo test -p multicalc(451 doctests included),--features alloc(540),--all-features --doc(540),cargo clippy -p multicalc --all-targets --features alloc -- -D warnings, andcargo fmt --all --checkare all green.Not done. Demos left untouched:
demos/examples/basics/rigid_body_dynamics.rscallsstate_derivativeinsideRk4closures and makes no claim that a degenerate orientation is impossible; the checked twin is there if they want it.free_joint_from_state_vector's pre-existing "all zero" wording was left alone (out of scope).