Skip to main content

smooth_frame/errors/
mod.rs

1use std::error::Error;
2use std::fmt;
3
4/// 几何计算错误。
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SmoothError {
7    /// 输入包含 `NaN` 或不允许的无穷值。
8    NonFiniteInput,
9    /// 长度、半径或限制为负数。
10    NegativeInput,
11    /// 角点方向向量长度过小。
12    DegenerateAxis,
13    /// 角点夹角不在开区间 `(0, PI)` 内。
14    InvalidAngle,
15    /// 闭合 frame 少于 3 个点。
16    TooFewPoints,
17    /// frame 包含退化边、共线点或面积为零。
18    DegenerateFrame,
19    /// frame 存在凹角,当前版本暂不支持。
20    ConcaveFrame,
21    /// frame 存在自相交边。
22    SelfIntersectingFrame,
23}
24
25impl fmt::Display for SmoothError {
26    // 将几何错误转换为面向调用方的中文错误信息。
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            SmoothError::NonFiniteInput => write!(f, "输入包含非有限数值"),
30            SmoothError::NegativeInput => write!(f, "长度、半径或限制不能为负数"),
31            SmoothError::DegenerateAxis => write!(f, "角点方向向量退化"),
32            SmoothError::InvalidAngle => write!(f, "角点角度必须满足 0 < phi < PI"),
33            SmoothError::TooFewPoints => write!(f, "闭合 frame 至少需要 3 个点"),
34            SmoothError::DegenerateFrame => write!(f, "frame 包含退化边或面积为零"),
35            SmoothError::ConcaveFrame => write!(f, "当前版本仅支持凸 frame"),
36            SmoothError::SelfIntersectingFrame => write!(f, "当前版本不支持自相交 frame"),
37        }
38    }
39}
40
41impl Error for SmoothError {}