1.0.1 • Published 10 years ago
poly-to-pslg v1.0.1
poly-to-pslg
Converts a polygon into a planar straight line graph.
Example
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
{ 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-pslgAPI
var graph = require('poly-to-pslg')(loops[, options])
Converts a polygon into a planar straight line graph.
loopsis an array of loops determining the vertices of the polygon. If only one loop is specified, this is inferred automatically.optionsis an object storing some optional parametersoptions.cleanif this flag is set to true, then clean up the resulting graph usingclean-pslg. (Defaulttrue)options.nestedif this flag is set to true, then assume the polygon is an array of loops. Iffalse, then suppose that the polygon is just one array.
Returns An object with two properties
pointsare the vertex coordinate of the pslgedgesare the edges of the pslg
License
(c) 2015 Mikola Lysenko. MIT License