Socket
Book a DemoInstallSign in
Socket

csg2d

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csg2d

A 2D port of CSG 3D library

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
2
Created
Source

csg2d.js

A 2D port from CSG 3D library

largely inspired by https://github.com/evanw/csg.js

Usage

var subjectPolygon = CSG.fromPolygons([[[10, 10], [100, 10], [50, 140]]]);
var clipPolygon = CSG.fromPolygons([[[10, 100], [50, 10], [100, 100]]]);
// 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.subtract(clipPolygon).toPolygons();
var unionPolygons = subjectPolygon.union(clipPolygon).toPolygons();
var intersectPolygons = subjectPolygon.intersect(clipPolygon).toPolygons();

/*
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/

screenshot

Keywords

csg

FAQs

Package last updated on 27 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts