Skip to main content

jagua_rs/geometry/primitives/
error.rs

1use crate::geometry::primitives::Point;
2
3/// Why a geometric primitive could not be constructed.
4///
5/// The constructors of [`SPolygon`](super::SPolygon), [`Rect`](super::Rect),
6/// [`Circle`](super::Circle), and [`Edge`](super::Edge) return it inside an [`anyhow::Error`];
7/// recover it with [`anyhow::Error::downcast_ref`], for example to point at the offending input.
8#[derive(Debug, Clone, Copy, PartialEq, thiserror::Error)]
9pub enum GeometryError {
10    #[error("simple polygon must have at least 3 points, it has {0}")]
11    TooFewPoints(usize),
12    /// The indices of two equal points.
13    #[error("simple polygon contains duplicate points {0} and {1}")]
14    DuplicatePoints(usize, usize),
15    /// The indices of two edges that intersect; edge `i` runs from point `i` to point `i + 1`,
16    /// and the last edge closes the polygon.
17    #[error("simple polygon contains intersecting edges {0} and {1}")]
18    IntersectingEdges(usize, usize),
19    #[error("simple polygon has no area")]
20    NoArea,
21    #[error("invalid rectangle, x_min: {x_min}, x_max: {x_max}, y_min: {y_min}, y_max: {y_max}")]
22    InvalidRect {
23        x_min: f32,
24        y_min: f32,
25        x_max: f32,
26        y_max: f32,
27    },
28    #[error("invalid circle, center: {center:?}, radius: {radius}")]
29    InvalidCircle { center: Point, radius: f32 },
30    #[error("degenerate edge, {0:?} == {0:?}")]
31    DegenerateEdge(Point),
32}