Skip to content

avoid NaN in the hole sorting comparator#134

Merged
mourner merged 1 commit into
mapbox:masterfrom
skeptopic:fix-hole-sort-nan
Jul 7, 2026
Merged

avoid NaN in the hole sorting comparator#134
mourner merged 1 commit into
mapbox:masterfrom
skeptopic:fix-hole-sort-nan

Conversation

@skeptopic

Copy link
Copy Markdown
Contributor

The slope tiebreak divides by the edge's dx, so a zero-length edge (coincident points that filterPoints has not yet removed) yields NaN.

In JS-world, Array#sort handles that , but for std::sort a comparator returning inconsistent results is undefined behavior (it must be a strict weak ordering; MSVC debug asserts on it, libc++ can crash).

Compare the slopes by cross-multiplication instead, which is exact for the same reason the division was (both dx are non-negative for leftmost points), and order zero-length edges first so the ordering stays strict.

JS Array#Sort doesn't bomb on NaN, but std::sort does
@skeptopic skeptopic requested a review from a team as a code owner July 6, 2026 20:06
@mourner mourner merged commit c0c5ecb into mapbox:master Jul 7, 2026
9 checks passed
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.

2 participants