Calculate the Delaunay triangulation of the given point cloud
(points: impl Iterator<Item = geo::Point>)
| 5 | |
| 6 | /// Calculate the Delaunay triangulation of the given point cloud |
| 7 | pub fn triangulate(points: impl Iterator<Item = geo::Point>) -> Option<Triangulation> { |
| 8 | let points: Vec<delaunator::Point> = points |
| 9 | .map(|gp| delaunator::Point { |
| 10 | x: gp.x(), |
| 11 | y: gp.y(), |
| 12 | }) |
| 13 | .collect(); |
| 14 | if points.len() < 3 { |
| 15 | return None; |
| 16 | } |
| 17 | let triangulation = delaunator::triangulate(&points); |
| 18 | |
| 19 | Some(Triangulation { |
| 20 | points, |
| 21 | triangulation, |
| 22 | }) |
| 23 | } |
| 24 | |
| 25 | pub struct Triangulation { |
| 26 | points: Vec<delaunator::Point>, |
no outgoing calls