#delaunay #voronoi #delaunay-triangulation #triangle #points #voronoi-diagram #space

delaunay2d

A library to compute Delaunay triangulations and Voronoi diagrams in 2D space

2 releases

Uses old Rust 2015

0.0.2 Dec 13, 2017
0.0.1 Jan 18, 2017

#972 in Math

MIT license

26KB
441 lines

% Delaunay2D

This crate provides a library for computing a Delaunay triangulation from a set of points using the Bowyer–Watson algorithm.

While performance shouldn't be terrible, there is definite room for improvement.

Usage

extern crate delaunay2d;

Example: Delaunay triangulation

use delaunay2d::{Delaunay2D, Triangle};
let mut dt = Delaunay2D::new((0., 0.), 9999.);

dt.add_point((13., 12.));
dt.add_point((18., 19.));
dt.add_point((21., 5.));
dt.add_point((37., -3.));

let mut triangles = dt.export_triangles();
triangles.sort_by_key(|t| (t.0, t.1, t.2));
assert_eq!(vec![Triangle(2,1,0), Triangle(3, 1, 2)], triangles);

Example: Voronoi regions

use delaunay2d::{Delaunay2D};
let mut dt = Delaunay2D::new((0., 0.), 9999.);

dt.add_point((13., 12.));
dt.add_point((18., 19.));
dt.add_point((21., 5.));
dt.add_point((37., -3.));

let (points, mut regions) = dt.export_voronoi_regions();
regions.sort();
assert_eq!(10, points.len());
assert_eq!(4, regions.len());

No runtime deps