https://github.com/juliuste/merge-simple-polygons
Merge two (adjacent) simple polygons into another simple polygon.
https://github.com/juliuste/merge-simple-polygons
library
Last synced: about 1 year ago
JSON representation
Merge two (adjacent) simple polygons into another simple polygon.
- Host: GitHub
- URL: https://github.com/juliuste/merge-simple-polygons
- Owner: juliuste
- License: isc
- Created: 2018-03-27T03:56:27.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2022-05-26T15:50:42.000Z (about 4 years ago)
- Last Synced: 2024-10-17T04:32:34.429Z (over 1 year ago)
- Topics: library
- Language: JavaScript
- Size: 9.77 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# merge-simple-polygons
Merge two (adjacent) simple polygons into another simple polygon.
[](https://www.npmjs.com/package/merge-simple-polygons)
[](license)
[](mailto:mail@juliustens.eu)
## Installation
```shell
npm install merge-simple-polygons
```
## Usage
**This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).**
The module's default export is a function that takes two arrays of vertex names, each spanning a planar polygon and returns:
- `false` if the given polygons share no vertices
- `null` if there would be more than one resulting simple polygon (if the two given polygons share either exactly one vertex, which would result in two polygons *or* multiple egdes that are not connected, which would result in a polygon with a "hole")
- a list of vertex IDs forming the merged polygon
```js
import mergePolygons from 'merge-simple-polygons'
const polygonA = ['a', 'b', 'c', 'd', 'e']
const polygonB = ['e', 'a', 'g', 'h', 'i', 'd']
const polygonC = mergePolygons(polygonA, polygonB)
console.log(polygonC) // ['a', 'b', 'c', 'd', 'i', 'h', 'g']
const polygonD = ['a', 'b', 'c']
const polygonE = ['d', 'e', 'f']
console.log(mergePolygons(polygonD, polygonE)) // false
const polygonF = ['a', 'b', 'c', 'd', 'e']
const polygonG = ['a', 'b', 'f', 'e', 'd', 'g']
console.log(mergePolygons(polygonF, polygonG)) // null
```
## Contributing
If you found a bug or want to propose a feature, feel free to visit [the issues page](https://github.com/juliuste/merge-simple-polygons/issues).