# 2d-polygon-boolean

> perform boolean operations on arbitrary polygons in 2d

Latest version **1.0.1** (published 2015-06-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install 2d-polygon-boolean
pnpm add 2d-polygon-boolean
yarn add 2d-polygon-boolean
bun add 2d-polygon-boolean
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2015-06-05 |
| First published | 2014-12-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 93 |
| Author | Elijah Insua |
| Maintainers | tmpvar |
| Keywords | polygon, geometry, math, 2d, clipping |

## Links

- npm: https://www.npmjs.com/package/2d-polygon-boolean
- Repository: https://github.com/tmpvar/polygon.clip.js
- Issues: https://github.com/tmpvar/polygon.clip.js/issues
- npm.io page: https://npm.io/package/2d-polygon-boolean

## Dependencies (4)

- [segseg](https://npm.io/package/segseg.md) ~0.2.0
- [signum](https://npm.io/package/signum.md) ^1.0.0
- [2d-polygon-area](https://npm.io/package/2d-polygon-area.md) ^1.0.0
- [point-in-big-polygon](https://npm.io/package/point-in-big-polygon.md) ~1.0.0

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2015-06-05
- 1.0.0 — 2014-12-18

## README

# polygon.clip

Implementation of the Greiner-Kai "efficient clipping of arbitrary polygons" [paper](http://www.inf.usi.ch/hormann/papers/Greiner.1998.ECO.pdf)

## 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
```javascript
  [
    [
      [0, 0],
      [0, 1],
      [1, 1]
    ]
  ]
```
### example

```javascript

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](LICENSE.txt)

---
_Source: https://npm.io/package/2d-polygon-boolean · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
