diff --git a/src/delaunay_core/cell.rs b/src/delaunay_core/cell.rs index 9f9aa3e..e8630f1 100644 --- a/src/delaunay_core/cell.rs +++ b/src/delaunay_core/cell.rs @@ -40,7 +40,7 @@ impl Cell { } pub fn dim(&self) -> usize { - D + self.number_of_vertices() - 1 } } @@ -53,18 +53,25 @@ mod tests { #[test] fn make_cell_with_data() { - let vertex1 = Vertex::new_with_data(Point::new([1.0, 2.0, 3.0]), "3D"); - let cell = Cell::new_with_data(vec![vertex1], 10); + let vertex1 = Vertex::new_with_data(Point::new([0.0, 0.0, 1.0]), 1); + let vertex2 = Vertex::new_with_data(Point::new([0.0, 1.0, 0.0]), 1); + let vertex3 = Vertex::new_with_data(Point::new([1.0, 0.0, 0.0]), 1); + let vertex4 = Vertex::new_with_data(Point::new([1.0, 1.0, 1.0]), 2); + let cell = Cell::new_with_data(vec![vertex1, vertex2, vertex3, vertex4], "three-one cell"); - assert_eq!(cell.vertices[0].point.coords[0], 1.0); - assert_eq!(cell.vertices[0].point.coords[1], 2.0); - assert_eq!(cell.vertices[0].point.coords[2], 3.0); - assert_eq!(cell.vertices[0].data.unwrap(), "3D"); + assert_eq!(cell.vertices[0], vertex1); + assert_eq!(cell.vertices[1], vertex2); + assert_eq!(cell.vertices[2], vertex3); + assert_eq!(cell.vertices[3], vertex4); + assert_eq!(cell.vertices[0].data.unwrap(), 1); + assert_eq!(cell.vertices[1].data.unwrap(), 1); + assert_eq!(cell.vertices[2].data.unwrap(), 1); + assert_eq!(cell.vertices[3].data.unwrap(), 2); assert_eq!(cell.dim(), 3); - assert_eq!(cell.number_of_vertices(), 1); + assert_eq!(cell.number_of_vertices(), 4); assert!(cell.neighbors.is_none()); assert!(cell.data.is_some()); - assert_eq!(cell.data.unwrap(), 10); + assert_eq!(cell.data.unwrap(), "three-one cell"); // Human readable output for cargo test -- --nocapture println!("Cell: {:?}", cell); @@ -72,15 +79,23 @@ mod tests { #[test] fn make_cell_without_data() { - let vertex1 = Vertex::new_with_data(Point::new([1.0, 2.0, 3.0]), "3D"); - let cell: Cell, 3> = Cell::new(vec![vertex1]); + let vertex1 = Vertex::new_with_data(Point::new([0.0, 0.0, 1.0]), 1); + let vertex2 = Vertex::new_with_data(Point::new([0.0, 1.0, 0.0]), 1); + let vertex3 = Vertex::new_with_data(Point::new([1.0, 0.0, 0.0]), 1); + let vertex4 = Vertex::new_with_data(Point::new([1.0, 1.0, 1.0]), 2); + let cell: Cell, 3> = + Cell::new(vec![vertex1, vertex2, vertex3, vertex4]); - assert_eq!(cell.vertices[0].point.coords[0], 1.0); - assert_eq!(cell.vertices[0].point.coords[1], 2.0); - assert_eq!(cell.vertices[0].point.coords[2], 3.0); - assert_eq!(cell.vertices[0].data.unwrap(), "3D"); + assert_eq!(cell.vertices[0], vertex1); + assert_eq!(cell.vertices[1], vertex2); + assert_eq!(cell.vertices[2], vertex3); + assert_eq!(cell.vertices[3], vertex4); + assert_eq!(cell.vertices[0].data.unwrap(), 1); + assert_eq!(cell.vertices[1].data.unwrap(), 1); + assert_eq!(cell.vertices[2].data.unwrap(), 1); + assert_eq!(cell.vertices[3].data.unwrap(), 2); assert_eq!(cell.dim(), 3); - assert_eq!(cell.number_of_vertices(), 1); + assert_eq!(cell.number_of_vertices(), 4); assert!(cell.neighbors.is_none()); assert!(cell.data.is_none()); diff --git a/src/delaunay_core/point.rs b/src/delaunay_core/point.rs index d995658..dde1a6f 100644 --- a/src/delaunay_core/point.rs +++ b/src/delaunay_core/point.rs @@ -1,4 +1,4 @@ -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Copy)] pub struct Point { pub coords: [T; D], } diff --git a/src/delaunay_core/vertex.rs b/src/delaunay_core/vertex.rs index 1f81404..250411c 100644 --- a/src/delaunay_core/vertex.rs +++ b/src/delaunay_core/vertex.rs @@ -4,7 +4,7 @@ use std::option::Option; use super::{point::Point, utilities::make_uuid}; -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Copy)] pub struct Vertex { pub point: Point, pub uuid: Uuid, @@ -62,7 +62,7 @@ mod tests { assert_eq!(vertex.point.coords[1], 2.0); assert_eq!(vertex.point.coords[2], 3.0); assert_eq!(vertex.point.coords[3], 4.0); - assert_eq!(vertex.point.dim(), 4); + assert_eq!(vertex.dim(), 4); assert!(vertex.incident_cell.is_none()); assert!(vertex.data.is_some()); assert_eq!(vertex.data.unwrap(), "4D"); @@ -75,6 +75,7 @@ mod tests { assert_eq!(vertex.point.coords[0], 1.0); assert_eq!(vertex.point.coords[1], 2.0); assert_eq!(vertex.point.coords[2], 3.0); + assert_eq!(vertex.dim(), 3); assert!(vertex.incident_cell.is_none()); assert!(vertex.data.is_none()); } @@ -92,12 +93,15 @@ mod tests { assert_eq!(vertices[0].point.coords[0], 1.0); assert_eq!(vertices[0].point.coords[1], 2.0); assert_eq!(vertices[0].point.coords[2], 3.0); + assert_eq!(vertices[0].dim(), 3); assert_eq!(vertices[1].point.coords[0], 4.0); assert_eq!(vertices[1].point.coords[1], 5.0); assert_eq!(vertices[1].point.coords[2], 6.0); + assert_eq!(vertices[1].dim(), 3); assert_eq!(vertices[2].point.coords[0], 7.0); assert_eq!(vertices[2].point.coords[1], 8.0); assert_eq!(vertices[2].point.coords[2], 9.0); + assert_eq!(vertices[2].dim(), 3); // Human readable output for cargo test -- --nocapture println!("{:?}", vertices);