Skip to content

Commit

Permalink
Add incident_cell to Vertex and neighbors to Cells
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acgetchell committed Dec 15, 2023
1 parent 10cc4bd commit 0b137ab
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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].

Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"acgetchell",
"CGAL",
"clippy",
"codecov",
"Voronoi"
],
"ignoreWords": [],
Expand Down
10 changes: 6 additions & 4 deletions src/delaunay_core/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ use uuid::Uuid;

use super::{utilities::make_uuid, vertex::Vertex};

#[allow(dead_code)]
#[derive(Debug)]
struct Cell<T, U, V> {
pub struct Cell<T, U, V> {
pub vertices: Vec<Vertex<U, V>>,
uuid: Uuid,
pub uuid: Uuid,
pub neighbors: Option<Vec<Uuid>>,
pub data: T,
}

#[allow(dead_code)]
impl<T, U, V> Cell<T, U, V> {
pub fn new(vertices: Vec<Vertex<U, V>>, data: T) -> Self {
let uuid = make_uuid();
let neighbors = None;
Cell {
vertices,
uuid,
neighbors,
data,
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/delaunay_core/point.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#[allow(dead_code)]
#[derive(Debug)]
pub struct Point<T> {
pub x: T,
pub y: T,
pub z: T,
}

#[allow(dead_code)]
impl<T> Point<T> {
pub fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
Expand Down
2 changes: 0 additions & 2 deletions src/delaunay_core/triangulation_data_structure.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[allow(dead_code)]

pub fn tds() -> i32 {
println!("Hello, world!");
1
Expand Down
16 changes: 13 additions & 3 deletions src/delaunay_core/vertex.rs
Original file line number Diff line number Diff line change
@@ -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<T, U> {
pub point: Point<T>,
pub uuid: Uuid,
pub incident_cell: Option<Uuid>,
pub data: U,
}

#[allow(dead_code)]
impl<T, U> Vertex<T, U> {
pub fn new(point: Point<T>, data: U) -> Self {
let uuid = make_uuid();
Self { point, uuid, data }
let incident_cell = None;
Self {
point,
uuid,
incident_cell,
data,
}
}
}
#[cfg(test)]
Expand All @@ -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);
}
}

0 comments on commit 0b137ab

Please sign in to comment.