|
1 | 1 | use crate::float_types::Real; |
2 | 2 | use nalgebra::Point3; |
3 | 3 |
|
| 4 | +/// Coordinate validation failure for a single point. |
| 5 | +#[derive(Clone, Debug, thiserror::Error, PartialEq)] |
| 6 | +pub enum PointError { |
| 7 | + #[error("point {0:?} has NaN fields")] |
| 8 | + NaN(Point3<Real>), |
| 9 | + #[error("point {0:?} has infinite fields")] |
| 10 | + Infinite(Point3<Real>), |
| 11 | +} |
| 12 | + |
4 | 13 | /// All the possible validation issues we might encounter, |
5 | | -#[derive(Debug, Clone, PartialEq)] |
| 14 | +#[derive(Debug, Clone, thiserror::Error, PartialEq)] |
| 15 | +#[non_exhaustive] |
6 | 16 | pub enum ValidationError { |
7 | 17 | /// (RepeatedPoint) Two consecutive coords are identical |
| 18 | + #[error("point {0:?} is repeated consecutively")] |
8 | 19 | RepeatedPoint(Point3<Real>), |
9 | 20 | /// (HoleOutsideShell) A hole is *not* contained by its outer shell |
| 21 | + #[error("hole is not contained by its outer shell near {0:?}")] |
10 | 22 | HoleOutsideShell(Point3<Real>), |
11 | 23 | /// (NestedHoles) A hole is nested inside another hole |
| 24 | + #[error("hole is nested inside another hole near {0:?}")] |
12 | 25 | NestedHoles(Point3<Real>), |
13 | 26 | /// (DisconnectedInterior) The interior is disconnected |
| 27 | + #[error("interior is disconnected near {0:?}")] |
14 | 28 | DisconnectedInterior(Point3<Real>), |
15 | 29 | /// (SelfIntersection) A polygon self‐intersects |
| 30 | + #[error("polygon self-intersects near {0:?}")] |
16 | 31 | SelfIntersection(Point3<Real>), |
17 | 32 | /// (RingSelfIntersection) A linear ring has a self‐intersection |
| 33 | + #[error("linear ring self-intersects near {0:?}")] |
18 | 34 | RingSelfIntersection(Point3<Real>), |
19 | 35 | /// (NestedShells) Two outer shells are nested incorrectly |
| 36 | + #[error("outer shells are nested incorrectly near {0:?}")] |
20 | 37 | NestedShells(Point3<Real>), |
21 | 38 | /// (TooFewPoints) A ring or line has fewer than the minimal #points |
| 39 | + #[error("ring or line has too few points near {0:?}")] |
22 | 40 | TooFewPoints(Point3<Real>), |
23 | 41 | /// (InvalidCoordinate) The coordinate has a NaN or infinite |
| 42 | + #[error("invalid coordinate {0:?}")] |
24 | 43 | InvalidCoordinate(Point3<Real>), |
| 44 | + /// A more precise invalid-coordinate report. |
| 45 | + #[error(transparent)] |
| 46 | + PointError(#[from] PointError), |
25 | 47 | /// (RingNotClosed) The ring's first/last points differ |
| 48 | + #[error("ring is not closed near {0:?}")] |
26 | 49 | RingNotClosed(Point3<Real>), |
27 | 50 | /// (MismatchedVertices) operation requires polygons with same number of vertices |
| 51 | + #[error("operation requires polygons with the same number of vertices")] |
28 | 52 | MismatchedVertices, |
| 53 | + /// Operation requires polygons with the same number of vertices. |
| 54 | + #[error("operation requires polygons with the same number of vertices, {left} != {right}")] |
| 55 | + MismatchedVertexCount { left: usize, right: usize }, |
29 | 56 | /// (IndexOutOfRange) operation requires polygons with same number of vertices |
| 57 | + #[error("index out of range")] |
30 | 58 | IndexOutOfRange, |
| 59 | + /// A required index is outside a collection. |
| 60 | + #[error("index {index} is out of range for length {len}")] |
| 61 | + IndexOutOfRangeWithLen { index: usize, len: usize }, |
31 | 62 | /// (InvalidArguments) operation requires polygons with same number of vertices |
| 63 | + #[error("invalid arguments")] |
32 | 64 | InvalidArguments, |
| 65 | + /// A named integer field is below the supported minimum. |
| 66 | + #[error("{name} must not be less than {min}")] |
| 67 | + FieldLessThan { name: &'static str, min: i32 }, |
| 68 | + /// A named real field is below the supported minimum. |
| 69 | + #[error("{name} must not be less than {min}")] |
| 70 | + FieldLessThanFloat { name: &'static str, min: Real }, |
| 71 | + /// An inconsistency while building a triangle mesh. |
| 72 | + #[error("triangle mesh builder error: {0}")] |
| 73 | + TriMeshError(String), |
33 | 74 | /// In general, anything else |
| 75 | + #[error("{0}")] |
34 | 76 | Other(String, Option<Point3<Real>>), |
35 | 77 | } |
36 | 78 |
|
|
0 commit comments