use nalgebra::Point2;
pub(crate) struct Triangulation {
pub(crate) triangles: Vec<usize>,
pub(crate) halfedges: Vec<usize>,
}
impl Triangulation {
#[inline]
pub(crate) fn num_tri(&self) -> usize {
self.triangles.len() / 3
}
#[inline]
pub(crate) fn next_edge(e: usize) -> usize {
if e % 3 == 2 {
e - 2
} else {
e + 1
}
}
#[inline]
pub(crate) fn tri_of(e: usize) -> usize {
e / 3
}
}
pub(crate) fn triangulate(positions: &[Point2<f32>]) -> Triangulation {
let pts: Vec<delaunator::Point> = positions
.iter()
.map(|p| delaunator::Point {
x: p.x as f64,
y: p.y as f64,
})
.collect();
let t = delaunator::triangulate(&pts);
Triangulation {
triangles: t.triangles,
halfedges: t.halfedges,
}
}