From ce0424b3e6c70a2def68e63d255244386bbe6238 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 1 Sep 2025 20:18:40 +0200 Subject: [PATCH] fix(autorouter/autoroute): Skip permutations that result in nothing undone --- src/autorouter/autoroute.rs | 19 +++++++++++++++---- src/autorouter/autorouter.rs | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 34d168c..8ce6118 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -92,6 +92,10 @@ impl AutorouteExecutionStepper { autorouter: &mut Autorouter, index: usize, ) -> Result<(), AutorouterError> { + if index > self.board_data_edits.len() { + return Err(AutorouterError::NothingToUndoForPermutation); + } + self.dissolve_route_stepper_and_push_layout_edit(); let board_edit = BoardEdit::new_from_edits( @@ -313,11 +317,18 @@ impl Step, Option, AutorouteContinue return Err(err); } - let Some(permutation) = self.permutations_iter.next() else { - return Ok(ControlFlow::Break(None)); - }; + loop { + let Some(permutation) = self.permutations_iter.next() else { + return Ok(ControlFlow::Break(None)); + }; + + match self.stepper.permute(autorouter, permutation) { + Ok(()) => break, + Err(AutorouterError::NothingToUndoForPermutation) => continue, + Err(err) => return Err(err), + } + } - self.stepper.permute(autorouter, permutation); self.stepper.step(autorouter) } } diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 8c47ead..7961638 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -62,6 +62,8 @@ pub enum AutorouterError { CouldNotRemoveBand(BandTermsegIndex), #[error("need exactly two ratlines")] NeedExactlyTwoRatlines, + #[error("nothing to undo for permutation")] + NothingToUndoForPermutation, } #[derive(Getters)]