{"name":"earcut","version":"3.0.0","description":"The fastest and smallest JavaScript polygon triangulation library for your WebGL apps","main":"src/earcut.js","type":"module","exports":"./src/earcut.js","scripts":{"pretest":"eslint src test/test.js bench/*.js viz/viz.js","test":"node --test","build":"rollup -c","prepublishOnly":"npm run build","cov":"node --test --experimental-test-coverage"},"author":{"name":"Vladimir Agafonkin"},"license":"ISC","devDependencies":{"@rollup/plugin-terser":"^0.4.4","benchmark":"^2.1.4","coveralls":"^3.1.1","eslint":"^9.5.0","eslint-config-mourner":"^4.0.1","rollup":"^4.18.0","uglify-js":"^3.18.0","watchify":"^4.0.0"},"eslintConfig":{"extends":"mourner","parserOptions":{"sourceType":"module","ecmaVersion":2020}},"repository":{"type":"git","url":"git://github.com/mapbox/earcut.git"},"_id":"earcut@3.0.0","gitHead":"b59a043360376ef1e40a58fceb42f07662501e5e","bugs":{"url":"https://github.com/mapbox/earcut/issues"},"homepage":"https://github.com/mapbox/earcut#readme","_nodeVersion":"20.14.0","_npmVersion":"10.8.0","dist":{"integrity":"sha512-41Fs7Q/PLq1SDbqjsgcY7GA42T0jvaCNGXgGtsNdvg+Yv8eIu06bxv4/PoREkZ9nMDNwnUSG9OFB9+yv8eKhDg==","shasum":"a8d5bf891224eaea8287201b5e787c6c0318af89","tarball":"http://registry-npm.ywwl.com/earcut/download/earcut-3.0.0.tgz","fileCount":6,"unpackedSize":55902,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE6HE8JaI3ekJgVL9xSa5Ra3/9gfY8qdVOBGD28jnlf6AiEAjxnvO7KHP+LVlBbL4dCMW0oy2P7UVuJOTNGYbtL+pZc="}],"size":12576,"noattachment":false,"key":"/earcut/-/earcut-3.0.0.tgz"},"_npmUser":{"name":"mourner","email":"agafonkin@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/earcut_3.0.0_1719565226739_0.41042117075811424"},"_hasShrinkwrap":false,"readme":"## Earcut\n\nThe fastest and smallest JavaScript polygon triangulation library. 3KB gzipped.\n\n[![Node](https://github.com/mapbox/earcut/actions/workflows/node.yml/badge.svg)](https://github.com/mapbox/earcut/actions/workflows/node.yml)\n[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/mapbox/earcut.svg)](http://isitmaintained.com/project/mapbox/earcut \"Average time to resolve an issue\")\n[![Percentage of issues still open](http://isitmaintained.com/badge/open/mapbox/earcut.svg)](http://isitmaintained.com/project/mapbox/earcut \"Percentage of issues still open\")\n[![](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)\n\n#### The algorithm\n\nThe library implements a modified ear slicing algorithm,\noptimized by [z-order curve](http://en.wikipedia.org/wiki/Z-order_curve) hashing\nand extended to handle holes, twisted polygons, degeneracies and self-intersections\nin a way that doesn't _guarantee_ correctness of triangulation,\nbut attempts to always produce acceptable results for practical data.\n\nIt's based on ideas from\n[FIST: Fast Industrial-Strength Triangulation of Polygons](http://www.cosy.sbg.ac.at/~held/projects/triang/triang.html) by Martin Held\nand [Triangulation by Ear Clipping](http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf) by David Eberly.\n\n#### Why another triangulation library?\n\nThe aim of this project is to create a JS triangulation library\nthat is **fast enough for real-time triangulation in the browser**,\nsacrificing triangulation quality for raw speed and simplicity,\nwhile being robust enough to handle most practical datasets without crashing or producing garbage.\nSome benchmarks using Node 0.12:\n\n(ops/sec)         | pts  | earcut    | libtess  | poly2tri | pnltri    | polyk\n------------------| ---- | --------- | -------- | -------- | --------- | ------\nOSM building      | 15   | _795,935_ | _50,640_ | _61,501_ | _122,966_ | _175,570_\ndude shape        | 94   | _35,658_  | _10,339_ | _8,784_  | _11,172_  | _13,557_\nholed dude shape  | 104  | _28,319_  | _8,883_  | _7,494_  | _2,130_   | n/a\ncomplex OSM water | 2523 | _543_     | _77.54_  | failure  | failure   | n/a\nhuge OSM water    | 5667 | _95_      | _29.30_  | failure  | failure   | n/a\n\nThe original use case it was created for is [Mapbox GL](https://www.mapbox.com/mapbox-gl), WebGL-based interactive maps.\n\nIf you want to get correct triangulation even on very bad data with lots of self-intersections\nand earcut is not precise enough, take a look at [libtess.js](https://github.com/brendankenny/libtess.js).\n\n#### Usage\n\n```js\nconst triangles = earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]\n```\n\nSignature: `earcut(vertices[, holes, dimensions = 2])`.\n\n* `vertices` is a flat array of vertex coordinates like `[x0,y0, x1,y1, x2,y2, ...]`.\n* `holes` is an array of hole _indices_ if any\n  (e.g. `[5, 8]` for a 12-vertex input would mean one hole with vertices 5&ndash;7 and another with 8&ndash;11).\n* `dimensions` is the number of coordinates per vertex in the input array (`2` by default). Only two are used for triangulation (`x` and `y`), and the rest are ignored.\n\nEach group of three vertex indices in the resulting array forms a triangle.\n\n```js\n// triangulating a polygon with a hole\nearcut([0,0, 100,0, 100,100, 0,100,  20,20, 80,20, 80,80, 20,80], [4]);\n// [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2]\n\n// triangulating a polygon with 3d coords\nearcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3);\n// [1,0,3, 3,2,1]\n```\n\nIf you pass a single vertex as a hole, Earcut treats it as a Steiner point.\n\nNote that Earcut is a **2D** triangulation algorithm, and handles 3D data as if it was projected onto the XY plane (with Z component ignored).\n\nIf your input is a multi-dimensional array (e.g. [GeoJSON Polygon](http://geojson.org/geojson-spec.html#polygon)),\nyou can convert it to the format expected by Earcut with `earcut.flatten`:\n\n```js\nconst data = earcut.flatten(geojson.geometry.coordinates);\nconst triangles = earcut(data.vertices, data.holes, data.dimensions);\n```\n\nAfter getting a triangulation, you can verify its correctness with `earcut.deviation`:\n\n```js\nconst deviation = earcut.deviation(vertices, holes, dimensions, triangles);\n```\n\nReturns the relative difference between the total area of triangles and the area of the input polygon.\n`0` means the triangulation is fully correct.\n\n#### Install\n\nInstall with NPM: `npm install earcut`, then import as a module:\n\n```js\nimport earcut from 'earcut';\n```\n\nOr use as a module directly in the browser with [jsDelivr](https://www.jsdelivr.com/esm):\n\n```html\n<script type=\"module\">\n    import earcut from 'https://cdn.jsdelivr.net/npm/earcut/+esm';\n</script>\n```\n\nAlternatively, there's a UMD browser bundle with an `earcut` global variable (exposing the main function as `earcut.default`):\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/earcut/dist/earcut.min.js\"></script>\n```\n\n![](https://cloud.githubusercontent.com/assets/25395/5778431/e8ec0c10-9da3-11e4-8d4e-a2ced6a7d2b7.png)\n\n#### Ports to other languages\n\n- [mapbox/earcut.hpp](https://github.com/mapbox/earcut.hpp) (C++11)\n- [JaffaKetchup/dart_earcut](https://github.com/JaffaKetchup/dart_earcut) (Dart)\n- [earcut4j/earcut4j](https://github.com/earcut4j/earcut4j) (Java)\n- [the3deers/earcut-java](https://github.com/the3deers/earcut-java) (Java)\n- [Larpon/earcut](https://github.com/Larpon/earcut) (V)\n- [Cawfree/earcut-j](https://github.com/Cawfree/earcut-j) (Java, outdated)\n","publish_time":1719565226892,"maintainers":[{"name":"mbx-npm-ci-production","email":"yannick.meeus+npm+production+ci@mapbox.com"},{"name":"mbx-npm-ci-staging","email":"yannick.meeus+npm+staging+ci@mapbox.com"},{"name":"mbx-npm-advanced-actions-production","email":"yannick.meeus+npm+prod+advanced+actions@mapbox.com"},{"name":"mbx-npm-advanced-actions-staging","email":"yannick.meeus+npm+staging+advanced+actions@mapbox.com"},{"name":"mbx-npm-09-production","email":"yannick.meeus+npm+prod+09@mapbox.com"},{"name":"mbx-npm-08-production","email":"yannick.meeus+npm+prod+08@mapbox.com"},{"name":"mbx-npm-07-production","email":"yannick.meeus+npm+prod+07@mapbox.com"},{"name":"mbx-npm-06-production","email":"yannick.meeus+npm+prod+06@mapbox.com"},{"name":"mbx-npm-05-production","email":"yannick.meeus+npm+prod+05@mapbox.com"},{"name":"mbx-npm-04-production","email":"yannick.meeus+npm+prod+04@mapbox.com"},{"name":"mbx-npm-03-production","email":"yannick.meeus+npm+prod+03@mapbox.com"},{"name":"mbx-npm-02-production","email":"yannick.meeus+npm+prod+02@mapbox.com"},{"name":"mbx-npm-01-production","email":"yannick.meeus+npm+prod+01@mapbox.com"},{"name":"mbx-npm-02-staging","email":"yannick.meeus@mapbox.com"},{"name":"mapbox-npm-01","email":"accounts+npmjs-01@mapbox.com"},{"name":"mapbox-npm-02","email":"accounts+npmjs-02@mapbox.com"},{"name":"mapbox-npm-07","email":"accounts+npmjs-07@mapbox.com"},{"name":"mapbox-npm-03","email":"accounts+npmjs-03@mapbox.com"},{"name":"mapbox-npm-04","email":"accounts+npmjs-04@mapbox.com"},{"name":"mapbox-npm-09","email":"accounts+npmjs-09@mapbox.com"},{"name":"mapbox-npm-05","email":"accounts+npmjs-05@mapbox.com"},{"name":"mapbox-npm-06","email":"accounts+npmjs-06@mapbox.com"},{"name":"mapbox-npm-08","email":"accounts+npmjs-08@mapbox.com"},{"name":"mapbox-npm-advanced-actions","email":"accounts+npmjs-advanced-actions@mapbox.com"},{"name":"mapbox-npm-ci","email":"accounts+npmjs-npm-ci@mapbox.com"},{"name":"mapbox-npm","email":"accounts+npmjs@mapbox.com"},{"name":"mapbox-admin","email":"accounts@mapbox.com"},{"name":"mapbox-machine-user","email":"accounts+npm-mapbox-machine-user@mapbox.com"},{"name":"mourner","email":"agafonkin@gmail.com"}],"_cnpm_publish_time":1719565226892,"dist-tags":{"latest":"3.2.4"}}