Repository navigation
h3: clamp the haversine term so antipodal distances are not NaN - #178
Merged
Merged
Conversation
For some antipodal pairs rounding pushes the haversine term just above its mathematical maximum of 1, and sqrt(1 - h) is then NaN, so GreatCircleDistanceRads and the kilometre and metre forms returned NaN instead of pi times the radius. Clamping the term at 1 affects only that overshoot. This is upstream uber/h3#1267. The conformance suite is unaffected: its distance sampler already redraws far targets within 1e-3 radians of antipodal, where the haversine is ill-conditioned. The test helper assertRelClose compared with >, and every comparison against NaN is false, so a NaN result passed; it now rejects NaN, and the new antipodal case fails without the clamp. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Coverage Report for CI Build 40544249803Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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
GreatCircleDistanceRads,GreatCircleDistanceKmandGreatCircleDistanceMreturned NaN for some antipodal pairs. Rounding pushes the haversine term just above its mathematical maximum of 1, andsqrt(1 - h)is then NaN. For example (10.123456789, 20.987654321) against its antipode. The fix clamps the term at 1, which affects only that overshoot. This is upstream uber/h3#1267.The conformance suite is unaffected: its distance sampler already redraws far targets within 1e-3 radians of antipodal, where the haversine is ill-conditioned, so no patch or regeneration is needed.
The test helper
assertRelClosecompared with>, and every comparison against NaN is false, so a NaN result passed it. It now rejects NaN explicitly. The newantipodalcase inTestGreatCircleDistancefails without the clamp and passes with it.Test plan
TestGreatCircleDistance/antipodalfails with the clamp removed (rads = NaN) and passes with itgo test -race ./...green, root and conformancegolangci-lint run ./...clean