# d3-polygon

> Operations for two-dimensional polygons.

Latest version **3.0.1** (published 2021-06-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install d3-polygon
pnpm add d3-polygon
yarn add d3-polygon
bun add d3-polygon
```

## Health

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

Positive: has types package; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2021-06-05 |
| First published | 2015-07-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/d3-polygon) |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 0 |
| Unpacked size | 14.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 100 |
| Author | Mike Bostock |
| Maintainers | mbostock, recifs |
| Keywords | d3, d3-module, polygon, hull, geometry, graphics |

## Links

- npm: https://www.npmjs.com/package/d3-polygon
- Repository: https://github.com/d3/d3-polygon
- Homepage: https://d3js.org/d3-polygon/
- Issues: https://github.com/d3/d3-polygon/issues
- npm.io page: https://npm.io/package/d3-polygon

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2021-06-05
- 2.0.0-rc.1 (next) — 2020-07-27
- 3.0.0 — 2021-06-04
- 2.0.0 — 2020-08-19
- 1.0.6 — 2019-11-16
- 1.0.5 — 2018-08-24
- 1.0.4 — 2018-08-24
- 1.0.3 — 2017-03-10
- 1.0.2 — 2016-11-23
- 1.0.1 — 2016-08-02
- 1.0.0 — 2016-06-14
- 0.3.0 — 2016-06-08
- 0.2.1 — 2016-01-29
- 0.2.0 — 2016-01-11
- 0.1.0 — 2015-12-18
- … 5 more at https://npm.io/package/d3-polygon/versions

## README

# d3-polygon

This module provides a few basic geometric operations for two-dimensional polygons. Each polygon is represented as an array of two-element arrays [​[<i>x1</i>, <i>y1</i>], [<i>x2</i>, <i>y2</i>], …], and may either be closed (wherein the first and last point are the same) or open (wherein they are not). Typically polygons are in counterclockwise order, assuming a coordinate system where the origin ⟨0,0⟩ is in the top-left corner.

## Installing

If you use npm, `npm install d3-polygon`. You can also download the [latest release on GitHub](https://github.com/d3/d3-polygon/releases/latest). For vanilla HTML in modern browsers, import d3-polygon from Skypack:

```html
<script type="module">

import {polygonHull} from "https://cdn.skypack.dev/d3-polygon@3";

const hull = polygonHull(points);

</script>
```

For legacy environments, you can load d3-polygon’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:

```html
<script src="https://cdn.jsdelivr.net/npm/d3-polygon@3"></script>
<script>

const hull = d3.polygonHull(points);

</script>
```

## API Reference

<a href="#polygonArea" name="polygonArea">#</a> d3.<b>polygonArea</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/area.js "Source Code")

Returns the signed area of the specified *polygon*. If the vertices of the polygon are in counterclockwise order (assuming a coordinate system where the origin ⟨0,0⟩ is in the top-left corner), the returned area is positive; otherwise it is negative, or zero.

<a href="#polygonCentroid" name="polygonCentroid">#</a> d3.<b>polygonCentroid</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/centroid.js "Source Code")

Returns the [centroid](https://en.wikipedia.org/wiki/Centroid) of the specified *polygon*.

<a href="#polygonHull" name="polygonHull">#</a> d3.<b>polygonHull</b>(<i>points</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/hull.js#L23 "Source Code")

<a href="http://bl.ocks.org/mbostock/6f14f7b7f267a85f7cdc"><img src="https://raw.githubusercontent.com/d3/d3-polygon/master/img/hull.png" width="250" height="250"></a>

Returns the [convex hull](https://en.wikipedia.org/wiki/Convex_hull) of the specified *points* using [Andrew’s monotone chain algorithm](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain). The returned hull is represented as an array containing a subset of the input *points* arranged in counterclockwise order. Returns null if *points* has fewer than three elements.

<a href="#polygonContains" name="polygonContains">#</a> d3.<b>polygonContains</b>(<i>polygon</i>, <i>point</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/contains.js "Source Code")

Returns true if and only if the specified *point* is inside the specified *polygon*.

<a href="#polygonLength" name="polygonLength">#</a> d3.<b>polygonLength</b>(<i>polygon</i>) [<>](https://github.com/d3/d3-polygon/blob/master/src/length.js "Source Code")

Returns the length of the perimeter of the specified *polygon*.

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