-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use uuid to identify cells and vertices
- Added the `uuid` crate as a dependency in `Cargo.toml` - Updated the `Cell` struct in `cell.rs` to include a `uuid` field of type `Uuid` - Modified the constructor of `Cell` in `cell.rs` to generate a unique UUID for each cell - Added a new module called `point.rs` in the `delaunay_core` module, which defines a generic point struct - Added a new module called `utilities.rs` in the `delaunay_core` module, which includes a function to generate UUIDs - Updated the constructor of `Vertex` in `vertex.rs` to generate a unique UUID for each vertex - Added tests for the new code changes
- Loading branch information
1 parent
885f1d4
commit ebc1c61
Showing
7 changed files
with
192 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,50 @@ | ||
use crate::delaunay_core::vertex::Vertex; | ||
use uuid::Uuid; | ||
|
||
use super::{utilities::make_uuid, vertex::Vertex}; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
struct Cell<T, U, V> { | ||
pub vertices: Vec<Vertex<U, V>>, | ||
index: usize, | ||
uuid: Uuid, | ||
pub data: T, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl<T, U, V> Cell<T, U, V> { | ||
pub fn new(vertices: Vec<Vertex<U, V>>, index: usize, data: T) -> Self { | ||
pub fn new(vertices: Vec<Vertex<U, V>>, data: T) -> Self { | ||
let uuid = make_uuid(); | ||
Cell { | ||
vertices, | ||
index, | ||
uuid, | ||
data, | ||
} | ||
} | ||
|
||
pub fn number_of_vertices(&self) -> usize { | ||
self.vertices.len() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use crate::delaunay_core::point::Point; | ||
|
||
use super::*; | ||
#[test] | ||
fn make_cell() { | ||
use crate::delaunay_core::cell::Cell; | ||
use crate::delaunay_core::vertex::Vertex; | ||
let vertex1 = Vertex::new( | ||
crate::delaunay_core::vertex::Point::new(1.0, 2.0, 3.0), | ||
0, | ||
3, | ||
); | ||
let cell = Cell::new(vec![vertex1], 5, 10); | ||
let vertex1 = Vertex::new(Point::new(1.0, 2.0, 3.0), 3); | ||
let cell = Cell::new(vec![vertex1], 10); | ||
println!("{:?}", cell); | ||
assert_eq!(cell.vertices[0].point.x, 1.0); | ||
assert_eq!(cell.vertices[0].point.y, 2.0); | ||
assert_eq!(cell.vertices[0].point.z, 3.0); | ||
assert_eq!(cell.vertices[0].index, 0); | ||
assert_ne!(cell.vertices[0].uuid, make_uuid()); | ||
assert_eq!(cell.vertices[0].data, 3); | ||
assert_eq!(cell.index, 5); | ||
assert_eq!(cell.number_of_vertices(), 1); | ||
assert_ne!(cell.uuid, make_uuid()); | ||
assert_ne!(cell.uuid, cell.vertices[0].uuid); | ||
assert_eq!(cell.data, 10); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use uuid::Uuid; | ||
|
||
pub fn make_uuid() -> Uuid { | ||
Uuid::new_v4() | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_uuid() { | ||
let uuid = make_uuid(); | ||
println!("make_uuid = {:?}", uuid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,35 @@ | ||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub struct Point<T> { | ||
pub x: T, | ||
pub y: T, | ||
pub z: T, | ||
} | ||
use uuid::Uuid; | ||
|
||
#[allow(dead_code)] | ||
impl<T> Point<T> { | ||
pub fn new(x: T, y: T, z: T) -> Self { | ||
Self { x, y, z } | ||
} | ||
} | ||
use super::{point::Point, utilities::make_uuid}; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub struct Vertex<T, U> { | ||
pub point: Point<T>, | ||
pub index: usize, | ||
pub uuid: Uuid, | ||
pub data: U, | ||
} | ||
|
||
#[allow(dead_code)] | ||
impl<T, U> Vertex<T, U> { | ||
pub fn new(point: Point<T>, index: usize, data: U) -> Self { | ||
Self { point, index, data } | ||
pub fn new(point: Point<T>, data: U) -> Self { | ||
let uuid = make_uuid(); | ||
Self { point, uuid, data } | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn make_vertex() { | ||
use crate::delaunay_core::vertex::Vertex; | ||
|
||
let vertex = Vertex::new( | ||
crate::delaunay_core::vertex::Point::new(1.0, 2.0, 3.0), | ||
0, | ||
3, | ||
); | ||
let vertex = Vertex::new(Point::new(1.0, 2.0, 3.0), 3); | ||
println!("{:?}", vertex); | ||
assert_eq!(vertex.point.x, 1.0); | ||
assert_eq!(vertex.point.y, 2.0); | ||
assert_eq!(vertex.point.z, 3.0); | ||
assert_eq!(vertex.index, 0); | ||
assert_ne!(vertex.uuid, make_uuid()); | ||
assert_eq!(vertex.data, 3); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters