iTriangle
A fast, stable, and robust 2d triangulation library for rust — tested on over 10⁹ randomized inputs.
For detailed performance benchmarks, check out the Performance Comparison
Delaunay
Convex polygons
Steiner points
Tessellation
Centroid net
Features
- Raw Triangulation - Fast and simple triangulation of polygons with or without holes.
- Delaunay Triangulation - Efficient and robust implementation for generating Delaunay triangulations.
- Self-Intersection Handling – Fully supports self-intersecting polygons with automatic resolution.
- Adaptive Tessellation - Refine Delaunay triangles using circumcenters for better shape quality.
- Convex Decomposition - Convert triangulation into convex polygons.
- Centroidal Polygon Net: Build per-vertex dual polygons using triangle centers and edge midpoints.
- Steiner Points: Add custom inner points to influence triangulation.
- GPU-Friendly Layout: Triangles and vertices are naturally ordered by X due to the sweep-line algorithm, improving cache locality for rendering.
Reliability
- Extremely Stable: The core triangulation and Delaunay algorithms have been tested against over 1 billion randomized polygon samples.
- Uses pure integer math to avoid floating-point precision issues.
- Designed for use in CAD, EDA, game engines, and any application where robustness is critical.
Demo
Documentation
Getting Started
Add to your Cargo.toml
:
[dependencies]
i_triangle = "^0.36.0"
Example: Single Shape Triangulation
use Triangulatable;
use Triangulation;
let shape = vec!;
let triangulation = shape.triangulate.;
println!;
println!;
let delaunay_triangulation: =
shape.triangulate.into_delaunay.to_triangulation;
println!;
println!;
let convex_polygons = shape.triangulate.into_delaunay.to_convex_polygons;
println!;
let tessellation: = shape
.triangulate
.into_delaunay
.refine_with_circumcenters_by_obtuse_angle
.to_triangulation;
println!;
println!;
let centroids = shape
.triangulate
.into_delaunay
.refine_with_circumcenters_by_obtuse_angle
.to_centroid_net;
println!;
💡 Output: Triangle indices and vertices, where all triangles oriented in a counter-clockwise direction..
Example: Triangulating Multiple Shapes Efficiently
If you need triangulate many shapes it's more efficient way is to use Triangulator
let contours = random_contours;
let mut triangulator = default;
// Enable Delaunay refinement
triangulator.delaunay;
// Use fast Earcut solver for contours with ≤ 64 points
triangulator.earcut;
let mut triangulation = with_capacity;
for contour in contours.iter