Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/poly-to-pslg
Convert a polygon into a planar straight line graph
https://github.com/mikolalysenko/poly-to-pslg
Last synced: about 2 months ago
JSON representation
Convert a polygon into a planar straight line graph
- Host: GitHub
- URL: https://github.com/mikolalysenko/poly-to-pslg
- Owner: mikolalysenko
- License: mit
- Created: 2015-06-28T07:01:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-04T08:44:12.000Z (over 9 years ago)
- Last Synced: 2024-10-19T00:19:15.720Z (2 months ago)
- Language: JavaScript
- Size: 113 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
poly-to-pslg
============
Converts a polygon into a planar straight line graph.# Example
```javascript
var poly2pslg = require('poly-to-pslg')var polygon = [
[[-2, 2], [2, 2], [2, -2], [-2,-2]],
[[-1, 1], [1, 1], [1, -1], [-1,-1]]
]var pslg = poly2pslg(polygon)
console.log(pslg)
```#### Output
```javascript
{ points:
[ [ -2, 2 ],
[ 2, 2 ],
[ 2, -2 ],
[ -2, -2 ],
[ -1, 1 ],
[ 1, 1 ],
[ 1, -1 ],
[ -1, -1 ] ],
edges:
[ [ 0, 1 ],
[ 1, 2 ],
[ 2, 3 ],
[ 3, 0 ],
[ 4, 5 ],
[ 5, 6 ],
[ 6, 7 ],
[ 7, 4 ] ] }
```# Install
```
npm i poly-to-pslg
```# API
#### `var graph = require('poly-to-pslg')(loops[, options])`
Converts a polygon into a planar straight line graph.* `loops` is an array of loops determining the vertices of the polygon. If only one loop is specified, this is inferred automatically.
* `options` is an object storing some optional parameters
+ `options.clean` if this flag is set to true, then clean up the resulting graph using `clean-pslg`. (Default `true`)
+ `options.nested` if this flag is set to true, then assume the polygon is an array of loops. If `false`, then suppose that the polygon is just one array.**Returns** An object with two properties
* `points` are the vertex coordinate of the pslg
* `edges` are the edges of the pslg# License
(c) 2015 Mikola Lysenko. MIT License