All Projects → mfogel → Polygon Clipping

mfogel / Polygon Clipping

Licence: mit
Apply boolean polygon clipping operations (union, intersection, difference, xor) to your Polygons & MultiPolygons.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Polygon Clipping

Visibility
Simple sweep line visibility polygon algorithm implementation
Stars: ✭ 62 (-68.69%)
Mutual labels:  polygon
Perspectivetransform
Calculate CATransform3D between two Perspectives
Stars: ✭ 113 (-42.93%)
Mutual labels:  polygon
Architectural Floor Plan
AFPlan is an architectural floor plan analysis and recognition system to create extended plans for building services.
Stars: ✭ 165 (-16.67%)
Mutual labels:  polygon
Graphical Debugging
GraphicalDebugging extension for Visual Studio
Stars: ✭ 88 (-55.56%)
Mutual labels:  polygon
Earcut
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Stars: ✭ 1,359 (+586.36%)
Mutual labels:  polygon
Round Anything
A set of OpenSCAD utilities for adding radii and fillets, that embodies a robust approach to developing OpenSCAD parts.
Stars: ✭ 122 (-38.38%)
Mutual labels:  polygon
Phidl
Python GDS layout and CAD geometry creation
Stars: ✭ 56 (-71.72%)
Mutual labels:  polygon
Libtessdotnet
C# port of the famous GLU Tessellator - prebuilt binaries now available in "releases" tab
Stars: ✭ 191 (-3.54%)
Mutual labels:  polygon
Polylidar
Polylidar3D - Fast polygon extraction from 3D Data
Stars: ✭ 106 (-46.46%)
Mutual labels:  polygon
Pyclipper
Cython wrapper for the C++ translation of the Angus Johnson's Clipper library (ver. 6.4.2)
Stars: ✭ 140 (-29.29%)
Mutual labels:  polygon
Plexus
Polygonal mesh processing.
Stars: ✭ 90 (-54.55%)
Mutual labels:  polygon
Shapes
📐 Net standard geometry/shape manipulation library, can be used to merge / split shapes
Stars: ✭ 95 (-52.02%)
Mutual labels:  polygon
Client Python
A python client library for accessing Polygon's APIs
Stars: ✭ 127 (-35.86%)
Mutual labels:  polygon
Polyclip Go
Go library for Boolean operations on 2D polygons.
Stars: ✭ 70 (-64.65%)
Mutual labels:  polygon
Matgeom
Matlab geometry toolbox for 2D/3D geometric computing
Stars: ✭ 168 (-15.15%)
Mutual labels:  polygon
Leaflet Geoman
🍂🗺️ The most powerful leaflet plugin for drawing and editing geometry layers
Stars: ✭ 1,088 (+449.49%)
Mutual labels:  polygon
Mapdrawingtools
this library Drawing polygon, polyline and points in Google Map and return coordinates to your App
Stars: ✭ 122 (-38.38%)
Mutual labels:  polygon
L7
🌎 Large-scale WebGL-powered Geospatial Data Visualization analysis framework which relies on Mapbox GL or AMap to render basemaps.
Stars: ✭ 2,517 (+1171.21%)
Mutual labels:  polygon
Hob3l
100x Faster Slicing of SCAD Files for 3D Printing
Stars: ✭ 182 (-8.08%)
Mutual labels:  polygon
Imgaug
Image augmentation for machine learning experiments.
Stars: ✭ 12,107 (+6014.65%)
Mutual labels:  polygon

polygon-clipping

Apply boolean Polygon clipping operations (intersection, union, difference, xor) to your Polygons & MultiPolygons.

build License: MIT npm

Quickstart

const polygonClipping = require('polygon-clipping')

const poly1 = [[[0,0],[2,0],[0,2],[0,0]]]
const poly2 = [[[-1,0],[1,0],[0,1],[-1,0]]]

polygonClipping.union       (poly1, poly2 /* , poly3, ... */)
polygonClipping.intersection(poly1, poly2 /* , poly3, ... */)
polygonClipping.xor         (poly1, poly2 /* , poly3, ... */)
polygonClipping.difference  (poly1, poly2 /* , poly3, ... */)

API

/* All functions take one or more [multi]polygon(s) as input */

polygonClipping.union       (<geom>, ...<geoms>)
polygonClipping.intersection(<geom>, ...<geoms>)
polygonClipping.xor         (<geom>, ...<geoms>)

/* The clipGeoms will be subtracted from the subjectGeom */
polygonClipping.difference(<subjectGeom>, ...<clipGeoms>)

Input

Each positional argument (<geom>) may be either a Polygon or a MultiPolygon. The GeoJSON spec is followed, with the following notes/modifications:

  • MultiPolygons may contain touching or overlapping Polygons.
  • rings are not required to be self-closing.
  • rings may contain repeated points, which are ignored.
  • rings may be self-touching and/or self-crossing. Self-crossing rings will be interpreted using the non-zero rule.
  • winding order of rings does not matter.
  • inner rings may extend outside their outer ring. The portion of inner rings outside their outer ring is dropped.
  • inner rings may touch or overlap each other.

Output

For non-empty results, output will always be a MultiPolygon containing one or more non-overlapping, non-edge-sharing Polygons. The GeoJSON spec is followed, with the following notes/modifications:

  • outer rings will be wound counter-clockwise, and inner rings clockwise.
  • inner rings will not extend outside their outer ring.
  • rings will not overlap, nor share an edge with each other.
  • rings will be self-closing.
  • rings will not contain repeated points.
  • rings will not contain superfluous points (intermediate points along a straight line).
  • rings will not be self-touching nor self-crossing.
  • rings may touch each other, but may not cross each other.

In the event that the result of the operation is the empty set, output will be a MultiPolygon with no Polygons: [].

Correctness

Run: npm test

The 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. Browse those tests here.

Performance

The 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.

Settings

Global settings are set via environment variables.

  • 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.

Changelog

This project adheres to Semantic Versioning.

The full changelog is available at CHANGELOG.md.

Authors

Sponsors

Please contact Mike Fogel if you or your company is interested in sponsoring work on specific bug fixes or feature requests.

Based on

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].