#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
use use_point::Point2;
#[derive(Debug, Clone, PartialEq)]
pub struct VoronoiCell {
site_index: usize,
boundary_vertices: Vec<Point2>,
}
impl VoronoiCell {
#[must_use]
pub const fn new(site_index: usize, boundary_vertices: Vec<Point2>) -> Self {
Self {
site_index,
boundary_vertices,
}
}
#[must_use]
pub const fn site_index(&self) -> usize {
self.site_index
}
#[must_use]
pub fn boundary_vertices(&self) -> &[Point2] {
&self.boundary_vertices
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct VoronoiDiagram {
cells: Vec<VoronoiCell>,
}
impl VoronoiDiagram {
#[must_use]
pub const fn new(cells: Vec<VoronoiCell>) -> Self {
Self { cells }
}
#[must_use]
pub fn cells(&self) -> &[VoronoiCell] {
&self.cells
}
#[must_use]
pub fn cell_count(&self) -> usize {
self.cells.len()
}
}
#[cfg(test)]
mod tests {
use super::{VoronoiCell, VoronoiDiagram};
use use_point::Point2;
#[test]
fn stores_voronoi_cells() {
let cell = VoronoiCell::new(0, vec![Point2::origin()]);
let diagram = VoronoiDiagram::new(vec![cell]);
assert_eq!(diagram.cell_count(), 1);
assert_eq!(diagram.cells()[0].site_index(), 0);
assert_eq!(diagram.cells()[0].boundary_vertices(), &[Point2::origin()]);
}
}