use thiserror::Error;
#[derive(Debug, Clone, PartialEq, Error)]
pub enum InputError {
#[error("input is empty")]
Empty,
#[error("non-finite coordinate at vertex {index}")]
NonFiniteCoordinate { index: usize },
#[error("vertex index {index} out of range (vertex count {vertex_count})")]
VertexIndexOutOfRange { index: usize, vertex_count: usize },
#[error("edge {edge} is degenerate (zero length) between vertices {v0} and {v1}")]
ZeroLengthEdge { edge: usize, v0: usize, v1: usize },
#[error("edge {edge} has non-positive weight {weight}")]
NonPositiveWeight { edge: usize, weight: f64 },
#[error("duplicate consecutive vertices in ring {ring} at offset {offset}")]
DuplicateConsecutiveVertices { ring: usize, offset: usize },
#[error("self-intersecting or improperly nested rings (edge {e0} vs {e1})")]
CrossingConstraints { e0: usize, e1: usize },
#[error("hole {hole} is not strictly inside the exterior")]
HoleOutsideExterior { hole: usize },
#[error("duplicate input edge between vertices {v0} and {v1}")]
DuplicateEdge { v0: usize, v1: usize },
#[error("ring {ring} has fewer than 3 distinct vertices")]
RingTooSmall { ring: usize },
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum TriangulationError {
#[error("CDT vertex insertion failed at input vertex {index}")]
VertexInsertion { index: usize },
#[error("constraint for input edge {edge} was split or lost during CDT")]
ConstraintSplitOrLost { edge: usize },
#[error("requested component {index} does not exist ({count} components)")]
ComponentOutOfRange { index: usize, count: usize },
#[error("failed to classify planar regions")]
RegionClassification,
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum PropagationError {
#[error("inconsistent event for triangle {triangle:?} at time {time}")]
InconsistentEvent { triangle: u64, time: f64 },
#[error("non-advancing event loop detected (component {component}, time {time})")]
NonAdvancingLoop { component: usize, time: f64 },
#[error("topology invariant violated: {detail}")]
TopologyInvariant { detail: String },
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum SkeletonError {
#[error(transparent)]
Input(#[from] InputError),
#[error(transparent)]
Triangulation(#[from] TriangulationError),
#[error(transparent)]
Propagation(#[from] PropagationError),
#[error("non-manifold topology while building DCEL: {detail}")]
NonManifoldTopology { detail: String },
#[error("incomplete DCEL face cycle: {detail}")]
IncompleteFaceCycle { detail: String },
#[error("offset construction failed at time {time}: {detail}")]
Offset { time: f64, detail: String },
}