{"id":13425950,"url":"https://github.com/mfogel/polygon-clipping","last_synced_at":"2025-05-15T04:04:42.293Z","repository":{"id":39332671,"uuid":"119088086","full_name":"mfogel/polygon-clipping","owner":"mfogel","description":"Apply boolean polygon clipping operations (union, intersection, difference, xor) to your Polygons \u0026 MultiPolygons.","archived":false,"fork":false,"pushed_at":"2024-04-19T03:31:53.000Z","size":12896,"stargazers_count":582,"open_issues_count":44,"forks_count":63,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-05-15T00:27:29.494Z","etag":null,"topics":["boolean-operations","difference","intersection","polygon","polygon-clipping","union","xor"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mfogel.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-01-26T18:28:46.000Z","updated_at":"2025-05-05T07:50:43.000Z","dependencies_parsed_at":"2024-04-21T11:39:42.616Z","dependency_job_id":null,"html_url":"https://github.com/mfogel/polygon-clipping","commit_stats":{"total_commits":478,"total_committers":15,"mean_commits":"31.866666666666667","dds":"0.16945606694560666","last_synced_commit":"b95ff723be4acec1d1d25370973a91c2c866bef8"},"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfogel%2Fpolygon-clipping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfogel%2Fpolygon-clipping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfogel%2Fpolygon-clipping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mfogel%2Fpolygon-clipping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mfogel","download_url":"https://codeload.github.com/mfogel/polygon-clipping/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270641,"owners_count":22042858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boolean-operations","difference","intersection","polygon","polygon-clipping","union","xor"],"created_at":"2024-07-31T00:01:22.754Z","updated_at":"2025-05-15T04:04:42.269Z","avatar_url":"https://github.com/mfogel.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# polygon-clipping\n\nApply boolean Polygon clipping operations (`intersection`, `union`, `difference`, `xor`) to your Polygons \u0026 MultiPolygons.\n\n[![CI](https://github.com/mfogel/polygon-clipping/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mfogel/polygon-clipping/actions) [![codecov](https://codecov.io/gh/mfogel/polygon-clipping/branch/main/graph/badge.svg?token=is93inDQiJ)](https://codecov.io/gh/mfogel/polygon-clipping) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) [![npm](https://img.shields.io/npm/v/polygon-clipping.svg)](https://www.npmjs.com/package/polygon-clipping)\n\n## Quickstart\n\n\u003c!-- prettier-ignore-start --\u003e\n```javascript\nconst polygonClipping = require('polygon-clipping')\n\nconst poly1 = [[[0,0],[2,0],[0,2],[0,0]]]\nconst poly2 = [[[-1,0],[1,0],[0,1],[-1,0]]]\n\npolygonClipping.union       (poly1, poly2 /* , poly3, ... */)\npolygonClipping.intersection(poly1, poly2 /* , poly3, ... */)\npolygonClipping.xor         (poly1, poly2 /* , poly3, ... */)\npolygonClipping.difference  (poly1, poly2 /* , poly3, ... */)\n```\n\u003c!-- prettier-ignore-end --\u003e\n\n## API\n\n```javascript\n/* All functions take one or more [multi]polygon(s) as input */\n\npolygonClipping.union       (\u003cgeom\u003e, ...\u003cgeoms\u003e)\npolygonClipping.intersection(\u003cgeom\u003e, ...\u003cgeoms\u003e)\npolygonClipping.xor         (\u003cgeom\u003e, ...\u003cgeoms\u003e)\n\n/* The clipGeoms will be subtracted from the subjectGeom */\npolygonClipping.difference(\u003csubjectGeom\u003e, ...\u003cclipGeoms\u003e)\n```\n\n### Input\n\nEach positional argument (`\u003cgeom\u003e`) may be either a Polygon or a MultiPolygon. The [GeoJSON spec](https://tools.ietf.org/html/rfc7946#section-3.1) is followed, with the following notes/modifications:\n\n- MultiPolygons may contain touching or overlapping Polygons.\n- rings are not required to be self-closing.\n- rings may contain repeated points, which are ignored.\n- rings may be self-touching and/or self-crossing. Self-crossing rings will be interpreted using the [non-zero rule](https://en.wikipedia.org/wiki/Nonzero-rule).\n- winding order of rings does not matter.\n- inner rings may extend outside their outer ring. The portion of inner rings outside their outer ring is dropped.\n- inner rings may touch or overlap each other.\n\n### Output\n\nFor non-empty results, output will always be a MultiPolygon containing one or more non-overlapping, non-edge-sharing Polygons. The [GeoJSON spec](https://tools.ietf.org/html/rfc7946#section-3.1) is followed, with the following notes/modifications:\n\n- outer rings will be wound counter-clockwise, and inner rings clockwise.\n- inner rings will not extend outside their outer ring.\n- rings will not overlap, nor share an edge with each other.\n- rings will be self-closing.\n- rings will not contain repeated points.\n- rings will not contain superfluous points (intermediate points along a straight line).\n- rings will not be self-touching nor self-crossing.\n- rings _may_ touch each other, but _may not_ cross each other.\n\nIn the event that the result of the operation is the empty set, output will be a MultiPolygon with no Polygons: `[]`.\n\n## Correctness\n\nRun: `npm test`\n\nThe tests are broken up into unit tests and end-to-end tests. The end-to-end tests are organized as GeoJSON files, to make them easy to visualize thanks to [GitHub's helpful rendering of GeoJSON files](https://help.github.com/articles/mapping-geojson-files-on-github/). Browse those tests [here](test/end-to-end).\n\n## Performance\n\nThe Martinez-Rueda-Feito polygon clipping algorithm is used to compute the result in `O((n+k)*log(n))` time, where `n` is the total number of edges in all polygons involved and `k` is the number of intersections between edges.\n\n## Settings\n\nGlobal settings are set via environment variables.\n\n- **POLYGON_CLIPPING_MAX_QUEUE_SIZE** and **POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS**: Aims to prevent infinite loops - usually caused by floating-point math round-off errors. Defaults are 1,000,000.\n\n## Changelog\n\nThis project adheres to [Semantic Versioning](https://semver.org/).\n\n\u003c!-- prettier-ignore-end --\u003e\n\nThe full changelog is available at [CHANGELOG.md](https://github.com/mfogel/polygon-clipping/blob/master/CHANGELOG.md).\n\n## Authors\n\n- [Mike Fogel](https://github.com/mfogel)\n- [Alexander Milevski](https://github.com/w8r)\n- [Vladimir Ovsyannikov](https://github.com/sh1ng)\n\n## Sponsors\n\n- [Alantgeo](https://www.alantgeo.com.au/)\n- [EasyTerritory](https://www.easyterritory.com/)\n\nPlease contact [Mike Fogel](https://github.com/mfogel) if you or your company is interested in sponsoring work on specific bug fixes or feature requests.\n\n## Based on\n\n- [A new algorithm for computing Boolean operations on polygons](paper.pdf) by Francisco Martinez, Antonio Jesus Rueda, Francisco Ramon Feito (2009)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfogel%2Fpolygon-clipping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmfogel%2Fpolygon-clipping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmfogel%2Fpolygon-clipping/lists"}