From 0b137ab609655655c8b4aae75391e07ad06b14c0 Mon Sep 17 00:00:00 2001 From: Adam Getchell Date: Fri, 15 Dec 2023 13:09:01 -0800 Subject: [PATCH] Add incident_cell to Vertex and neighbors to Cells Cells and vertices are identified by their universally unique identifiers (UUIDs) generated by the uuid crate. Following CGAL's convention: - A Vertex stores the UUID of an incident cell - A cell stores a container of the UUIDs of it's neighboring cells These are Options because they are not known when an individual cell or vertex is created. They are planned to be later inserted by the Triangulation when it is constructed. --- Cargo.toml | 2 ++ README.md | 1 + cspell.json | 1 + src/delaunay_core/cell.rs | 10 ++++++---- src/delaunay_core/point.rs | 2 -- .../triangulation_data_structure.rs | 2 -- src/delaunay_core/vertex.rs | 16 +++++++++++++--- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a155a20..8984ec8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,5 @@ uuid = { version = "1.6.1", features = ["v4", "fast-rng", "macro-diagnostics"] } [lints.rust] unsafe_code = "forbid" +dead_code = "allow" +#missing_docs = "warn" diff --git a/README.md b/README.md index 7a5c2d5..ef55613 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![CI](https://github.com/acgetchell/d-delaunay/actions/workflows/ci.yml/badge.svg)](https://github.com/acgetchell/d-delaunay/actions/workflows/ci.yml) [![rust-clippy analyze](https://github.com/acgetchell/d-delaunay/actions/workflows/rust-clippy.yml/badge.svg)](https://github.com/acgetchell/d-delaunay/actions/workflows/rust-clippy.yml) +[![codecov](https://codecov.io/gh/acgetchell/d-delaunay/graph/badge.svg?token=WT7qZGT9bO)](https://codecov.io/gh/acgetchell/d-delaunay) D-dimensional Delaunay triangulations in Rust, inspired by [CGAL]. diff --git a/cspell.json b/cspell.json index 946b2cc..790fc3e 100644 --- a/cspell.json +++ b/cspell.json @@ -7,6 +7,7 @@ "acgetchell", "CGAL", "clippy", + "codecov", "Voronoi" ], "ignoreWords": [], diff --git a/src/delaunay_core/cell.rs b/src/delaunay_core/cell.rs index 25dab3b..dd0fe7c 100644 --- a/src/delaunay_core/cell.rs +++ b/src/delaunay_core/cell.rs @@ -2,21 +2,22 @@ use uuid::Uuid; use super::{utilities::make_uuid, vertex::Vertex}; -#[allow(dead_code)] #[derive(Debug)] -struct Cell { +pub struct Cell { pub vertices: Vec>, - uuid: Uuid, + pub uuid: Uuid, + pub neighbors: Option>, pub data: T, } -#[allow(dead_code)] impl Cell { pub fn new(vertices: Vec>, data: T) -> Self { let uuid = make_uuid(); + let neighbors = None; Cell { vertices, uuid, + neighbors, data, } } @@ -44,6 +45,7 @@ mod tests { assert_ne!(cell.vertices[0].uuid, make_uuid()); assert_eq!(cell.vertices[0].data, 3); assert_eq!(cell.number_of_vertices(), 1); + assert!(cell.neighbors.is_none()); assert_ne!(cell.uuid, make_uuid()); assert_ne!(cell.uuid, cell.vertices[0].uuid); assert_eq!(cell.data, 10); diff --git a/src/delaunay_core/point.rs b/src/delaunay_core/point.rs index a2220e1..36c2692 100644 --- a/src/delaunay_core/point.rs +++ b/src/delaunay_core/point.rs @@ -1,4 +1,3 @@ -#[allow(dead_code)] #[derive(Debug)] pub struct Point { pub x: T, @@ -6,7 +5,6 @@ pub struct Point { pub z: T, } -#[allow(dead_code)] impl Point { pub fn new(x: T, y: T, z: T) -> Self { Self { x, y, z } diff --git a/src/delaunay_core/triangulation_data_structure.rs b/src/delaunay_core/triangulation_data_structure.rs index 29e27c8..39c11ef 100644 --- a/src/delaunay_core/triangulation_data_structure.rs +++ b/src/delaunay_core/triangulation_data_structure.rs @@ -1,5 +1,3 @@ -#[allow(dead_code)] - pub fn tds() -> i32 { println!("Hello, world!"); 1 diff --git a/src/delaunay_core/vertex.rs b/src/delaunay_core/vertex.rs index 61bb36e..1bc96b1 100644 --- a/src/delaunay_core/vertex.rs +++ b/src/delaunay_core/vertex.rs @@ -1,20 +1,27 @@ use uuid::Uuid; +use std::option::Option; + use super::{point::Point, utilities::make_uuid}; -#[allow(dead_code)] #[derive(Debug)] pub struct Vertex { pub point: Point, pub uuid: Uuid, + pub incident_cell: Option, pub data: U, } -#[allow(dead_code)] impl Vertex { pub fn new(point: Point, data: U) -> Self { let uuid = make_uuid(); - Self { point, uuid, data } + let incident_cell = None; + Self { + point, + uuid, + incident_cell, + data, + } } } #[cfg(test)] @@ -29,7 +36,10 @@ mod tests { assert_eq!(vertex.point.x, 1.0); assert_eq!(vertex.point.y, 2.0); assert_eq!(vertex.point.z, 3.0); + assert_eq!(vertex.uuid.get_version_num(), 4); + println!("uuid version: {:?}\n", vertex.uuid.get_version_num()); assert_ne!(vertex.uuid, make_uuid()); + assert!(vertex.incident_cell.is_none()); assert_eq!(vertex.data, 3); } }