router: replace RouterStatus with Poll

This commit is contained in:
Alain Emilia Anna Zscheile 2024-10-05 13:15:07 +02:00
parent 224dd0c3bd
commit 76537e7dfa
3 changed files with 19 additions and 31 deletions

View File

@ -2,14 +2,15 @@
//! routing steps. Provides access to navigation meshes, traces, ghost shapes,
//! and obstacles encountered during routing.
use core::task::Poll;
use petgraph::graph::EdgeIndex;
use crate::{
board::mesadata::AccessMesadata,
drawing::{band::BandTermsegIndex, graph::PrimitiveIndex},
geometry::primitive::PrimitiveShape,
router::{navmesh::Navmesh, route::RouteStepper, trace::TraceStepper, Router, RouterStatus},
stepper::{Step, StepError},
router::{navmesh::Navmesh, route::RouteStepper, trace::TraceStepper, Router},
stepper::{PollStep, Step, StepError},
};
use super::{
@ -107,10 +108,11 @@ impl<M: AccessMesadata> Step<Autorouter<M>, AutorouteStatus> for AutorouteExecut
let mut router =
Router::new(autorouter.board.layout_mut(), self.options.router_options);
let RouterStatus::Finished(band_termseg) = route.step(&mut router)? else {
return Ok(AutorouteStatus::Running);
};
band_termseg
match route.poll_step(&mut router) {
Poll::Pending => return Ok(AutorouteStatus::Running),
Poll::Ready(Ok(band_termseg)) => band_termseg,
Poll::Ready(Err(err)) => return Err(err.into()),
}
};
let band = autorouter

View File

@ -1,14 +1,18 @@
use core::task::Poll;
use crate::{
drawing::{dot::FixedDotIndex, graph::PrimitiveIndex, rules::AccessRules},
drawing::{
band::BandTermsegIndex, dot::FixedDotIndex, graph::PrimitiveIndex, rules::AccessRules,
},
geometry::primitive::PrimitiveShape,
router::{
astar::{Astar, AstarError, AstarStatus},
navmesh::{Navmesh, NavmeshError},
trace::TraceStepper,
tracer::Tracer,
Router, RouterAstarStrategy, RouterStatus,
Router, RouterAstarStrategy,
},
stepper::{Step, StepError},
stepper::{PollStep, Step, StepError},
};
pub struct RouteStepper {
@ -75,17 +79,15 @@ impl StepError for RouteStepper {
type Error = AstarError;
}
impl<'a, R: AccessRules> Step<Router<'a, R>, RouterStatus> for RouteStepper {
fn step(&mut self, router: &mut Router<R>) -> Result<RouterStatus, AstarError> {
impl<'a, R: AccessRules> PollStep<Router<'a, R>, BandTermsegIndex> for RouteStepper {
fn poll_step(&mut self, router: &mut Router<R>) -> Poll<Result<BandTermsegIndex, AstarError>> {
let tracer = Tracer::new(router.layout_mut());
let target = self.astar.graph.destination();
let mut strategy = RouterAstarStrategy::new(tracer, &mut self.trace, target);
let result = match self.astar.step(&mut strategy)? {
AstarStatus::Probing | AstarStatus::Probed | AstarStatus::Visited => {
Ok(RouterStatus::Running)
}
AstarStatus::Finished(_cost, _path, band) => Ok(RouterStatus::Finished(band)),
AstarStatus::Probing | AstarStatus::Probed | AstarStatus::Visited => Poll::Pending,
AstarStatus::Finished(_cost, _path, band) => Poll::Ready(Ok(band)),
};
self.ghosts = strategy.probe_ghosts;

View File

@ -35,22 +35,6 @@ pub struct RouterOptions {
pub squeeze_through_under_bands: bool,
}
#[derive(Debug)]
pub enum RouterStatus {
Running,
Finished(BandTermsegIndex),
}
impl TryInto<BandTermsegIndex> for RouterStatus {
type Error = ();
fn try_into(self) -> Result<BandTermsegIndex, ()> {
match self {
RouterStatus::Running => Err(()),
RouterStatus::Finished(band_termseg) => Ok(band_termseg),
}
}
}
#[derive(Debug)]
pub struct RouterAstarStrategy<'a, R: AccessRules> {
pub tracer: Tracer<'a, R>,