From 33d91b0a875d6bfb03061f3672f4f4b9333b52d4 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 21 Nov 2025 21:34:46 +0100 Subject: [PATCH] refactor(autorouter/planar_autoroute): Slightly reduce code duplication --- src/autorouter/planar_autoroute.rs | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/autorouter/planar_autoroute.rs b/src/autorouter/planar_autoroute.rs index d12fd61..5084db6 100644 --- a/src/autorouter/planar_autoroute.rs +++ b/src/autorouter/planar_autoroute.rs @@ -141,9 +141,17 @@ impl PlanarAutorouteExecutionStepper { autorouter.board.apply_edit(&board_edit.reverse()); + self.curr_ratline_index = index; + Ok(self.start_routing_ratline(autorouter)?) + } + + fn start_routing_ratline( + &mut self, + autorouter: &mut Autorouter, + ) -> Result<(), AutorouterError> { let (origin, destination) = self .configuration - .ratline_terminating_dots(autorouter, index); + .ratline_terminating_dots(autorouter, self.curr_ratline_index); let mut router = Router::new(autorouter.board.layout_mut(), self.options.router); self.route = Some(router.route( @@ -153,7 +161,6 @@ impl PlanarAutorouteExecutionStepper { self.options.router.routed_band_width, )?); - self.curr_ratline_index = index; Ok(()) } @@ -245,21 +252,14 @@ impl Step, Option, PlanarAutorouteCo self.curr_ratline_index += 1; - if let Some(..) = self.configuration.ratlines.get(self.curr_ratline_index) { - let (origin, destination) = self - .configuration - .ratline_terminating_dots(autorouter, self.curr_ratline_index); - let mut router = Router::new(autorouter.board.layout_mut(), self.options.router); - + if self + .configuration + .ratlines + .get(self.curr_ratline_index) + .is_some() + { self.dissolve_route_stepper_and_push_layout_edit(); - let recorder = LayoutEdit::new(); - - self.route = Some(router.route( - recorder, - origin, - destination, - self.options.router.routed_band_width, - )?); + self.start_routing_ratline(autorouter); } Ok(ControlFlow::Continue(ret))