Skip to content

Commit

Permalink
Fix traits to be consistent across Vertex, Cell, Facet, Tds
Browse files Browse the repository at this point in the history
Also debug Bowyer-Watson. Still getting Singular matrices.
  • Loading branch information
acgetchell committed Jan 17, 2024
1 parent 9e7ba59 commit d55df6f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
nalgebra = "0.32.3"
num-traits = "0.2.17"
serde = { version = "1.0.194", features = ["derive"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = "1.0.111"
serde_test = "1.0.176"
uuid = { version = "1.6.1", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }
Expand Down
8 changes: 4 additions & 4 deletions src/delaunay_core/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use uuid::Uuid;
pub struct Cell<T: Clone + Copy + Default, U, V, const D: usize>
where
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
V: Clone + Copy,
U: Clone + Copy + PartialEq,
V: Clone + Copy + PartialEq,
{
/// The vertices of the cell.
pub vertices: Vec<Vertex<T, U, D>>,
Expand All @@ -47,8 +47,8 @@ where
for<'a> &'a T: Div<f64>,
f64: From<T>,
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
V: Clone + Copy,
U: Clone + Copy + PartialEq,
V: Clone + Copy + PartialEq,
{
/// The function `new` creates a new `Cell`` object with the given
/// vertices. A D-dimensional cell has D + 1 vertices, so the number of
Expand Down
6 changes: 3 additions & 3 deletions src/delaunay_core/facet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use serde::{de::DeserializeOwned, Deserialize, Serialize};
pub struct Facet<T: Clone + Copy + Default, U, V, const D: usize>
where
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
V: Clone + Copy,
U: Clone + Copy + PartialEq,
V: Clone + Copy + PartialEq,
{
/// The `Cell` that contains this facet.
pub cell: Cell<T, U, V, D>,
Expand All @@ -39,7 +39,7 @@ where
T: Copy + Default + PartialEq,
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy + PartialEq,
V: Clone + Copy,
V: Clone + Copy + PartialEq,
{
/// The `new` function is a constructor for the `Facet` struct. It takes
/// in a `Cell` and a `Vertex` as arguments and returns a `Result`
Expand Down
23 changes: 9 additions & 14 deletions src/delaunay_core/triangulation_data_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ use uuid::Uuid;
pub struct Tds<T: Clone + Copy + Default, U, V, const D: usize>
where
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
V: Clone + Copy,
U: Clone + Copy + PartialEq,
V: Clone + Copy + PartialEq,
{
/// A `HashMap` that stores vertices with their corresponding `Uuid`s as
/// keys. Each `Vertex` has a `Point` of type T, vertex data of type U,
Expand Down Expand Up @@ -267,15 +267,15 @@ where

// Create super-cell that contains all vertices
let supercell = self.supercell()?;
cells.push(supercell);
cells.push(supercell.clone());

// Iterate over vertices
for vertex in self.vertices.values() {
// Find cells that contain the vertex
let mut bad_cells: Vec<Cell<T, U, V, D>> = Vec::new();
for cell in cells.iter() {
// TODO: understand why we're getting singular matrices here
if cell.circumsphere_contains(*vertex).unwrap() {
if cell.circumsphere_contains(*vertex)? {
bad_cells.push((*cell).clone());
}
}
Expand All @@ -285,7 +285,7 @@ where
for cell in bad_cells.iter() {
// Create `Facet`s from the `Cell`
for vertex in cell.vertices.iter() {
let facet = Facet::new(cell.clone(), *vertex).unwrap();
let facet = Facet::new(cell.clone(), *vertex)?;
polygonal_hole.push(facet);
}

Expand Down Expand Up @@ -317,12 +317,8 @@ where
}

// Remove all cells containing vertices from the supercell
// TODO: Fix borrow-checker errors
// for cell in cells.iter_mut() {
// if cell.contains_vertex(supercell.vertices[0]) {
// cells.remove(cells.iter().position(|c| c == cell).unwrap());
// }
// }
cells
.retain(|c| !c.contains_vertex(supercell.vertices.clone().into_iter().next().unwrap()));

Ok(cells)
}
Expand Down Expand Up @@ -453,15 +449,14 @@ mod tests {
#[test]
fn tds_bowyer_watson() {
let points = vec![
Point::new([0.0, 0.0, 0.0]),
Point::new([1.0, 1.0, 1.0]),
Point::new([1.0, 0.0, 0.0]),
Point::new([0.0, 1.0, 0.0]),
Point::new([0.0, 0.0, 1.0]),
];
let mut tds: Tds<f64, usize, usize, 3> = Tds::new(points);
let cells = tds.bowyer_watson();
let unwrapped_cells =
cells.unwrap_or_else(|err| panic!("Error creating cells: {:?}!", err));
let unwrapped_cells = cells.unwrap_or_else(|err| panic!("Error creating cells: {:?}", err));

assert_eq!(unwrapped_cells.len(), 1);

Expand Down
2 changes: 1 addition & 1 deletion src/delaunay_core/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn find_extreme_coordinates<T, U, const D: usize>(
where
T: Clone + Copy + Default + PartialOrd,
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
U: Clone + Copy + PartialEq,
{
let mut min_coords = [Default::default(); D];

Expand Down
4 changes: 2 additions & 2 deletions src/delaunay_core/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use uuid::Uuid;
pub struct Vertex<T: Clone + Copy + Default, U, const D: usize>
where
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
U: Clone + Copy + PartialEq,
{
/// The coordinates of the vertex in a D-dimensional space.
pub point: Point<T, D>,
Expand All @@ -40,7 +40,7 @@ where
impl<T: Clone + Copy + Default, U, const D: usize> Vertex<T, U, D>
where
[T; D]: Default + DeserializeOwned + Serialize + Sized,
U: Clone + Copy,
U: Clone + Copy + PartialEq,
{
/// The function creates a new instance of a `Vertex`.
///
Expand Down

0 comments on commit d55df6f

Please sign in to comment.