#![forbid(unsafe_code)]
pub use crate::core::algorithms::flips::{
BistellarFlipKind, FlipDirection, FlipError, FlipInfo, RidgeHandle, TriangleHandle,
};
pub use crate::core::edge::EdgeKey;
pub use crate::core::facet::FacetHandle;
pub use crate::core::triangulation_data_structure::{CellKey, VertexKey};
use crate::core::algorithms::flips::{
apply_bistellar_flip_dynamic, apply_bistellar_flip_k1, apply_bistellar_flip_k1_inverse,
apply_bistellar_flip_k2, apply_bistellar_flip_k3, build_k2_flip_context,
build_k2_flip_context_from_edge, build_k3_flip_context, build_k3_flip_context_from_triangle,
};
use crate::core::delaunay_triangulation::DelaunayTriangulation;
use crate::core::traits::data_type::DataType;
use crate::core::triangulation::Triangulation;
use crate::core::vertex::Vertex;
use crate::geometry::kernel::Kernel;
pub trait BistellarFlips<K, U, V, const D: usize>
where
K: Kernel<D>,
U: DataType,
V: DataType,
{
fn flip_k1_insert(
&mut self,
cell_key: CellKey,
vertex: Vertex<K::Scalar, U, D>,
) -> Result<FlipInfo<D>, FlipError>;
fn flip_k1_remove(&mut self, vertex_key: VertexKey) -> Result<FlipInfo<D>, FlipError>;
fn flip_k2(&mut self, facet: FacetHandle) -> Result<FlipInfo<D>, FlipError>;
fn flip_k3(&mut self, ridge: RidgeHandle) -> Result<FlipInfo<D>, FlipError>;
fn flip_k2_inverse_from_edge(&mut self, edge: EdgeKey) -> Result<FlipInfo<D>, FlipError>;
fn flip_k3_inverse_from_triangle(
&mut self,
triangle: TriangleHandle,
) -> Result<FlipInfo<D>, FlipError>;
}
impl<K, U, V, const D: usize> BistellarFlips<K, U, V, D> for Triangulation<K, U, V, D>
where
K: Kernel<D>,
U: DataType,
V: DataType,
{
fn flip_k1_insert(
&mut self,
cell_key: CellKey,
vertex: Vertex<K::Scalar, U, D>,
) -> Result<FlipInfo<D>, FlipError> {
apply_bistellar_flip_k1(&mut self.tds, cell_key, vertex)
}
fn flip_k1_remove(&mut self, vertex_key: VertexKey) -> Result<FlipInfo<D>, FlipError> {
apply_bistellar_flip_k1_inverse(&mut self.tds, vertex_key)
}
fn flip_k2(&mut self, facet: FacetHandle) -> Result<FlipInfo<D>, FlipError> {
let context = build_k2_flip_context(&self.tds, facet)?;
apply_bistellar_flip_k2(&mut self.tds, &context)
}
fn flip_k3(&mut self, ridge: RidgeHandle) -> Result<FlipInfo<D>, FlipError> {
let context = build_k3_flip_context(&self.tds, ridge)?;
apply_bistellar_flip_k3(&mut self.tds, &context)
}
fn flip_k2_inverse_from_edge(&mut self, edge: EdgeKey) -> Result<FlipInfo<D>, FlipError> {
let context = build_k2_flip_context_from_edge(&self.tds, edge)?;
apply_bistellar_flip_dynamic(&mut self.tds, D, &context)
}
fn flip_k3_inverse_from_triangle(
&mut self,
triangle: TriangleHandle,
) -> Result<FlipInfo<D>, FlipError> {
if D < 4 {
return Err(FlipError::UnsupportedDimension { dimension: D });
}
let context = build_k3_flip_context_from_triangle(&self.tds, triangle)?;
let k_move = D
.checked_sub(1)
.ok_or(FlipError::UnsupportedDimension { dimension: D })?;
apply_bistellar_flip_dynamic(&mut self.tds, k_move, &context)
}
}
impl<K, U, V, const D: usize> BistellarFlips<K, U, V, D> for DelaunayTriangulation<K, U, V, D>
where
K: Kernel<D>,
U: DataType,
V: DataType,
{
fn flip_k1_insert(
&mut self,
cell_key: CellKey,
vertex: Vertex<K::Scalar, U, D>,
) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k1_insert(cell_key, vertex)
}
fn flip_k1_remove(&mut self, vertex_key: VertexKey) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k1_remove(vertex_key)
}
fn flip_k2(&mut self, facet: FacetHandle) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k2(facet)
}
fn flip_k3(&mut self, ridge: RidgeHandle) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k3(ridge)
}
fn flip_k2_inverse_from_edge(&mut self, edge: EdgeKey) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k2_inverse_from_edge(edge)
}
fn flip_k3_inverse_from_triangle(
&mut self,
triangle: TriangleHandle,
) -> Result<FlipInfo<D>, FlipError> {
self.tri.flip_k3_inverse_from_triangle(triangle)
}
}