Skip to content

fix(distance): keep antipodal distances finite - #3185

Open
Doomguy-BFG9000 wants to merge 1 commit into
Turfjs:masterfrom
Doomguy-BFG9000:fix/antipodal-distance
Open

Doomguy-BFG9000 wants to merge 1 commit into
Turfjs:masterfrom
Doomguy-BFG9000:fix/antipodal-distance

Conversation

@Doomguy-BFG9000

Copy link
Copy Markdown

Fixes #3182.

Cap the haversine intermediate at 1 before taking its square-root complement. Floating-point rounding can otherwise make the complement negative for antipodal points, producing NaN in distance and calculations that depend on it.

The new tests cover an antipodal pair and a nearby pair whose shorter arc is below half a circumference. On Windows with Node.js 24, the build, workspace tests, and targeted ESLint and Prettier checks passed. The root pnpm test stopped in Monorepolint with the same Windows file-URL error reproduced on the base source.

This branch has not been deployed

No deployments
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.

@turf/distance returns NaN for some antipodal points

1 participant