New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

2d-polygon-boolean

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2d-polygon-boolean

perform boolean operations on arbitrary polygons in 2d


Version published
Weekly downloads
1.4K
increased by3.14%
Maintainers
1
Weekly downloads
 
Created

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 = require('2d-polygon-boolean');

var subject = [
  [0, 0],
  [100, 0],
  [100, 100],
  [0, 100]
];

var clip = [
  [90, 90],
  [110, 90],
  [110, 110],
  [90, 110],
  [90, 90]
];


var union = polygonBoolean(subject, clip, 'or');
console.log('union results', union);

/*
union results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 110 ],
    [ 110, 110 ],
    [ 110, 90 ] ] ]
*/

var cut = polygonBoolean(subject, clip, 'not');
console.log('cut results', cut);

/*
cut results [ [ [ 100, 90 ],
    [ 100, 0 ],
    [ 0, 0 ],
    [ 0, 100 ],
    [ 90, 100 ],
    [ 90, 90 ] ] ]
*/

var intersect = polygonBoolean(subject, clip, 'and');
console.log('intersect results', intersect);

/*
intersect results [ [ [ 100, 90 ], [ 100, 100 ], [ 90, 100 ], [ 90, 90 ] ] ]
*/

license

MIT

FAQs

Package last updated on 05 Jun 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