Repository navigation
Fix distance calculation for nearby and antipodal points - #13749
Open
DestinyOfLove wants to merge 1 commit into
Open
DestinyOfLove wants to merge 1 commit into
DestinyOfLove wants to merge 1 commit into
Conversation
Contributor
|
Hey, @DestinyOfLove 👋 Thanks for your contribution to Mapbox GL JS! Important: This repository does not accept direct merges. All changes go through our internal review process. What happens next:
Please respond to any review comments on this PR. For more details, see CONTRIBUTING.md. |
This branch has not been deployed
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
LngLat.distanceTo()can return zero for distinct nearby coordinates, a positive distance for identical coordinates, orNaNfor antipodal coordinates because the spherical law of cosines loses precision near its domain limits. For example,[5.1, 52.1]to[5.100001, 52.1]currently returns zero instead of approximately 0.06830549 m.Use the Haversine formula described in the existing API documentation, retaining the existing Earth radius. Clamp its intermediate value to avoid floating-point overshoot at antipodal points.
Evidence
npm run test-unit -- test/unit/geo/lng_lat.test.tsnpm run tscnpm run lintMerge Danger
Distances may differ slightly due to floating-point rounding; this fixes larger errors for very short and antipodal distances. No public API changes or dependencies are introduced.
Launch Checklist