Skip to content

Fix NaN and precision loss in spherical point distances - #118

Open
sulaimwn wants to merge 1 commit into
spatial-go:mainfrom
sulaimwn:fix/spherical-point-distance
Open

sulaimwn wants to merge 1 commit into
spatial-go:mainfrom
sulaimwn:fix/spherical-point-distance

Conversation

@sulaimwn

Copy link
Copy Markdown

Fixes #114.

I reproduced the reported NaN with the exact coordinates in the issue. The previous calculation also returned zero for points 1.11 mm apart on the equator and NaN for the reported point and its antipode.

The point-to-point path now returns zero for identical coordinates and computes the central angle with the spherical Vincenty formula using the existing Earth radius. The regression tests cover coincident, nearby, antipodal and nearly antipodal points. The public distance and grid tests now allow floating-point rounding while still checking distances, grid dimensions and every polygon against their expected values.

On Go 1.19.8, go build ./... and go test -count=1 ./... passed. Race-enabled tests also passed for algorithm/measure, grid and planar. As a separate numerical check, I compared 8,006 point pairs against an 85-digit reference calculation. The largest absolute difference was under 8 nanometres.

Prepared and tested with OpenAI Codex.

Compute the central angle using the spherical Vincenty formula. This keeps coincident points at zero and resolves small separations near either end of the distance range.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

measure.SpheroidDistance returns NaN for some data

1 participant