fix: normalize vreckon output longitude to [-180, 180] range#108
Open
gaoflow wants to merge 1 commit into
Open
fix: normalize vreckon output longitude to [-180, 180] range#108gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
vreckon() was wrapping lon2 with `% tau`, producing values in [0, 360). This caused wrong results for any starting longitude west of the prime meridian: e.g., lon1=-1.27° yielded lon2=358.74° instead of ~-1.26°. The docstring (added by Joaquim Luis) already stated lon2 should be in [-180, 180]. Fix by changing the normalization to `(lon2 + pi) % tau - pi`, which maps [0, 360) correctly to [-180, 180). Update four test expectations that encoded the old [0, 360) convention, and add a regression test for issue geospace-code#88. Fixes geospace-code#88
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
Fixes #88.
vreckon()wrapped the computed destination longitude withlon2 %= tau, producing values in [0, 360). Any starting longitude west of the prime meridian therefore returned a wrong result — e.g. the example in #88:The comment added by Joaquim Luis already stated: "lon2 is always converted to the [-180 180] interval" — the implementation simply didn't match that intent.
Fix
One-line change in
vincenty.py:Four existing test expectations that encoded the old
[0, 360)behaviour are updated (e.g. west-quadrant output270°→-90°), and a regression test for the exact case in #88 is added.All 396 tests pass (9 skipped for missing optional deps).
Test plan
pytest src/pymap3d/tests/test_vincenty_vreckon.py— 17/17 pass (incl. new regression)pytest src/pymap3d/tests/test_vincenty_dist.py— 16/16 passpytest src/pymap3d/tests/ -q) — 396 passed, 9 skippedThis pull request was prepared with the assistance of AI, under my direction and review.