{"_id":"poly-decomp-es","_rev":"899845","name":"poly-decomp-es","description":"Convex decomposition for 2D polygons","dist-tags":{"latest":"0.4.2"},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"},{"name":"joergjaeckel","email":"jojaecke@gmail.com"},{"name":"isaacmason","email":"isaac@isaacmason.com"}],"time":{"modified":"2024-07-21T23:42:09.000Z","created":"2022-04-10T14:00:40.570Z","0.4.2":"2023-08-07T11:21:39.328Z","0.4.1":"2022-04-15T04:22:30.373Z","0.4.0":"2022-04-10T14:00:40.570Z"},"users":{},"author":{"name":"Stefan Hedman","email":"schteppe@gmail.com","url":"http://steffe.se"},"repository":{"type":"git","url":"git+https://github.com/pmndrs/poly-decomp-es.git"},"versions":{"0.4.2":{"name":"poly-decomp-es","version":"0.4.2","license":"MIT","description":"Convex decomposition for 2D polygons","homepage":"https://github.com/pmndrs/poly-decomp-es","author":{"name":"Stefan Hedman","email":"schteppe@gmail.com","url":"http://steffe.se"},"contributors":[{"name":"Isaac Mason","email":"isaac@isaacmason.com","url":"https://github.com/isaac-mason"}],"keywords":["convex","decomposition","polygon","2d"],"main":"./dist/poly-decomp-es.cjs.js","module":"./dist/poly-decomp-es.js","react-native":"./dist/poly-decomp-es.js","types":"./dist/poly-decomp-es.d.ts","sideEffects":false,"scripts":{"eslint":"eslint .","eslint-fix":"eslint --fix .","prepare":"husky install","prebuild":"rimraf dist","build":"npm run typegen && rollup -c","prepublishOnly":"npm run build && npm run test","prettier":"prettier --list-different .","prettier-fix":"prettier --write .","typecheck":"tsc --noEmit --emitDeclarationOnly false --strict","typegen":"tsc --outFile dist/poly-decomp-es.d.ts","test":"jest","change":"yarn changeset","bump":"yarn changeset version && yarn install --mode update-lockfile","release":"yarn build && yarn test && changeset publish"},"repository":{"type":"git","url":"git+https://github.com/pmndrs/poly-decomp-es.git"},"bugs":{"url":"https://github.com/pmndrs/poly-decomp-es/issues"},"devDependencies":{"@babel/core":"^7.16.5","@babel/preset-env":"^7.16.5","@babel/preset-typescript":"^7.16.5","@changesets/cli":"^2.22.0","@rollup/plugin-babel":"^6.0.3","@rollup/plugin-json":"^6.0.0","@rollup/plugin-node-resolve":"^15.1.0","@rollup/plugin-replace":"^5.0.2","@types/jest":"^27.0.3","@types/node":"^20.3.0","@typescript-eslint/eslint-plugin":"^5.17.0","@typescript-eslint/parser":"^5.17.0","eslint":"^8.12.0","eslint-config-prettier":"^8.5.0","eslint-plugin-es":"^4.1.0","eslint-plugin-simple-import-sort":"^10.0.0","eslint-plugin-typescript-enum":"^2.1.0","husky":"^8.0.3","jest":"^27.4.5","lint-staged":"^13.2.2","prettier":"^2.5.1","rimraf":"^5.0.1","rollup":"^2.62.0","rollup-plugin-filesize":"^10.0.0","ts-jest":"^27.1.2","ts-node":"^10.4.0","typescript":"^4.5.4"},"lint-staged":{"*.{js,json,jsx,ts,tsx,md,yaml,yml}":"prettier --write"},"gitHead":"23f764641d7b63b215ea191b8b122f4c0d1b8f4f","_id":"poly-decomp-es@0.4.2","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-akjZkaTeyfECMNkMqv0g9gFiU2HjpZ5ubJA/aczw1ILdgWQbv1OPwCi05/9JbY2GnGpjm9k85Jdbd/j/p/lg/g==","shasum":"2b874984e6f1d0efa3a27d0b13bbf18904a58156","tarball":"http://registry-npm.ywwl.com/poly-decomp-es/download/poly-decomp-es-0.4.2.tgz","fileCount":7,"unpackedSize":68853,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCIOv4FQJfX9wgSlbhd8x3k7nYMSOgjAwEFMrsy68lNAwIgECp80PmjfZv6TFxgcUvjYAV5wVARbbol/RWB3G9sKzU="}],"size":25006,"noattachment":false,"key":"/poly-decomp-es/-/poly-decomp-es-0.4.2.tgz"},"_npmUser":{"name":"isaacmason","email":"isaac@isaacmason.com"},"directories":{},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"},{"name":"joergjaeckel","email":"jojaecke@gmail.com"},{"name":"isaacmason","email":"isaac@isaacmason.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/poly-decomp-es_0.4.2_1691407299150_0.07933402894548292"},"_hasShrinkwrap":false,"publish_time":1691407299328,"_cnpm_publish_time":1691407299328},"0.4.1":{"name":"poly-decomp-es","version":"0.4.1","license":"MIT","description":"Convex decomposition for 2D polygons","homepage":"https://github.com/pmndrs/poly-decomp-es","author":{"name":"Stefan Hedman","email":"schteppe@gmail.com","url":"http://steffe.se"},"contributors":[{"name":"Isaac Mason","email":"isaac@isaacmason.com","url":"https://github.com/isaac-mason"}],"keywords":["convex","decomposition","polygon","2d"],"main":"./dist/poly-decomp-es.cjs.js","module":"./dist/poly-decomp-es.js","react-native":"./dist/poly-decomp-es.js","types":"./dist/poly-decomp-es.d.ts","sideEffects":false,"scripts":{"eslint":"eslint .","eslint-fix":"eslint --fix .","prepare":"husky install","prebuild":"rimraf dist","build":"npm run typegen && rollup -c","prepublishOnly":"npm run build && npm run test","prettier":"prettier --list-different .","prettier-fix":"prettier --write .","typecheck":"tsc --noEmit --emitDeclarationOnly false --strict","typegen":"tsc --outFile dist/poly-decomp-es.d.ts","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/pmndrs/poly-decomp-es.git"},"bugs":{"url":"https://github.com/pmndrs/poly-decomp-es/issues"},"devDependencies":{"@babel/core":"^7.16.5","@babel/preset-env":"^7.16.5","@babel/preset-typescript":"^7.16.5","@rollup/plugin-babel":"^5.3.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.1","@rollup/plugin-replace":"^3.0.0","@types/jest":"^27.0.3","@types/node":"^17.0.4","@typescript-eslint/eslint-plugin":"^5.17.0","@typescript-eslint/parser":"^5.17.0","eslint":"^8.12.0","eslint-config-prettier":"^8.5.0","eslint-plugin-es":"^4.1.0","eslint-plugin-simple-import-sort":"^7.0.0","eslint-plugin-typescript-enum":"^2.1.0","husky":"^7.0.4","jest":"^27.4.5","lint-staged":"^12.1.4","prettier":"^2.5.1","rimraf":"^3.0.2","rollup":"^2.62.0","rollup-plugin-filesize":"^9.1.1","ts-jest":"^27.1.2","ts-node":"^10.4.0","typescript":"^4.5.4"},"lint-staged":{"*.{js,json,jsx,ts,tsx,md,yaml,yml}":"prettier --write"},"gitHead":"9348386a655c3c9686309de3bf5fa3a77107288e","_id":"poly-decomp-es@0.4.1","_nodeVersion":"14.18.2","_npmVersion":"6.14.15","dist":{"integrity":"sha512-ClJK/YGQ3A2xCQ1YkxCM5KvHtwplZ9LHHoPlJMJ/+O3EnF7OSq9OcqsOfMilgIjZiFpccBobpb4nnDlEKdg+ig==","shasum":"523e81338ab7e16b2f5648315ddb5a4370e00109","tarball":"http://registry-npm.ywwl.com/poly-decomp-es/download/poly-decomp-es-0.4.1.tgz","fileCount":8,"unpackedSize":69503,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIFeca7+wkCvE2DFC+QSM835AW5TkEuBGTtMoxtdbAM9LAiANIFWTDewXyf4cbdFOqCrEAN0bWgsCz2TqhKrpynQeWg=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiWPMGACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpyjQ/+OnaqC6MfqJK1wivpW171JjnN4kDx5HNsxvgTOb7nBaGk7i64\r\nxSDRRald4JSgstNYyhDjBqDn3OH/zMvyFuBUalPjCd+lYbHYR+uVeURZIefx\r\nBmonR2W3tujgeZPFB7RguTDi3FN1JPEy3L1Io/Wb/UH9Y/UI+tBLdWDIMVa2\r\nlXOg5Gntju82xcz2/03OEzzHIXxC8NesV2N/XA4gWcxk5tjRT3gT9jHPSvjq\r\nDowDk9sQF4psabBMYhUR+r/pUWRbDEElXUSSmuma8Ma/MctLgYixQjwMqnQL\r\n+453+vCi3biCVdNOnG3sDpstWZybTNsqMNEndei/a2LB1MYmeH0Wkc5y0Z6L\r\n2OqTiqCBSayFw4nxPB7F3wHMYQUdohK2682ZeDV27jwtHJezD9vHwBGb2dkw\r\niVVM0bTRvMianOZzwzkV08M+J4fe4WxgFpf9A9m/PyQ3DLlSWCzmEOk4Ch/N\r\nN+bf5kyGqtqKzApH9Kw/imqGELPjyiNrOfXvVivEEU8NammG5XCNGbAXw0tR\r\nkLhQ1xIKh4vHvLkyRnEuXWj0SF1H1xH0Ya6ZVSYU3sMbY/QkgoFAUTbtC+HU\r\n+7I/yOq6SxdwPAdDTP58m6K8OJDoj6uBLnu0hjBYSehfgcJnTmTkS/EU92x1\r\n0m5dus8FaY5uJa+pr9xC4OIqBlzF+cWdQPc=\r\n=Caan\r\n-----END PGP SIGNATURE-----\r\n","size":25389,"noattachment":false,"key":"/poly-decomp-es/-/poly-decomp-es-0.4.1.tgz"},"_npmUser":{"name":"isaacmason","email":"isaac@isaacmason.com"},"directories":{},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"},{"name":"joergjaeckel","email":"jojaecke@gmail.com"},{"name":"isaacmason","email":"isaac@isaacmason.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/poly-decomp-es_0.4.1_1649996550220_0.8884002715400909"},"_hasShrinkwrap":false,"publish_time":1649996550373,"_cnpm_publish_time":1649996550373},"0.4.0":{"name":"poly-decomp-es","version":"0.4.0","license":"MIT","description":"Convex decomposition for 2D polygons","homepage":"https://github.com/pmndrs/poly-decomp-es","author":{"name":"Stefan Hedman","email":"schteppe@gmail.com","url":"http://steffe.se"},"contributors":[{"name":"Isaac Mason","email":"isaac@isaacmason.com","url":"https://github.com/isaac-mason"}],"keywords":["convex","decomposition","polygon","2d"],"main":"./dist/poly-decomp-es.cjs.js","module":"./dist/poly-decomp-es.js","react-native":"./dist/poly-decomp-es.js","types":"./dist/poly-decomp-es.d.ts","sideEffects":false,"scripts":{"eslint":"eslint .","eslint-fix":"eslint --fix .","prepare":"husky install","prebuild":"rimraf dist","build":"npm run typegen && rollup -c","prepublishOnly":"npm run build && npm run test","prettier":"prettier --list-different .","prettier-fix":"prettier --write .","typecheck":"tsc --noEmit --emitDeclarationOnly false --strict","typegen":"tsc --outFile dist/poly-decomp-es.d.ts","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/pmndrs/poly-decomp-es.git"},"bugs":{"url":"https://github.com/pmndrs/poly-decomp-es/issues"},"devDependencies":{"@babel/core":"^7.16.5","@babel/preset-env":"^7.16.5","@babel/preset-typescript":"^7.16.5","@rollup/plugin-babel":"^5.3.0","@rollup/plugin-json":"^4.1.0","@rollup/plugin-node-resolve":"^13.1.1","@rollup/plugin-replace":"^3.0.0","@types/jest":"^27.0.3","@types/node":"^17.0.4","@typescript-eslint/eslint-plugin":"^5.17.0","@typescript-eslint/parser":"^5.17.0","eslint":"^8.12.0","eslint-config-prettier":"^8.5.0","eslint-plugin-es":"^4.1.0","eslint-plugin-simple-import-sort":"^7.0.0","eslint-plugin-typescript-enum":"^2.1.0","husky":"^7.0.4","jest":"^27.4.5","lint-staged":"^12.1.4","prettier":"^2.5.1","rimraf":"^3.0.2","rollup":"^2.62.0","rollup-plugin-filesize":"^9.1.1","ts-jest":"^27.1.2","ts-node":"^10.4.0","typescript":"^4.5.4"},"lint-staged":{"*.{js,json,jsx,ts,tsx,md,yaml,yml}":"prettier --write"},"gitHead":"06b6b66f590e79aca6d662bec0c4add7ff538276","_id":"poly-decomp-es@0.4.0","_nodeVersion":"14.18.2","_npmVersion":"6.14.15","dist":{"integrity":"sha512-PTJbxVuAfpCHMk/9z9NICJYYZO25L+G63xyH0WgBDZCiVKFOKrOfnh6FQKUclFHmrMbOMTcAsEll72CmQXQ9Yg==","shasum":"6d5ce84f0a9fb5c59d9f3072609a64a2743788be","tarball":"http://registry-npm.ywwl.com/poly-decomp-es/download/poly-decomp-es-0.4.0.tgz","fileCount":8,"unpackedSize":69599,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGVRYnYfQEFVHVQLYFpkJvTUsUvVPTwSW9SpoX2ChjekAiBpK1O5/78qnhNofrybSvafVh2siDKPc8mC7BtRsPrSoQ=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiUuMIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoGfw//azDkfzVQM+5Hk8WmrVdKSJRbqMHHn1MaBM37g3oS76fLLE3c\r\nHgCGbuKpcG8Eguo//aO4spXM7uyCphSf1enOmn99yTal7M8/wEGX1p+DkQF6\r\nWLKIiWcbokuaEPQ1lRvjGIa8pqoLiQdgT0oC3b1TgYjeZOmMrrS7VNNTPHFH\r\n4PY7qh9o5BPNWLAlW2uFmy65tS0sN2jm27BCjhOh7mYrigsjHeP+wxv+RqC6\r\nU4ZqwxABewmfZ+4x0whIG+C2ekDnwa74bt3teNscT62CSCZlXE+/VFMSVIyn\r\n+zeyoOOJT8VVXZ9jdgKW6yx348dRS+VOd9mX2rinO2zGwbvps7sWKkzL8v6w\r\nM3JUwH3ijZGt+qSnozrHcz1EVi9fWyB6f+mLn1ionZzPcP/idWW2l2LpxDc3\r\n1zN57o0TyfuvQLtynn1xRv0NqtdL5Y/N4+DQQAi/zQ/V/77HT468FnzjNbs5\r\nWabnV3DhfQlMaBKsnVXsiJelmiJdqZZ71zwG/Zd+jz0IwhDupA0t3Zf4CewV\r\nmG+zpnIPFtSoHJ3gG9mooQtZrUv5MBJ9Wbc1es4f22HGnGZP1DXeSKpNswu2\r\nKFj2yLFmX1Lat/0on4NTkfnmS0t1tbTDmQ1J0h7ocSJDJSBPAG9Lfq4yc5OR\r\n4rGGyW2a4sXGOVCLeUTjzdk9Z67WB2F57Dc=\r\n=Grh5\r\n-----END PGP SIGNATURE-----\r\n","size":25391,"noattachment":false,"key":"/poly-decomp-es/-/poly-decomp-es-0.4.0.tgz"},"_npmUser":{"name":"isaacmason","email":"isaac@isaacmason.com"},"directories":{},"maintainers":[{"name":"isaacmason","email":"isaac@isaacmason.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/poly-decomp-es_0.4.0_1649599240364_0.08038635942350636"},"_hasShrinkwrap":false,"publish_time":1649599240570,"_cnpm_publish_time":1649599240570}},"readme":"# poly-decomp-es\n\nThis is a maintained fork of poly-decomp.js, originally created by Stefan Hedman @schteppe.\n\n`poly-decomp-es` is a library for decomposing a 2D polygon into convex pieces.\n\n```\nyarn add poly-decomp-es\n```\n\n![Decomposing a convcave polygon into convex regions](./readme.gif)\n\n[**Launch the demo!**](https://poly-decomp-es.vercel.app/)\n\nThe library implements two algorithms, one optimal (but slow) and one less optimal (but fast).\n\nIt's is a manual port of the C++ library [Poly Decomp](https://mpen.ca/406/bayazit) by [Mark Penner](https://mpen.ca).\n\n### Basic usage\n\n```js\nimport { decomp, makeCCW, quickDecomp } from 'poly-decomp-es'\n\n// Create a concave polygon\nconst concavePolygon = [\n  [-1, 1],\n  [-1, 0],\n  [1, 0],\n  [1, 1],\n  [0.5, 0.5],\n]\n\n// Make sure the polygon has counter-clockwise winding. Skip this step if you know it's already counter-clockwise.\nmakeCCW(concavePolygon)\n\n// Decompose into convex polygons, using the faster algorithm\nconst convexPolygons = quickDecomp(concavePolygon)\n\n// ==> [  [[1,0],[1,1],[0.5,0.5]],  [[0.5,0.5],[-1,1],[-1,0],[1,0]]  ]\n\n// Decompose using the slow (but optimal) algorithm\nconst optimalConvexPolygons = decomp(concavePolygon)\n\n// ==> [  [[-1,1],[-1,0],[1,0],[0.5,0.5]],  [[1,0],[1,1],[0.5,0.5]]  ]\n```\n\n### Advanced usage\n\n```js\nimport { isSimple, makeCCW, quickDecomp } from 'poly-decomp-es'\n\n// Get user input as an array of points.\nconst polygon = getUserInput()\n\n// Check if the polygon self-intersects\nif (isSimple(polygon)) {\n  // Reverse the polygon to make sure it uses counter-clockwise winding\n  makeCCW(polygon)\n\n  // Decompose into convex pieces\n  const convexPolygons = quickDecomp(polygon)\n\n  // Draw each point on an HTML5 Canvas context\n  for (let i = 0; i < convexPolygons.length; i++) {\n    const convexPolygon = convexPolygons[i]\n\n    ctx.beginPath()\n    const firstPoint = convexPolygon[0]\n    ctx.moveTo(firstPoint[0], firstPoint[1])\n\n    for (let j = 1; j < convexPolygon.length; j++) {\n      const point = convexPolygon[j]\n      const x = point[0]\n      const y = point[1]\n      c.lineTo(x, y)\n    }\n    ctx.closePath()\n    ctx.fill()\n  }\n}\n```\n\n### Documentation\n\n#### type Point = [number, number]\n\n#### type Polygon = Point[]\n\n#### quickDecomp(polygon: Polygon): Polygon[]\n\n```js\nimport { quickDecomp } from 'poly-decomp-es'\n\nconst convexPolygons = quickDecomp(polygon)\n```\n\nSlices the polygon into convex sub-polygons, using a fast algorithm. Note that the input points objects will be re-used in the result array.\n\nIf the polygon is not simple, the decomposition will produce unexpected results.\n\n#### decomp(polygon: Polygon): Polygon[] | false\n\n```js\nimport { decomp } from 'poly-decomp-es'\n\nconst convexPolygons = decomp(polygon)\n```\n\nDecomposes the polygon into one or more convex sub-polygons using an optimal algorithm. Note that the input points objects will be re-used in the result array.\n\nReturns false if the decomposition fails.\n\n#### isSimple(polygon: Polygon): boolean\n\n```js\nimport { isSimple, quickDecomp } from 'poly-decomp-es'\n\nif (isSimple(polygon)) {\n  // Polygon does not self-intersect - it's safe to decompose.\n  const convexPolygons = quickDecomp(polygon)\n}\n```\n\nReturns true if the polygon does not self-intersect. Use this to check if the input polygon is OK to decompose.\n\n#### makeCCW(polygon: Polygon): void\n\n```js\nimport { makeCCW } from 'poly-decomp-es'\n\nconsole.log('Polygon with clockwise winding:', polygon)\nmakeCCW(polygon)\nconsole.log('Polygon with counter-clockwise winding:', polygon)\n```\n\nReverses the polygon, if its vertices are not ordered counter-clockwise. Note that the input polygon array will be modified in place.\n\n#### removeCollinearPoints(polygon: Polygon, thresholdAngle = 0): void\n\n```js\nimport { removeCollinearPoints } from 'poly-decomp-es'\n\nconst before = polygon.length\nremoveCollinearPoints(polygon, 0.1)\nconst numRemoved = before - polygon.length\nconsole.log(numRemoved + ' collinear points could be removed')\n```\n\nRemoves collinear points in the polygon. This means that if three points are placed along the same line, the middle one will be removed. The `thresholdAngle` is measured in radians and determines whether the points are collinear or not. Note that the input array will be modified in place.\n\n#### removeDuplicatePoints(polygon: Polygon, precision = 0): void\n\n```js\nimport { removeDuplicatePoints } from 'poly-decomp-es'\n\nconst polygon = [\n  [0, 0],\n  [1, 1],\n  [2, 2],\n  [0, 0],\n]\nremoveDuplicatePoints(polygon, 0.01)\n\n// polygon is now [[1,1],[2,2],[0,0]]\n```\n","_attachments":{},"homepage":"https://github.com/pmndrs/poly-decomp-es","bugs":{"url":"https://github.com/pmndrs/poly-decomp-es/issues"},"license":"MIT"}