polygon.clip
Implementation of the Greiner-Kai "efficient clipping of arbitrary polygons" paper
install
npm install 2d-polygon-boolean
use
signature
var polygons = polygonBoolean(array1, array2, mode)
Where mode is the string and
(intersect), or
(union), not
(cut)
polygons
is an array of arrays of arrays
e.g
0 0 0 1 1 1
example
var polygonBoolean = ; var subject = 0 0 100 0 100 100 0 100; var clip = 90 90 110 90 110 110 90 110 90 90; var union = ;console; /*union results [ [ [ 100, 90 ], [ 100, 0 ], [ 0, 0 ], [ 0, 100 ], [ 90, 100 ], [ 90, 110 ], [ 110, 110 ], [ 110, 90 ] ] ]*/ var cut = ;console; /*cut results [ [ [ 100, 90 ], [ 100, 0 ], [ 0, 0 ], [ 0, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]*/ var intersect = ;console; /*intersect results [ [ [ 100, 90 ], [ 100, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]*/