Skip to content

Commit

Permalink
feat: Add functions to refactor Bowyer-Watson
Browse files Browse the repository at this point in the history
  • Loading branch information
acgetchell committed Aug 22, 2024
1 parent 0f7a2c0 commit e603652
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 23 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ edition = "2021"
[dependencies]
nalgebra = "0.33.0"
num-traits = "0.2.19"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.121"
serde_test = "1.0.176"
serde = { version = "1.0.208", features = ["derive"] }
serde_json = "1.0.125"
serde_test = "1.0.177"
uuid = { version = "1.10.0", features = ["v4", "fast-rng", "macro-diagnostics", "serde"] }

[lints.rust]
Expand Down
60 changes: 58 additions & 2 deletions src/delaunay_core/cell.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Data and operations on d-dimensional cells or [simplices](https://en.wikipedia.org/wiki/Simplex).

use super::{point::Point, utilities::make_uuid, vertex::Vertex};
use super::{facet::Facet, point::Point, utilities::make_uuid, vertex::Vertex};
use na::{ComplexField, Const, OPoint};
use nalgebra as na;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
Expand Down Expand Up @@ -215,7 +215,7 @@ where
///
/// # Arguments:
///
/// * [Vertex]: The vertex to check.
/// * vertex: The [Vertex] to check.
///
/// # Returns:
///
Expand Down Expand Up @@ -382,6 +382,62 @@ where

Ok(circumradius >= radius)
}

/// The function `facets` returns the [Facet]s of the [Cell].
///
/// # Example
///
/// ```
/// use d_delaunay::delaunay_core::cell::Cell;
/// use d_delaunay::delaunay_core::vertex::Vertex;
/// use d_delaunay::delaunay_core::point::Point;
/// use d_delaunay::delaunay_core::facet::Facet;
/// 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").unwrap();
/// let facets = cell.facets();
/// assert_eq!(facets.len(), 4);
pub fn facets(&self) -> Vec<Facet<T, U, V, D>> {
let mut facets: Vec<Facet<T, U, V, D>> = Vec::new();
for vertex in self.vertices.iter() {
facets.push(Facet::new(self.clone(), *vertex).unwrap());
}

facets
}

/// The function `contains_facet` checks if a given [Facet] is present in
/// the [Cell].
///
/// # Arguments:
///
/// * facet: The [Facet] to check.
///
/// # Returns:
///
/// Returns `true` if the given [Facet] is present in the [Cell], and
/// `false` otherwise.
///
/// # Example
///
/// ```
/// use d_delaunay::delaunay_core::cell::Cell;
/// use d_delaunay::delaunay_core::facet::Facet;
/// use d_delaunay::delaunay_core::vertex::Vertex;
/// use d_delaunay::delaunay_core::point::Point;
/// 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").unwrap();
/// let facet = Facet::new(cell.clone(), vertex1).unwrap();
/// assert!(cell.contains_facet(facet));
/// ```
pub fn contains_facet(&self, facet: Facet<T, U, V, D>) -> bool {
self.facets().contains(&facet)
}
}

/// Equality of cells is based on equality of sorted vector of vertices.
Expand Down

0 comments on commit e603652

Please sign in to comment.