Port upstream earcut v3.1.0–v3.2.3 (radix sort, block-bbox index, Delaunay refinement)#23
Merged
Merged
Conversation
Closed
Closed
This was
linked to
issues
Jul 8, 2026
…ndex, Delaunay refine)
Copilot
AI
changed the title
[WIP] Port latest changes from MichaCo/Earcut
Port upstream earcut v3.1.0–v3.2.3 (radix sort, block-bbox index, Delaunay refinement)
Jul 8, 2026
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.
Ports all upstream mapbox/earcut changes from issues #14–#21 to the C#/.NET repository. Covers algorithm performance improvements, a new public Delaunay refinement API, and several correctness fixes.
Core algorithm changes
EarcutLinked: removed the 3-pass recursion system; replaced withfilteredOut/curedflagsFilterPoints: backward-sweep after node removal; setss_filteredOut[ThreadStatic] flagIsEarHashed: simplified from interleaved bidirectional scan to two sequential while loops; area check hoisted to callerIntersects: addedincludeBoundaryparameter;CureLocalIntersectionsnow usesboundary=falsefor stricter crossing testIsValidDiagonal: droppedprev.Icheck; addedzeroLengthguardIntersectsPolygon: bbox short-circuit before segment testsPerformance
IndexCurve— faster for large polygonsFindHoleBridge— reduces O(n) scan to O(n/K) by partitioning segments into fixed-width blocks;RemoveNodemaintains the index viaGrowBlockwhens_indexActiveNew public API —
Earcut.Refine()Lawson-flip Delaunay refinement pass on an existing triangulation. Uses an undirected-edge hash with a generation counter to avoid table clears, and a
1e-13 * s²tolerance inInCircleto prevent infinite flip loops on near-cocircular quads.New fixtures & tests
earcut,self-tangent-1/2/3/4,issue147,water-huge3expected.jsonwith corrected triangle counts/errors across all fixturesBlockIndexCollinearregression testTriangulateWaterHuge3andRefineWaterHuge3benchmarks--refineflag added to the viz appThread safety
All mutable scratch (
sort arrays,block-bbox index,refine hash table) uses[ThreadStatic], matching the JS module-level state model. Node arrays are cleared after use to avoid holding GC references.