poly2tri-rs
An idiomatic and fast(not just because the language) rust porting for poly2tri cpp project. It calculates CDT (Constrained Delaunay Triangulation) on a polygon.
Install
Add following to cargo.toml
[]
= "0.1"
Or
Features
- Multiple hole and steiner points
- Fast
- Test coverage, there are both stable and random tests(prop test). Actually discovered and fixed several bugs from cpp lib.
Performance
Introduced a bunch of perf optimizations to meet the cpp version, without breaking the type system.
Timing at the time of writing on my m1 mbp:
| example | poly2tri-rs | poly2tri (cpp) | point count |
|---|---|---|---|
| bird | 0.12ms | 0.17ms | 275 |
| debug | 0.1ms | 0.14ms | 200 |
| nazca_heron | 0.82ms | 0.55ms | 1036 |
| nazca_monkey | 0.89ms | 0.76ms | 1204 |
I think both libraries are fast enough. Take nazca_heron as an example, there are 1000 points, generated around 2000 triangles in the process, around 7000 rotation fix, all finished under 1ms on one core.
Limitations
- Only one polyline supported. For multiple polyline, need to preprocess them.
- Duplicate point not supported. (yet)
Examples
A square with a hole
&&
Sample code
Draw test data from poly2tri's testbed
# clone repos
# open the svg