Fix Unit/Vector slerp endpoints for antiparallel inputs - #1614
Open
gaoflow wants to merge 1 commit into
Open
Conversation
The infallible Unit::slerp fell back to returning self for every t when self and rhs are antiparallel, so slerp(a, b, 1.0) gave -b instead of b, breaking the documented endpoint contract (dimforge#657). Vector::slerp inherited this. Handle the degenerate branch by rotating through a deterministic axis orthogonal to self, keeping the endpoints exact and the path continuous; the interior geodesic is arbitrary since it is genuinely ambiguous there. Also make try_slerp return None (instead of Some(NaN)) when rounding pushes the dot product just past -1.
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.
The infallible
Unit::slerpfell back to returningselffor everytwhenselfandrhsare antiparallel, soslerp(a, b, 1.0)returned-binstead ofb, breaking its own doctest contractslerp(a, b, 1) == b.Vector::slerpinherited it. This is #657, and the spot of the old// TODO: … wrong when self and rhs are collinear with opposite direction.Antiparallel is genuinely ambiguous (any great circle is valid), so only the endpoints are contractual. The degenerate branch now rotates through a deterministic axis orthogonal to
self, making both endpoints exact and the path continuous; the interior geodesic is arbitrary-but-fixed.Related:
try_slerpreturnedSome(NaN)when rounding pushedself.dot(rhs)just past-1(e.g. someVector4inputs), becauseacos/sqrtwent out of domain — it now returnsNone, mirroring the existing parallel guard above it.UnitQuaternion/Rotation3::slerp(documented to panic at 180°) andUnitComplex/Rotation2::slerp(angle-based, already correct) have different contracts and are left as-is.Tested with 6 new
core::interpolationcases (2D/3D/4D antiparallel endpoints, unit-norm interior + orthogonal midpoint, generic control,Vector::slerpwrapper); the full feature-setcargo testsuite is otherwise green (the one unrelatedstack!trybuild UI failure is pre-existing toolchain drift, red on a clean checkout too).