0.0.3 • Published 10 years ago

polygon.clip v0.0.3

Weekly downloads
3
License
-
Repository
github
Last release
10 years ago

polygon.clip

Implementation of the Greiner-Kai "efficient clipping of arbitrary polygons" paper

install

npm install poygon.clip

use

signature

Polygon#clip(clippingPolygon, mode)

Where mode is 'difference' or 'union'

example

Lets clip two squares

var Polygon = require('polygon.clip'),
    Vec2 = require('vec2');

var subject = Polygon([
  Vec2(0, 0),
  Vec2(100, 0),
  Vec2(100, 100),
  Vec2(0, 100),
  Vec2(0, 0)
]);

var clip = Polygon([
  Vec2(90, 90),
  Vec2(110, 90),
  Vec2(110, 110),
  Vec2(90, 110),
  Vec2(90, 90)
]);


// union is an array of Polygons
var union = subject.clip(clip, 'union');

console.log(JSON.stringify(union[0].points, null, '  '));

In this case, there will only be one polygon in the union array, and it will define the upper corner of the subject polygon

[[100, 90], [100,100], [90, 100], [90,90]]

license

MIT

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

11 years ago