mirror of https://codeberg.org/topola/topola.git
refactor(autorouter/autoroute): Move permuting to new trait
This commit is contained in:
parent
8fb94c96ff
commit
3cc2315ebe
|
|
@ -20,7 +20,7 @@ use crate::{
|
|||
router::{
|
||||
navcord::Navcord, navmesh::Navmesh, thetastar::ThetastarStepper, RouteStepper, Router,
|
||||
},
|
||||
stepper::{Abort, EstimateProgress, Step},
|
||||
stepper::{Abort, EstimateProgress, Permute, Step},
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
|
@ -87,22 +87,6 @@ impl AutorouteExecutionStepper {
|
|||
})
|
||||
}
|
||||
|
||||
fn permute(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<impl AccessMesadata>,
|
||||
permutation: Vec<RatlineIndex>,
|
||||
) -> Result<(), AutorouterError> {
|
||||
let new_index = permutation
|
||||
.iter()
|
||||
.zip(self.ratlines.iter())
|
||||
.position(|(permuted, original)| *permuted != *original)
|
||||
.unwrap();
|
||||
self.ratlines = permutation;
|
||||
|
||||
self.backtrace_to_index(autorouter, new_index)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn backtrace_to_index(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<impl AccessMesadata>,
|
||||
|
|
@ -236,6 +220,27 @@ impl<M: AccessMesadata> Abort<Autorouter<M>> for AutorouteExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl<M: AccessMesadata> Permute<Autorouter<M>> for AutorouteExecutionStepper {
|
||||
type Index = RatlineIndex;
|
||||
type Output = Result<(), AutorouterError>;
|
||||
|
||||
fn permute(
|
||||
&mut self,
|
||||
autorouter: &mut Autorouter<M>,
|
||||
permutation: Vec<RatlineIndex>,
|
||||
) -> Result<(), AutorouterError> {
|
||||
let new_index = permutation
|
||||
.iter()
|
||||
.zip(self.ratlines.iter())
|
||||
.position(|(permuted, original)| *permuted != *original)
|
||||
.unwrap();
|
||||
self.ratlines = permutation;
|
||||
|
||||
self.backtrace_to_index(autorouter, new_index)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl EstimateProgress for AutorouteExecutionStepper {
|
||||
type Value = f64;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,14 @@ pub trait Abort<Ctx> {
|
|||
fn abort(&mut self, context: &mut Ctx);
|
||||
}
|
||||
|
||||
/// Some steppers may be permuted from their initial order.
|
||||
pub trait Permute<Ctx> {
|
||||
type Index;
|
||||
type Output;
|
||||
|
||||
fn permute(&mut self, context: &mut Ctx, ordering: Vec<Self::Index>) -> Self::Output;
|
||||
}
|
||||
|
||||
/// Steppers that can receive discrete events and act on them implement this
|
||||
/// trait.
|
||||
// XXX: Doesn't this violate the rule that stepper's future states are
|
||||
|
|
|
|||
Loading…
Reference in New Issue