{
  "id": 16026617,
  "title": "Faster than earcut: triangulating 3.7M map polygons in 489 ms",
  "url": "https://urgent.news/2026/10/22/faster-than-earcut-triangulating-3-7m-map-polygons-in-489-ms",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-22T09:31:18.000Z",
  "source": {
    "name": "Hacker News",
    "slug": "hacker-news",
    "url": "https://globus.software/blog/2026/10/16/cutting-map-polygons/"
  },
  "original_language": "en",
  "account": "Polygon triangulation plays a crucial role in rendering maps accurately. Our map engine's polygon triangulator, released as a small C++ library called earstrip under the ISC license, can outperform the popular earcut library. While earcut takes approximately 489 milliseconds to triangulate 3.7 million polygons, earstrip excels by delivering speeds ranging from 1.4 to 2.1 times faster in the browser compared to its counterpart.\n\nThe process begins by breaking down polygons into triangles, which are filled during the rendering process. For instance, the Śródmieście district of Warsaw features 331 polygons with 5,151 vertices, transforming into 4,514 triangles upon triangulation. Zooming in on map data of the Masovian Voivodeship, an area encompassing Warsaw, reveals 3,740,425 polygons requiring triangulation.\n\nThe core of the triangulation algorithm involves inserting vertices one at a time. Each new point is then placed within a suitable triangle, which is subsequently split and edges rewritten to align with the circle rule. This step ensures that no point resides inside the circle formed by any triangle's vertices. Moreover, the algorithm must respect the polygon's edges set by the constrained Delaunay triangulator, which maintains the polygon's outline during the triangulation process.\n\nNotably, well-shaped triangles are vital for achieving accurate interpolations and simulations. In our case, a significant portion—1.8 million polygons—consist of four or fewer vertices. Triangulating these polygons requires minimal effort, while the algorithm dedicates considerable time to more complex polygons. Half of the polygons in the Masovian region have four vertices or fewer, yet the Delaunay triangulation code expends 419 milliseconds on them, building each triangulation independently.\n\nTo handle polygons with holes, ear clipping requires creating bridges—edges connecting hole vertices to boundary vertices—thus enabling the polygon to remain a single ring. The bridging process involves casting a ray from the rightmost hole vertex to the right and identifying the first edge it collides with. If no boundary vertex lies within the resulting triangle, the bridge is deemed safe. In some instances, such as when a hole's tip resides within a triangle, a different bridge must be formed, connecting the hole to a different vertex.\n\nIn conclusion, our polygon triangulator, earstrip, demonstrates significant performance improvements over alternative libraries when processing a large number of polygons. By focusing on well-shaped triangles and strategically handling polygons with holes, earstrip efficiently triangulates maps for accurate rendering and interpolation purposes.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}