Skip to main content

connector_routing/
error.rs

1//! The crate's [`Error`] type.
2
3use core::fmt;
4
5use crate::geom::Point;
6
7/// Why an operation failed.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum Error {
11    /// A coordinate lies outside `[-MAX_COORD, MAX_COORD]`
12    /// ([`MAX_COORD`](crate::MAX_COORD)).
13    CoordinateOutOfRange(Point),
14    /// An obstacle id does not name a live obstacle.
15    UnknownObstacle,
16    /// A port id does not name a live port.
17    UnknownPort,
18    /// A port lies in the open interior of an obstacle, so no route can reach it.
19    PortBlocked(Point),
20    /// A port allows no direction.
21    PortWithoutDirections(Point),
22    /// No route exists between the two ports of a connector.
23    NoRoute {
24        /// The index of the connector in the request.
25        connector: usize,
26    },
27    /// A cost product or sum does not fit into `u64`.
28    CostOverflow,
29    /// A net needs at least two ports.
30    TooFewPorts,
31    /// Two obstacle interiors overlap, which the triangulation-based routers do not
32    /// support.
33    OverlappingObstacles,
34    /// The constrained Delaunay triangulation could not recover a constraint. Only
35    /// crossing constraints cause this, which validated input rules out.
36    TriangulationFailed,
37}
38
39impl fmt::Display for Error {
40    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41        match self {
42            Self::CoordinateOutOfRange(p) => write!(f, "coordinate out of range at {p}"),
43            Self::UnknownObstacle => f.write_str("unknown obstacle id"),
44            Self::UnknownPort => f.write_str("unknown port id"),
45            Self::PortBlocked(p) => write!(f, "port {p} lies inside an obstacle"),
46            Self::PortWithoutDirections(p) => write!(f, "port {p} allows no direction"),
47            Self::NoRoute { connector } => write!(f, "no route for connector {connector}"),
48            Self::CostOverflow => f.write_str("route cost overflows u64"),
49            Self::TooFewPorts => f.write_str("a net needs at least two ports"),
50            Self::OverlappingObstacles => f.write_str("obstacle interiors overlap"),
51            Self::TriangulationFailed => f.write_str("constraint recovery failed"),
52        }
53    }
54}
55
56impl core::error::Error for Error {}