From deb2fffbf14c6356f30f08c4dfcdb4b4328c3868 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Tue, 6 Aug 2024 21:29:23 +0200 Subject: [PATCH] autorouter: show whole detour compare animation --- src/autorouter/autoroute.rs | 24 ++++++++++++------------ src/autorouter/compare_detours.rs | 24 +++++++++++------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index eced645..142d322 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -62,12 +62,12 @@ impl Autoroute { impl Step, AutorouteStatus, AutorouterError, ()> for Autoroute { fn step(&mut self, autorouter: &mut Autorouter) -> Result { - let Some(ref mut route) = self.route else { - // Shouldn't happen. + let Some(curr_ratline) = self.curr_ratline else { return Ok(AutorouteStatus::Finished); }; - let Some(curr_ratline) = self.curr_ratline else { + let Some(ref mut route) = self.route else { + // Shouldn't happen. return Ok(AutorouteStatus::Finished); }; @@ -97,16 +97,16 @@ impl Step, AutorouteStatus, AutorouterError, () .board .try_set_band_between_nodes(source, target, band); - let Some(new_ratline) = self.ratlines_iter.next() else { + if let Some(new_ratline) = self.ratlines_iter.next() { + let (source, target) = autorouter.ratline_endpoints(new_ratline); + let mut router = Router::new(autorouter.board.layout_mut()); + + self.curr_ratline = Some(new_ratline); + self.route = Some(router.route(source, target, 100.0)?); + } else { self.curr_ratline = None; - return Ok(AutorouteStatus::Finished); - }; - - let (source, target) = autorouter.ratline_endpoints(new_ratline); - let mut router = Router::new(autorouter.board.layout_mut()); - - self.curr_ratline = Some(new_ratline); - self.route = Some(router.route(source, target, 100.0)?); + //return Ok(AutorouteStatus::Finished); + } Ok(AutorouteStatus::Routed(band_termseg)) } diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index 0368dc0..a1c5ce3 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -37,8 +37,8 @@ pub struct CompareDetours { next_autoroute: Option, ratline1: EdgeIndex, ratline2: EdgeIndex, - total_length1: Option, - total_length2: Option, + total_length1: f64, + total_length2: f64, done: bool, } @@ -53,8 +53,8 @@ impl CompareDetours { next_autoroute: Some(autorouter.autoroute_ratlines(vec![ratline2, ratline1])?), ratline1, ratline2, - total_length1: None, - total_length2: None, + total_length1: 0.0, + total_length2: 0.0, done: false, }) } @@ -71,8 +71,8 @@ impl Step, CompareDetoursStatus, AutorouterErro ) -> Result { if self.done { return Ok(CompareDetoursStatus::Finished( - self.total_length1.unwrap(), - self.total_length2.unwrap(), + self.total_length1, + self.total_length2, )); } @@ -83,12 +83,10 @@ impl Step, CompareDetoursStatus, AutorouterErro .ref_(autorouter.board.layout().drawing()) .length(); - if self.total_length1.is_none() { - self.total_length1 = Some(length); - } else if self.total_length2.is_none() { - self.total_length2 = Some(length); + if self.next_autoroute.is_some() { + self.total_length1 += length; } else { - panic!(); + self.total_length2 += length; } Ok(CompareDetoursStatus::Running) @@ -104,8 +102,8 @@ impl Step, CompareDetoursStatus, AutorouterErro autorouter.undo_autoroute_ratlines(vec![self.ratline2, self.ratline1]); Ok(CompareDetoursStatus::Finished( - self.total_length1.unwrap(), - self.total_length2.unwrap(), + self.total_length1, + self.total_length2, )) } }