1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
use core::fmt;
/// Errors returned by `manifold-knn` construction, update, and query APIs.
#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Error {
/// Number of points and number of successor lists differ.
TableLengthMismatch {
/// Number of points.
points: usize,
/// Number of successor lists.
lists: usize,
},
/// A point coordinate is `NaN` or infinite.
NonFiniteCoordinate {
/// Point index.
point: usize,
/// Coordinate index inside the point.
coordinate: usize,
/// Invalid coordinate value.
value: f64,
},
/// A query coordinate is `NaN` or infinite.
NonFiniteQuery {
/// Coordinate index inside the query.
coordinate: usize,
/// Invalid coordinate value.
value: f64,
},
/// Prefix length exceeds the number of stored points.
InvalidPrefix {
/// Requested prefix length.
prefix_len: usize,
/// Number of stored points.
len: usize,
},
/// A point index is out of bounds.
InvalidIndex {
/// Requested index.
index: usize,
/// Number of stored points or lists.
len: usize,
},
/// A successor edge is invalid. Successors must satisfy `owner < successor < len`.
InvalidSuccessor {
/// Owner list index.
owner: usize,
/// Successor index.
successor: usize,
/// Number of stored points or lists.
len: usize,
},
/// A successor list is not sorted.
UnsortedSuccessorList {
/// Owner list index.
owner: usize,
/// Previous entry.
previous: usize,
/// Current out-of-order entry.
current: usize,
},
/// A successor list contains a duplicate entry.
DuplicateSuccessor {
/// Owner list index.
owner: usize,
/// Duplicated successor index.
successor: usize,
},
/// An insertion-time neighbor is not an earlier birth index.
InvalidInsertionNeighbor {
/// Index of the point being inserted.
inserted: usize,
/// Invalid neighbor index.
neighbor: usize,
},
/// An operation requires an active point, but the point is inactive.
InactivePoint {
/// Inactive point index.
index: usize,
},
/// The optional Delaunay backend returned an error.
DelaunayKernel {
/// Delaunay operation that failed.
operation: &'static str,
/// Backend error message.
message: String,
},
/// The Delaunay backend produced an internally inconsistent state.
DelaunayInvariant {
/// Human-readable invariant violation.
message: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::TableLengthMismatch { points, lists } => write!(
formatter,
"successor table length mismatch: {points} points but {lists} lists"
),
Error::NonFiniteCoordinate {
point,
coordinate,
value,
} => write!(
formatter,
"point {point} has non-finite coordinate {coordinate}: {value}"
),
Error::NonFiniteQuery { coordinate, value } => write!(
formatter,
"query has non-finite coordinate {coordinate}: {value}"
),
Error::InvalidPrefix { prefix_len, len } => write!(
formatter,
"invalid prefix length {prefix_len}; index contains {len} points"
),
Error::InvalidIndex { index, len } => {
write!(formatter, "index {index} out of bounds for length {len}")
}
Error::InvalidSuccessor {
owner,
successor,
len,
} => write!(
formatter,
"invalid successor edge {owner} -> {successor}; expected owner < successor < {len}"
),
Error::UnsortedSuccessorList {
owner,
previous,
current,
} => write!(
formatter,
"successor list {owner} is not sorted: {previous} appears before {current}"
),
Error::DuplicateSuccessor { owner, successor } => write!(
formatter,
"successor list {owner} contains duplicate successor {successor}"
),
Error::InvalidInsertionNeighbor { inserted, neighbor } => write!(
formatter,
"invalid insertion neighbor {neighbor} for inserted point {inserted}; \
expected neighbor < inserted"
),
Error::InactivePoint { index } => write!(formatter, "point {index} is inactive"),
Error::DelaunayKernel { operation, message } => {
write!(
formatter,
"Delaunay backend failed during {operation}: {message}"
)
}
Error::DelaunayInvariant { message } => {
write!(formatter, "Delaunay backend invariant violation: {message}")
}
}
}
}
impl std::error::Error for Error {}