mirror of https://codeberg.org/topola/topola.git
feat(stepper,autorouter): get rid of Step::finish
This commit is contained in:
parent
24c7f66b04
commit
2fdb8aee6c
|
|
@ -3,6 +3,7 @@
|
|||
//! while providing access to navigation meshes, traces, ghost shapes, and
|
||||
//! obstacles encountered.
|
||||
|
||||
use core::task::Poll;
|
||||
use petgraph::graph::EdgeIndex;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -11,7 +12,7 @@ use crate::{
|
|||
geometry::{primitive::PrimitiveShape, shape::MeasureLength},
|
||||
graph::MakeRef,
|
||||
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||
stepper::{Step, StepError},
|
||||
stepper::{PollStep, Step, StepError},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
@ -20,23 +21,6 @@ use super::{
|
|||
Autorouter, AutorouterError, AutorouterOptions,
|
||||
};
|
||||
|
||||
pub enum CompareDetoursStatus {
|
||||
Running,
|
||||
Finished(f64, f64),
|
||||
}
|
||||
|
||||
impl TryInto<(f64, f64)> for CompareDetoursStatus {
|
||||
type Error = ();
|
||||
fn try_into(self) -> Result<(f64, f64), ()> {
|
||||
match self {
|
||||
CompareDetoursStatus::Running => Err(()),
|
||||
CompareDetoursStatus::Finished(total_length1, total_length2) => {
|
||||
Ok((total_length1, total_length2))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CompareDetoursExecutionStepper {
|
||||
autoroute: AutorouteExecutionStepper,
|
||||
next_autoroute: Option<AutorouteExecutionStepper>,
|
||||
|
|
@ -72,22 +56,17 @@ impl StepError for CompareDetoursExecutionStepper {
|
|||
|
||||
// XXX: Do we really need this to be a stepper? We don't use at the moment, as sorting functions
|
||||
// aren't steppable either. It may be useful for debugging later on tho.
|
||||
impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus>
|
||||
for CompareDetoursExecutionStepper
|
||||
{
|
||||
fn step(
|
||||
impl<M: AccessMesadata> PollStep<Autorouter<M>, (f64, f64)> for CompareDetoursExecutionStepper {
|
||||
fn poll_step(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<M>,
|
||||
) -> Result<CompareDetoursStatus, AutorouterError> {
|
||||
) -> Poll<Result<(f64, f64), AutorouterError>> {
|
||||
if self.done {
|
||||
return Ok(CompareDetoursStatus::Finished(
|
||||
self.total_length1,
|
||||
self.total_length2,
|
||||
));
|
||||
return Poll::Ready(Ok((self.total_length1, self.total_length2)));
|
||||
}
|
||||
|
||||
match self.autoroute.step(autorouter)? {
|
||||
AutorouteStatus::Running => Ok(CompareDetoursStatus::Running),
|
||||
AutorouteStatus::Running => Poll::Pending,
|
||||
AutorouteStatus::Routed(band_termseg) => {
|
||||
let length = band_termseg
|
||||
.ref_(autorouter.board.layout().drawing())
|
||||
|
|
@ -99,22 +78,19 @@ impl<M: AccessMesadata> Step<Autorouter<M>, CompareDetoursStatus>
|
|||
self.total_length2 += length;
|
||||
}
|
||||
|
||||
Ok(CompareDetoursStatus::Running)
|
||||
Poll::Pending
|
||||
}
|
||||
AutorouteStatus::Finished => {
|
||||
if let Some(next_autoroute) = self.next_autoroute.take() {
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline1, self.ratline2])?;
|
||||
self.autoroute = next_autoroute;
|
||||
|
||||
Ok(CompareDetoursStatus::Running)
|
||||
Poll::Pending
|
||||
} else {
|
||||
self.done = true;
|
||||
autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1])?;
|
||||
|
||||
Ok(CompareDetoursStatus::Finished(
|
||||
self.total_length1,
|
||||
self.total_length2,
|
||||
))
|
||||
Poll::Ready(Ok((self.total_length1, self.total_length2)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
|
||||
use super::{
|
||||
autoroute::{AutorouteExecutionStepper, AutorouteStatus},
|
||||
compare_detours::{CompareDetoursExecutionStepper, CompareDetoursStatus},
|
||||
compare_detours::CompareDetoursExecutionStepper,
|
||||
invoker::{Invoker, InvokerError},
|
||||
measure_length::MeasureLengthExecutionStepper,
|
||||
place_via::PlaceViaExecutionStepper,
|
||||
|
|
@ -59,15 +59,15 @@ impl ExecutionStepper {
|
|||
Poll::Ready("finished removing bands".to_string())
|
||||
}
|
||||
ExecutionStepper::CompareDetours(compare_detours) => {
|
||||
match compare_detours.step(autorouter)? {
|
||||
CompareDetoursStatus::Running => Poll::Pending,
|
||||
CompareDetoursStatus::Finished(total_length1, total_length2) => {
|
||||
Poll::Ready(format!(
|
||||
return compare_detours.poll_step(autorouter).map(|res| {
|
||||
res.map(|(total_length1, total_length2)| {
|
||||
format!(
|
||||
"total detour lengths are {} and {}",
|
||||
total_length1, total_length2
|
||||
))
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
.map_err(Into::into)
|
||||
});
|
||||
}
|
||||
ExecutionStepper::MeasureLength(measure_length) => {
|
||||
let length = measure_length.doit(autorouter)?;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
drawing::graph::PrimitiveIndex,
|
||||
geometry::primitive::PrimitiveShape,
|
||||
router::{navmesh::Navmesh, trace::TraceStepper},
|
||||
stepper::{PollStep, Step},
|
||||
stepper::PollStep,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
|
|||
|
|
@ -6,17 +6,6 @@ pub trait StepError {
|
|||
|
||||
pub trait Step<C, S>: StepError {
|
||||
fn step(&mut self, context: &mut C) -> Result<S, Self::Error>;
|
||||
|
||||
fn finish<O>(&mut self, context: &mut C) -> Result<O, Self::Error>
|
||||
where
|
||||
S: TryInto<O>,
|
||||
{
|
||||
loop {
|
||||
if let Ok(outcome) = self.step(context)?.try_into() {
|
||||
return Ok(outcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note that PollStep's `S` is usually not the same as Step's `S`.
|
||||
|
|
|
|||
Loading…
Reference in New Issue