Fix numerical instability in ECEF to geodetic coordinate conversion#1124
Merged
olemke merged 3 commits intoatmtools:mainfrom May 5, 2026
Merged
Fix numerical instability in ECEF to geodetic coordinate conversion#1124olemke merged 3 commits intoatmtools:mainfrom
olemke merged 3 commits intoatmtools:mainfrom
Conversation
- Add near-pole threshold detection to handle cases where horizontal distance from z-axis is smaller than 1e-15 * semi-major axis - Add maximum iteration limit (100) with error handling to prevent infinite loops in edge cases
riclarsson
reviewed
Apr 30, 2026
riclarsson
reviewed
Apr 30, 2026
Comment on lines
+181
to
+182
| add_test(NAME "cpp.fast.test_path_point" COMMAND test_path_point) | ||
| add_dependencies(check-deps test_path_point) |
Contributor
There was a problem hiding this comment.
You add this again. Was this the reason for the previous failure, then?
Member
Author
There was a problem hiding this comment.
It was consistently failing on Windows (not sure if it errored out or got stuck in the endless loop). Since the fix, I haven't seen any failures reoccurring which leads me to believe this was the culprit.
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.
This PR fixes a numerical instability in the ECEF to geodetic coordinate conversion algorithm. The previous implementation used an exact equality check (
ecef[0] == 0 && ecef[1] == 0) to detect points on the poles, which was both numerically unstable and failed to handle near-pole cases. These near-pole cases could cause the iterative algorithm to enter an endless loop. To safeguard against any other edge cases that might still be overlooked, additional convergence protection was added.Changes
src/core/geodesy/geodetic.cpp:near_pole_threshold_ecefconstant to detect near-pole points using a threshold-based approach instead of exact equalitymax_ecef2geodetic_iterconstant to prevent endless loops in the iterative conversion algorithmsrc/tests/CMakeLists.txt: Reenabled thetest_path_pointtest that was previously disabled (commit c94deff part of Improve format #773)