use std::fmt;
use crate::ids::{HalfEdgeId, VertexId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TopologyError {
InvalidHalfEdge(HalfEdgeId),
FlipOnBoundaryEdge(HalfEdgeId),
CollapseOnBoundaryEdge(HalfEdgeId),
NoTwin(HalfEdgeId),
NoFace(HalfEdgeId),
DegenerateTriangle,
LinkConditionViolated { a: VertexId, b: VertexId },
Inconsistent(String),
}
impl fmt::Display for TopologyError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidHalfEdge(h) => write!(f, "无效半边句柄 {:?}", h),
Self::FlipOnBoundaryEdge(h) => write!(f, "禁止翻转边界边 {:?}", h),
Self::CollapseOnBoundaryEdge(h) => write!(f, "禁止折叠边界边 {:?}", h),
Self::NoTwin(h) => write!(f, "半边 {:?} 没有 twin", h),
Self::NoFace(h) => write!(f, "半边 {:?} 两侧均无面", h),
Self::DegenerateTriangle => write!(f, "操作会产生退化三角形"),
Self::LinkConditionViolated { a, b } => {
write!(f, "链接条件不满足:折叠 {:?}-{:?} 会产生非流形", a, b)
}
Self::Inconsistent(msg) => write!(f, "网格拓扑不一致:{}", msg),
}
}
}
impl std::error::Error for TopologyError {}