Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brunoimbrizi/poly-parse
Parses .poly or .node files
https://github.com/brunoimbrizi/poly-parse
delaunay pslg triangle
Last synced: 17 days ago
JSON representation
Parses .poly or .node files
- Host: GitHub
- URL: https://github.com/brunoimbrizi/poly-parse
- Owner: brunoimbrizi
- License: mit
- Created: 2020-10-31T00:13:51.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-08T20:10:57.000Z (about 4 years ago)
- Last Synced: 2024-10-10T21:42:52.459Z (about 1 month ago)
- Topics: delaunay, pslg, triangle
- Language: JavaScript
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
poly-parse
==========Parses .poly files from [Triangle](https://www.cs.cmu.edu/~quake/triangle.html).
> 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](https://www.cs.cmu.edu/~quake/triangle.poly.html).
It can also parse [.node files](https://www.cs.cmu.edu/~quake/triangle.node.html) since they are a subset of .poly.
The file is parsed with [Papa Parse](https://www.npmjs.com/package/papaparse).
[![demo](https://user-images.githubusercontent.com/880280/98482770-7b0eaf80-21fb-11eb-870e-fb30791b4d30.png)](https://brunoimbrizi.github.io/poly-parse/demo/)
## Install
```
npm install poly-parse
```## Example
```js
const polyparse = require('poly-parse');fetch('./A.poly')
.then(result => result.text())
.then(result => {
console.log(polyparse(result));
});
```
Output:```js
{
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
[poly-parse demo](https://brunoimbrizi.github.io/poly-parse/demo/)
## Usage
### `polyparse(poly, options)`
- `poly` string with the content of the .poly file
- `options`
- `flat` (default `false`) flatten nested arrays i.e. `[[x, y], [x, y]]` into `[x, y, x, y]`
- `flipY` (default `false`) multiplies y coordinates by -1
- `normalize` (default `false`) normalizes path to its bounding box, returns points in the `-1.0 ... 1.0` range
- all the [config options from Papa Parse](https://www.papaparse.com/docs#config)**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](https://www.cs.cmu.edu/~quake/triangle.html).
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](https://www.cs.cmu.edu/~quake/triangle.html) - Jonathan Shewchuk
- [svg-to-poly](https://github.com/brunoimbrizi/svg-to-poly)## License
MIT, see [LICENSE](LICENSE) for details.