# merge-simple-polygons

> Merge two (adjacent) simple polygons into one.

Latest version **2.0.0** (published 2022-05-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install merge-simple-polygons
pnpm add merge-simple-polygons
yarn add merge-simple-polygons
bun add merge-simple-polygons
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-05-26 |
| First published | 2018-03-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Julius Tens |
| Maintainers | juliuste |
| Keywords | merge, combine, join, adjacent, simple, polygon, polygons, planar, shape, shapes, path, paths |

## Links

- npm: https://www.npmjs.com/package/merge-simple-polygons
- Repository: https://github.com/juliuste/merge-simple-polygons
- Issues: https://github.com/juliuste/merge-simple-polygons/issues
- npm.io page: https://npm.io/package/merge-simple-polygons

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-05-26
- 1.0.2 — 2018-03-27
- 1.0.1 — 2018-03-27
- 1.0.0 — 2018-03-27

## README

# merge-simple-polygons

Merge two (adjacent) simple polygons into another simple polygon.

[![npm version](https://img.shields.io/npm/v/merge-simple-polygons.svg)](https://www.npmjs.com/package/merge-simple-polygons)
[![License](https://img.shields.io/github/license/juliuste/merge-simple-polygons.svg?style=flat)](license)
[![Contact me](https://img.shields.io/badge/contact-email-turquoise)](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).

---
_Source: https://npm.io/package/merge-simple-polygons · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
