Repository navigation
fix: resolve precision loss and potential NaN in spherical coordinates conversion - #128
Open
vamshidharre wants to merge 1 commit into
Open
vamshidharre wants to merge 1 commit into
vamshidharre wants to merge 1 commit into
Conversation
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.
Summary
In
Coordinate::spherical_coordinates(which powersCoordinate::bearing_from_originandVector::bearing_at_origin), polar and azimuth angles were previously calculated using inverse cosine:Problems:
Because
1.0in double precision, causingacos(1.0)to return0.0(100% loss of azimuth angle!).NaN/ Panic:Due to floating point rounding in
distance_from_origin()orsqrt(x^2 + y^2), ifFloatMath::acosproducesNaN, causingIn::spherical_to_bearingto returnNoneand panic at.expect(...).Solution:
Replace the
acosprojections with standard, numerically stableFloatMath::atan2formulations:NaN.0whenFloatMath::hypotacrossstdand#.Verification:
small_angle_azimuth_precision_preservedtest confirmingsmall_angle_polar_elevation_precision_preservedtest confirming polar deviation resolution nearspherical_coordinates_round_triptesting consistency withfrom_sphericalacross quadrants.#![no_std]+libmverified viacargo check --no-default-features --features libm.cargo fmt -- --check.