Function rtriangulate::triangulate
[−]
[src]
pub fn triangulate<T, P>(points: &[P]) -> Result<Vec<Triangle>> where
T: FloatCore,
P: Point<T>,
Generate the Delaunay triangulation of given set of points.
It takes a slice of points, and returns a vector of triangles arranged in clockwise order. The
list of points must have a least three entries, otherwise this function will panic. The points
needs to be sorted by increasing x
value. The sort_points
function provided in this
module can be used, in conjunction with sort_by
or sort_unstable_by
, to order your slice
of points as necessary.
The returned triangles are indices into the input slice of points.
Example:
use rtriangulate::{TriangulationPoint, Triangle, triangulate}; // Note that the points are sorted in ascending order of x. let points = [ TriangulationPoint::new(10.0, 10.0), TriangulationPoint::new(15.0, 25.0), TriangulationPoint::new(25.0, 15.0), TriangulationPoint::new(30.0, 25.0), TriangulationPoint::new(40.0, 15.0) ]; // If needed, you can sort your points like this: // points.sort_unstable_by(rtriangulate::sort_points); let triangles = triangulate(&points).unwrap(); assert_eq!( triangles, [Triangle(0, 1, 2), Triangle(2, 1, 3), Triangle(0, 2, 4), Triangle(2, 3, 4)] );