{"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,"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","publish_time":1649996550373,"_cnpm_publish_time":1649996550373,"dist-tags":{"latest":"0.4.2"}}