RC RANDOM CHAOS

Earstrip: 1.4-2.1x Faster Polygon Triangulation Than Earcut

· via Hacker News

Original source

Faster than earcut: triangulating 3.7M map polygons in 489 ms

Hacker News →

An open-source map rendering library has released earstrip, a polygon triangulation tool that substantially outperforms earcut in both C++ and browser environments. Maps consist primarily of polygons—buildings, parks, parking lots—but GPUs render only triangles, requiring algorithmic conversion. Triangulating 3.7 million polygons from Warsaw’s Masovian region, earstrip completes in milliseconds rather than seconds.

The optimization journey began with constrained Delaunay triangulation taking 2.93 seconds on a single CPU core. The team switched to ear clipping, which identifies and removes convex corners as triangles iteratively. A baseline implementation achieved 1.12 seconds—2.6 times faster than Delaunay. Further refinements reduced the cost of testing whether a corner is a valid “ear,” including an optimization that tests only reflex vertices (concave points), cutting 237 milliseconds from processing time.

Earstrip runs 14% faster than earcut.hpp in C++ and 1.4 to 2.1 times faster than earcut.js in browsers. Published under the ISC license as a single C++ header with WebAssembly support, it maintains API compatibility with earcut. The authors documented each optimization incrementally, providing both a practical tool and a case study in algorithm optimization for geometric computation.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.