refactor(DrawingException): factor out extraction of ghost+obstacle

This commit is contained in:
Ellen Emilia Anna Zscheile 2025-03-29 22:32:58 +01:00
parent 566949d4c1
commit 22460c75f7
2 changed files with 14 additions and 13 deletions

View File

@ -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:?}")]

View File

@ -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<R: AccessRules> AstarStrategy<Navmesh, f64, BandTermsegIndex> 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