diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index f5285ef..34d168c 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -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, - permutation: Vec, - ) -> 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, @@ -236,6 +220,27 @@ impl Abort> for AutorouteExecutionStepper { } } +impl Permute> for AutorouteExecutionStepper { + type Index = RatlineIndex; + type Output = Result<(), AutorouterError>; + + fn permute( + &mut self, + autorouter: &mut Autorouter, + permutation: Vec, + ) -> 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; diff --git a/src/stepper.rs b/src/stepper.rs index 6f9dba7..86e6c3f 100644 --- a/src/stepper.rs +++ b/src/stepper.rs @@ -53,6 +53,14 @@ pub trait Abort { fn abort(&mut self, context: &mut Ctx); } +/// Some steppers may be permuted from their initial order. +pub trait Permute { + type Index; + type Output; + + fn permute(&mut self, context: &mut Ctx, ordering: Vec) -> 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