lyon_tessellation/
error.rs1pub type TessellationResult = Result<(), TessellationError>;
3
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
6pub enum GeometryBuilderError {
7 InvalidVertex,
8 TooManyVertices,
9}
10
11#[cfg(feature = "std")]
12impl core::fmt::Display for GeometryBuilderError {
13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 match self {
15 GeometryBuilderError::InvalidVertex => {
16 std::write!(f, "Invalid vertex")
17 },
18 GeometryBuilderError::TooManyVertices => {
19 std::write!(f, "Too many vertices")
20 }
21 }
22 }
23}
24
25#[cfg(feature = "std")]
26impl std::error::Error for GeometryBuilderError {}
27
28#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
33pub enum InternalError {
34 IncorrectActiveEdgeOrder(i16),
35 InsufficientNumberOfSpans,
36 InsufficientNumberOfEdges,
37 MergeVertexOutside,
38 InvalidNumberOfEdgesBelowVertex,
39 ErrorCode(i16),
43}
44
45impl InternalError {
46 pub(crate) fn intersections_disabled() -> Self {
47 InternalError::ErrorCode(1)
48 }
49}
50
51#[cfg(feature = "std")]
52impl core::fmt::Display for InternalError {
53 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
54 match self {
55 InternalError::IncorrectActiveEdgeOrder(i) => {
56 std::write!(f, "Incorrect active edge order ({i})")
57 },
58 InternalError::InsufficientNumberOfSpans => {
59 std::write!(f, "Insufficient number of spans")
60 },
61 InternalError::InsufficientNumberOfEdges => {
62 std::write!(f, "Insufficient number of edges")
63 },
64 InternalError::MergeVertexOutside => {
65 std::write!(f, "Merge vertex is outside of the shape")
66 },
67 InternalError::InvalidNumberOfEdgesBelowVertex => {
68 std::write!(f, "Unexpected number of edges below a vertex")
69 },
70 InternalError::ErrorCode(i) => {
71 std::write!(f, "Error code: #{i}")
72 },
73 }
74 }
75}
76
77#[cfg(feature = "std")]
78impl std::error::Error for InternalError {}
79
80#[derive(Clone, Debug, PartialEq)]
82pub enum TessellationError {
83 UnsupportedParamater(UnsupportedParamater),
85 GeometryBuilder(GeometryBuilderError),
86 Internal(InternalError),
87}
88
89#[cfg(feature = "std")]
90impl core::fmt::Display for TessellationError {
91 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
92 match self {
93 TessellationError::UnsupportedParamater(e) => {
94 std::write!(f, "Unsupported parameter: {e}")
95 },
96 TessellationError::GeometryBuilder(e) => {
97 std::write!(f, "Geometry builder error: {e}")
98 },
99 TessellationError::Internal(e) => {
100 std::write!(f, "Internal error: {e}")
101 },
102 }
103 }
104}
105
106#[cfg(feature = "std")]
107impl std::error::Error for TessellationError {}
108
109impl core::convert::From<GeometryBuilderError> for TessellationError {
110 fn from(value: GeometryBuilderError) -> Self {
111 Self::GeometryBuilder(value)
112 }
113}
114
115impl core::convert::From<InternalError> for TessellationError {
116 fn from(value: InternalError) -> Self {
117 Self::Internal(value)
118 }
119}
120
121#[derive(Clone, Debug, PartialEq)]
122pub enum UnsupportedParamater {
123 PositionIsNaN,
124 ToleranceIsNaN,
125}
126
127#[cfg(feature = "std")]
128impl core::fmt::Display for UnsupportedParamater {
129 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
130 match self {
131 UnsupportedParamater::PositionIsNaN => {
132 std::write!(f, "Position is not a number")
133 },
134 UnsupportedParamater::ToleranceIsNaN => {
135 std::write!(f, "Tolerance threshold is not a number")
136 },
137 }
138 }
139}
140
141#[cfg(feature = "std")]
142impl std::error::Error for UnsupportedParamater {}