A fast and compact JavaScript library for triangulating 2D polygons, optimized for WebGL applications.
Earcut is a JavaScript library for triangulating 2D polygons, converting complex shapes into triangles for rendering in WebGL applications. It solves the problem of efficiently breaking down polygons into triangles, which is essential for GPU-based graphics rendering, by offering a fast and lightweight algorithm optimized for real-time performance in browsers.
WebGL developers, especially those building interactive maps, data visualizations, or 2D/3D graphics applications in the browser that require efficient polygon rendering.
Developers choose Earcut for its exceptional speed and minimal bundle size, making it ideal for performance-critical WebGL apps where real-time triangulation is needed without sacrificing robustness for common polygon data.
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Benchmarks show it outperforms alternatives like libtess.js by orders of magnitude, handling complex polygons at thousands of ops/sec for real-time WebGL applications.
At only 3KB gzipped, it has negligible impact on web application load times and bundle sizes, ideal for performance-critical deployments.
Manages holes, self-intersections, and degeneracies without crashing, producing acceptable results for most real-world datasets as highlighted in the README.
Accepts flat arrays and hole indices, returning triangle indices for easy WebGL buffer use, with utilities like earcut.flatten for GeoJSON conversion.
Sacrifices triangulation quality for speed, so on pathological data with complex self-intersections, results may be incorrect or suboptimal, as admitted in the README.
Ignores Z-coordinates by projecting 3D data onto the XY plane, making it unsuitable for true three-dimensional triangulation needs.
While robust, it may produce garbage on extreme cases, and users must manually verify correctness with earcut.deviation if precision is critical.