poly-parse
Parses .poly files from Triangle.
A .poly file represents a PSLG, as well as some additional information. PSLG stands for Planar Straight Line Graph, a term familiar to computational geometers. By definition, a PSLG is just a list of vertices and segments. A .poly file can also contain information about holes and concavities, as well as regional attributes and constraints on the areas of triangles.
Full description of the .poly file format.
It can also parse .node files since they are a subset of .poly.
The file is parsed with Papa Parse.
Install
npm install poly-parse
Example
const polyparse = require('poly-parse');
fetch('./A.poly')
.then(result => result.text())
.then(result => {
console.log(polyparse(result));
});
Output:
{
pointlist: [[0.2, -0.7764], [0.22, -0.7732] ...],
pointattributelist: [-0.57, -0.55, -0.51, -0.53 ...],
pointmarkerlist: [],
segmentlist: [[28, 0], [0, 1] ...],
segmentmarkerlist: [],
holelist: [[0.47, -0.5]],
regionlist: [],
numberofpoints: 29,
numberofpointattributes: 1,
numberofsegments: 29,
numberofholes: 1,
numberofregions: 0
}
Demo
Usage
polyparse(poly, options)
-
poly
string with the content of the .poly file -
options
flat
(defaultfalse
) flatten nested arrays i.e.[[x, y], [x, y]]
into[x, y, x, y]
flipY
(defaultfalse
) multiplies y coordinates by -1normalize
(defaultfalse
) normalizes path to its bounding box, returns points in the-1.0 ... 1.0
range- all the config options from Papa Parse
Returns an object with the parsed properties.
For convenience the parsed output uses the same property names as struct triangulateio
defined in triangle.h
from Triangle.
Indices in a .poly file can be zero-based or one-based, but the parsed result is always zero-based.
See Also
- Triangle - A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator - Jonathan Shewchuk
- svg-to-poly
License
MIT, see LICENSE for details.