# polyline-normals

> gets miter normals for a 2D polyline

Latest version **2.0.2** (published 2014-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install polyline-normals
pnpm add polyline-normals
yarn add polyline-normals
bun add polyline-normals
```

## 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 | 2.0.2 |
| Published | 2014-11-28 |
| First published | 2014-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 145 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | polyline, mesh, webgl, glsl, stackgl |

## Links

- npm: https://www.npmjs.com/package/polyline-normals
- Repository: https://github.com/mattdesl/polyline-normals
- Issues: https://github.com/mattdesl/polyline-normals/issues
- npm.io page: https://npm.io/package/polyline-normals

## Dependencies (1)

- [polyline-miter-util](https://npm.io/package/polyline-miter-util.md) ^1.0.1

## Recent versions

- 2.0.2 (latest) — 2014-11-28
- 2.0.1 — 2014-11-28
- 2.0.0 — 2014-11-28
- 1.0.2 — 2014-11-28
- 1.0.1 — 2014-11-28
- 1.0.0 — 2014-11-28

## README

# polyline-normals

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

![img](http://i.imgur.com/UP2Fq12.png)

Computes the normals of a polyline, using miter joins where multiple segments meet.  This is mainly useful to expand thick lines in a vertex shader on the GPU. 

```js
var getNormals = require('polyline-normals')

//a triangle
var path = [ [0, 122], [0, 190], [90, 190] ]

//get the normals as a closed loop
var normals = getNormals(path, true)

//now draw our thick line in 2D/3D/etc
```

See [the 2d test](test-2d.js) for an example of how these lines would be extruded. 

For more complex line joins and end caps, see [extrude-polyline](https://nodei.co/npm/extrude-polyline/) (which builds an indexed mesh). 

## Shader Example

For an example of how to use this within a shader, see [three-line-2d](https://nodei.co/npm/three-line-2d/).

## Usage

[![NPM](https://nodei.co/npm/polyline-normals.png)](https://nodei.co/npm/polyline-normals/)

#### `normals(path[, closed])`

For the given path, produces a new array of the same length with normal information for each point. The data contains a normal, `[nx, ny]` and the length of the miter (default to 1.0 where no join occurs). 

```js
[ 
    [ [nx, ny], miterLength ],
    [ [nx, ny], miterLength ]
]
```

If `closed` is true, it assumes a segment will be drawn from the last point to the first point, and adjusts those normals accordingly.

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/polyline-normals/blob/master/LICENSE.md) for details.

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