https://github.com/mikolalysenko/poly-bool
Exact polygon boolean operations
https://github.com/mikolalysenko/poly-bool
Last synced: 4 months ago
JSON representation
Exact polygon boolean operations
- Host: GitHub
- URL: https://github.com/mikolalysenko/poly-bool
- Owner: mikolalysenko
- License: mit
- Created: 2015-07-01T23:06:46.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-07-01T23:33:25.000Z (over 10 years ago)
- Last Synced: 2025-05-21T01:59:02.092Z (5 months ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 20
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
poly-bool
=========
A robust polygon Boolean library in under 20 lines of code! (Excluding dependencies) Work with *any* kind of polygon, results are accurate to *machine precision*, and under no circumstances will valid input ever crash or produce incorrect output.
# Example
```javascript
var polybool = require('poly-bool')
var a = [[[-1,-1], [-1,1], [1,1], [1,-1]]]
var b = [[[0, 0], [0,2], [2,2], [2,0]]]
console.log(polybool(a, b, 'sub'))
```
#### Output
```javascript
[ [ [ 1, 1 ], [ 1, 0 ], [ 2, 0 ], [ 2, 2 ], [ 0, 2 ], [ 0, 1 ] ] ]
```
# Install
```
npm i poly-bool
```
# API
#### `require('poly-bool')(a, b, op)`
Computes a Boolean set operation between `a` and `b`
* `a,b` are polygons represented by lists of loops of points
* `op` is the operation to apply. Possible values include `'and', 'or', 'xor', 'sub', 'rsub'`
**Returns** A polygon encoding some boolean combination of the components of `a` and `b`
# License
(c) 2015 Mikola Lysenko. MIT License