JSPM

poly-bool

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44
  • Score
    100M100P100Q67023F
  • License MIT

Exact polygon boolean operations

Package Exports

  • poly-bool

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (poly-bool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

polygon-boolean

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

var polybool = require('polygon-boolean')

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

[ [ [ 1, 1 ], [ 1, 0 ], [ 2, 0 ], [ 2, 2 ], [ 0, 2 ], [ 0, 1 ] ] ]

Install

npm i polygon-boolean

API

require('polygon-boolean')(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