https://github.com/pirxpilot/vis-why
M Visvalingam and J D Whyatt line simplification algorithm
https://github.com/pirxpilot/vis-why
polyline
Last synced: 11 months ago
JSON representation
M Visvalingam and J D Whyatt line simplification algorithm
- Host: GitHub
- URL: https://github.com/pirxpilot/vis-why
- Owner: pirxpilot
- Created: 2014-07-29T14:41:52.000Z (almost 12 years ago)
- Default Branch: main
- Last Pushed: 2024-02-07T11:47:31.000Z (over 2 years ago)
- Last Synced: 2024-11-20T03:39:04.894Z (over 1 year ago)
- Topics: polyline
- Language: JavaScript
- Size: 131 KB
- Stars: 4
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# vis-why
M Visvalingam and J D Whyatt line simplification algorithm
Implementation based on [Mike Bostock's code](http://bost.ocks.org/mike/simplify/) but without a d3 dependency.
Live demo is [here](http://pirxpilot.github.io/vis-why/)
## Installation
Install with [npm]:
$ npm install vis-why
## API
### `simplify(polyline, limit)`
Simplify polyline by [repeated elimination of the smallest][vis-why] area.
- `polyline` - array of points representing a polyline, each point represented by coordinate array `[x, y]`
- `limit` - number of points/vortexes that will remain in the resulting polyline
### `simplify(polyline, limit, areaFn)`
You can specify a custom `areaFn` if your points are not represented by `[x, y]` pair. For example if you have
an array of `{x, y}` objects you can use something like this:
```js
function area(a, b, c) {
return Math.abs(
(a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y)
);
}
simplify(poly, 4, area);
```
## License
The MIT License (MIT)
Copyright (c) 2014
[npm]: https://www.npmjs.org/
[vis-why]: https://hydra.hull.ac.uk/resources/hull:8338
[npm-image]: https://img.shields.io/npm/v/vis-why
[npm-url]: https://npmjs.org/package/vis-why
[build-url]: https://github.com/pirxpilot/vis-why/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/vis-why/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/vis-why
[deps-url]: https://libraries.io/npm/vis-why