diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 87fcc08..d1eeb53 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -66,6 +66,17 @@ impl fmt::Debug for DrawingException { } } +impl DrawingException { + pub fn maybe_ghost_and_obstacle(&self) -> Option<(&PrimitiveShape, PrimitiveIndex)> { + match self { + Self::NoTangents(_) => None, + Self::Infringement(Infringement(ghost, obstacle)) => Some((ghost, *obstacle)), + Self::Collision(Collision(ghost, obstacle)) => Some((ghost, *obstacle)), + Self::AlreadyConnected(_) => None, + } + } +} + // TODO add real error messages + these should eventually use Display #[derive(Error, Debug, Clone, Copy)] #[error("{0:?} infringes on {1:?}")] diff --git a/src/router/router.rs b/src/router/router.rs index 5ef1747..b6ba039 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -15,7 +15,7 @@ use crate::{ head::GetFace, primitive::MakePrimitiveShape, rules::AccessRules, - Collision, DrawingException, Guide, Infringement, + Guide, }, geometry::{ primitive::PrimitiveShape, @@ -116,18 +116,8 @@ impl AstarStrategy for RouterAst DrawException::CannotWrapAround(.., layout_err) => layout_err, }; - let (ghost, obstacle) = match layout_err { - DrawingException::NoTangents(..) => return None, - DrawingException::Infringement(Infringement(ghost, obstacle)) => { - (ghost, obstacle) - } - DrawingException::Collision(Collision(ghost, obstacle)) => { - (ghost, obstacle) - } - DrawingException::AlreadyConnected(..) => return None, - }; - - self.probe_ghosts = vec![ghost]; + let (ghost, obstacle) = layout_err.maybe_ghost_and_obstacle()?; + self.probe_ghosts = vec![*ghost]; self.probe_obstacles = vec![obstacle]; } None