honeycomb_kernels/splits/
mod.rs

1//! Cell splitting functions
2//!
3//! This module contains implementations of cell splitting methods. We currently define
4//! two edge-splitting methods, depending on the number of splits done. Both functions
5//! have "no-alloc" variants: these take additional darts as argument in order not to
6//! allocate darts during the process.
7
8mod edge_multiple;
9mod edge_single;
10
11pub use edge_multiple::{splitn_edge, splitn_edge_transac};
12pub use edge_single::{split_edge, split_edge_transac};
13
14use honeycomb_core::{
15    attributes::AttributeError,
16    cmap::{LinkError, SewError},
17};
18
19/// Error-modeling enum for edge-splitting routines.
20#[derive(thiserror::Error, Debug, PartialEq, Eq)]
21pub enum SplitEdgeError {
22    /// A core operation failed.
23    #[error("core operation failed: {0}")]
24    FailedCoreOp(#[from] SewError),
25    /// Relative position of the new vertex isn't located on the edge.
26    #[error("vertex placement for split is not in ]0;1[")]
27    VertexBound,
28    /// One or both vertices of the edge are undefined.
29    #[error("edge isn't defined correctly")]
30    UndefinedEdge,
31    /// Darts passed to the function do not match requirements.
32    #[error("passed darts should be free & non-null - {0}")]
33    InvalidDarts(&'static str),
34    /// The number of darts passed to create the new segments is too low. The `usize` value
35    /// is the number of missing darts.
36    #[error("wrong # of darts - expected `{0}`, got {1}")]
37    WrongAmountDarts(usize, usize),
38}
39
40impl From<LinkError> for SplitEdgeError {
41    fn from(value: LinkError) -> Self {
42        Self::FailedCoreOp(value.into())
43    }
44}
45
46impl From<AttributeError> for SplitEdgeError {
47    fn from(value: AttributeError) -> Self {
48        Self::FailedCoreOp(value.into())
49    }
50}
51
52#[cfg(test)]
53mod tests;