csg2d.js
A 2D port from CSG 3D library
largely inspired by https://github.com/evanw/csg.js
Usage
var subjectPolygon = CSG;var clipPolygon = CSG;// note: this syntax is also accepted// var clipPolygon = CSG.fromPolygons([[{x:10, y:100}, {x:50, y:10}, {x:100, y:100}]]); var subtractPolygons = subjectPolygon;var unionPolygons = subjectPolygon;var intersectPolygons = subjectPolygon; /*return [ [ {x:x1, y:y1} , ... , {x:xN, y:yN} ], //polygon #1 ... [ {x:x1, y:y1} , ... , {x:xN, y:yN} ], //polygon #K]*/
Example
http://come.github.io/csg2d.js/