From 47371fdf3f08ac6f633bcf0386d78678ed4e197f Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Mon, 12 May 2025 00:39:19 +0200 Subject: [PATCH] refactor(router/navcord): Make it clear that navcord is not a stepper Rename `NavcordStepper<...>` to `Navcord<...>. Since the navcord is not actually considered a true stepper, having the word "stepper" in its identifier would confuse anyone new to source-diving Topola's code. Rename Navcord's `.step(...)` to `.step_to(...)` to make it clear that this is not just a step like in a stepper, but a step to a some specified position. --- src/autorouter/autoroute.rs | 4 ++-- src/autorouter/compare_detours.rs | 4 ++-- src/autorouter/invoker.rs | 4 ++-- src/autorouter/measure_length.rs | 4 ++-- src/autorouter/place_via.rs | 4 ++-- src/autorouter/remove_bands.rs | 4 ++-- src/interactor/activity.rs | 4 ++-- src/interactor/interaction.rs | 4 ++-- src/router/navcord.rs | 14 +++++++------- src/router/navcorder.rs | 26 +++++++++++++------------- src/router/route.rs | 4 ++-- src/router/router.rs | 12 ++++-------- 12 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index 2257a70..8ddcddc 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -15,7 +15,7 @@ use crate::{ geometry::primitive::PrimitiveShape, layout::LayoutEdit, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, RouteStepper, Router, }, @@ -169,7 +169,7 @@ impl GetMaybeNavmesh for AutorouteExecutionStepper { } impl GetMaybeNavcord for AutorouteExecutionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { self.route.as_ref().map(|route| route.navcord()) } } diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index 699ae26..c451c02 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -15,7 +15,7 @@ use crate::{ geometry::{primitive::PrimitiveShape, shape::MeasureLength}, graph::MakeRef, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, stepper::Step, @@ -110,7 +110,7 @@ impl GetMaybeNavmesh for CompareDetoursExecutionStepper { } impl GetMaybeNavcord for CompareDetoursExecutionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { self.autoroute.maybe_navcord() } } diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index 0dc0a7d..ba6397a 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -16,7 +16,7 @@ use crate::{ drawing::graph::PrimitiveIndex, geometry::{edit::ApplyGeometryEdit, primitive::PrimitiveShape}, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, stepper::Step, @@ -42,7 +42,7 @@ pub trait GetMaybeNavmesh { #[enum_dispatch] /// Trait for getting the navcord to display it on the debug overlay. pub trait GetMaybeNavcord { - fn maybe_navcord(&self) -> Option<&NavcordStepper>; + fn maybe_navcord(&self) -> Option<&Navcord>; } #[enum_dispatch] diff --git a/src/autorouter/measure_length.rs b/src/autorouter/measure_length.rs index 16894cb..8e9844b 100644 --- a/src/autorouter/measure_length.rs +++ b/src/autorouter/measure_length.rs @@ -12,7 +12,7 @@ use crate::{ geometry::{primitive::PrimitiveShape, shape::MeasureLength as MeasureLengthTrait}, graph::MakeRef, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, }; @@ -65,7 +65,7 @@ impl GetMaybeNavmesh for MeasureLengthExecutionStepper { } impl GetMaybeNavcord for MeasureLengthExecutionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { None } } diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index 86eb074..f57aadc 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -12,7 +12,7 @@ use crate::{ geometry::primitive::PrimitiveShape, layout::{via::ViaWeight, LayoutEdit}, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, }; @@ -62,7 +62,7 @@ impl GetMaybeNavmesh for PlaceViaExecutionStepper { } impl GetMaybeNavcord for PlaceViaExecutionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { None } } diff --git a/src/autorouter/remove_bands.rs b/src/autorouter/remove_bands.rs index 32b4d64..71326f8 100644 --- a/src/autorouter/remove_bands.rs +++ b/src/autorouter/remove_bands.rs @@ -10,7 +10,7 @@ use crate::{ geometry::primitive::PrimitiveShape, layout::LayoutEdit, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, }; @@ -61,7 +61,7 @@ impl GetMaybeNavmesh for RemoveBandsExecutionStepper { } impl GetMaybeNavcord for RemoveBandsExecutionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { None } } diff --git a/src/interactor/activity.rs b/src/interactor/activity.rs index 5647bd2..1134dbb 100644 --- a/src/interactor/activity.rs +++ b/src/interactor/activity.rs @@ -21,7 +21,7 @@ use crate::{ geometry::primitive::PrimitiveShape, interactor::interaction::{InteractionError, InteractionStepper}, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, stepper::{Abort, Step}, @@ -131,7 +131,7 @@ impl GetMaybeNavmesh for ActivityStepperWithStatus { } impl GetMaybeNavcord for ActivityStepperWithStatus { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { self.activity.maybe_navcord() } } diff --git a/src/interactor/interaction.rs b/src/interactor/interaction.rs index e7aeafc..d6e80d7 100644 --- a/src/interactor/interaction.rs +++ b/src/interactor/interaction.rs @@ -14,7 +14,7 @@ use crate::{ drawing::graph::PrimitiveIndex, geometry::primitive::PrimitiveShape, router::{ - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }, stepper::{Abort, Step}, @@ -59,7 +59,7 @@ impl GetMaybeNavmesh for InteractionStepper { } impl GetMaybeNavcord for InteractionStepper { - fn maybe_navcord(&self) -> Option<&NavcordStepper> { + fn maybe_navcord(&self) -> Option<&Navcord> { todo!() } } diff --git a/src/router/navcord.rs b/src/router/navcord.rs index d0a34b4..83c5d79 100644 --- a/src/router/navcord.rs +++ b/src/router/navcord.rs @@ -20,30 +20,30 @@ use super::{ navmesh::{BinavvertexNodeIndex, Navmesh, NavvertexIndex}, }; -/// The navcord (stepper) is a structure that holds the movable non-borrowing +/// The navcord is a structure that holds the movable non-borrowing /// data of the currently running routing process. /// /// The name "navcord" is a shortening of "navigation cord", by analogy to /// "navmesh" being a shortening of "navigation mesh". #[derive(Debug)] -pub struct NavcordStepper { +pub struct Navcord { pub recorder: LayoutEdit, /// The currently attempted path. pub path: Vec, - /// The head of the routed band. + /// The head of the currently routed band. pub head: Head, - /// The width of the routed band. + /// The width of the currently routed band. pub width: f64, } -impl NavcordStepper { +impl Navcord { /// Creates a new navcord. pub fn new( recorder: LayoutEdit, source: FixedDotIndex, source_navvertex: NavvertexIndex, width: f64, - ) -> NavcordStepper { + ) -> Navcord { Self { recorder, path: vec![source_navvertex], @@ -89,7 +89,7 @@ impl NavcordStepper { #[debug_ensures(ret.is_ok() -> matches!(self.head, Head::Cane(..)))] #[debug_ensures(ret.is_ok() -> self.path.len() == old(self.path.len() + 1))] #[debug_ensures(ret.is_err() -> self.path.len() == old(self.path.len()))] - pub fn step( + pub fn step_to( &mut self, layout: &mut Layout, navmesh: &Navmesh, diff --git a/src/router/navcorder.rs b/src/router/navcorder.rs index 00ebd47..49c3930 100644 --- a/src/router/navcorder.rs +++ b/src/router/navcorder.rs @@ -12,7 +12,7 @@ use crate::{ use super::{ draw::{Draw, DrawException}, - navcord::NavcordStepper, + navcord::Navcord, navmesh::{Navmesh, NavvertexIndex}, }; @@ -31,30 +31,30 @@ pub trait Navcorder { source: FixedDotIndex, source_navvertex: NavvertexIndex, width: f64, - ) -> NavcordStepper; + ) -> Navcord; fn finish( &mut self, _navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, target: FixedDotIndex, ) -> Result; fn rework_path( &mut self, navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, path: &[NavvertexIndex], ) -> Result<(), NavcorderException>; fn path( &mut self, navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, path: &[NavvertexIndex], ) -> Result<(), NavcorderException>; - fn undo_path(&mut self, navcord: &mut NavcordStepper, step_count: usize); + fn undo_path(&mut self, navcord: &mut Navcord, step_count: usize); } impl Navcorder for Layout { @@ -64,14 +64,14 @@ impl Navcorder for Layout { source: FixedDotIndex, source_navvertex: NavvertexIndex, width: f64, - ) -> NavcordStepper { - NavcordStepper::new(recorder, source, source_navvertex, width) + ) -> Navcord { + Navcord::new(recorder, source, source_navvertex, width) } fn finish( &mut self, _navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, target: FixedDotIndex, ) -> Result { Ok(self.finish_in_dot(&mut navcord.recorder, navcord.head, target, navcord.width)?) @@ -82,7 +82,7 @@ impl Navcorder for Layout { fn rework_path( &mut self, navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, path: &[NavvertexIndex], ) -> Result<(), NavcorderException> { let prefix_length = navcord @@ -101,11 +101,11 @@ impl Navcorder for Layout { fn path( &mut self, navmesh: &Navmesh, - navcord: &mut NavcordStepper, + navcord: &mut Navcord, path: &[NavvertexIndex], ) -> Result<(), NavcorderException> { for (i, vertex) in path.iter().enumerate() { - if let Err(err) = navcord.step(self, navmesh, *vertex) { + if let Err(err) = navcord.step_to(self, navmesh, *vertex) { self.undo_path(navcord, i); return Err(err); } @@ -115,7 +115,7 @@ impl Navcorder for Layout { } #[debug_ensures(navcord.path.len() == old(navcord.path.len() - step_count))] - fn undo_path(&mut self, navcord: &mut NavcordStepper, step_count: usize) { + fn undo_path(&mut self, navcord: &mut Navcord, step_count: usize) { for _ in 0..step_count { let _ = navcord.step_back(self); } diff --git a/src/router/route.rs b/src/router/route.rs index 733c923..3699ea5 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -14,7 +14,7 @@ use crate::{ layout::LayoutEdit, router::{ astar::{Astar, AstarError}, - navcord::NavcordStepper, + navcord::Navcord, navcorder::Navcorder, navmesh::{Navmesh, NavmeshError}, Router, RouterAstarStrategy, @@ -26,7 +26,7 @@ use crate::{ pub struct RouteStepper { #[getter(skip)] astar: Astar, - navcord: NavcordStepper, + navcord: Navcord, ghosts: Vec, obstacles: Vec, } diff --git a/src/router/router.rs b/src/router/router.rs index b6ba039..48b2aa6 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -28,7 +28,7 @@ use crate::{ use super::{ astar::{AstarStrategy, PathTracker}, draw::DrawException, - navcord::NavcordStepper, + navcord::Navcord, navcorder::{Navcorder, NavcorderException}, navmesh::{Navmesh, NavmeshEdgeReference, NavmeshError, NavvertexIndex}, route::RouteStepper, @@ -44,18 +44,14 @@ pub struct RouterOptions { #[derive(Debug)] pub struct RouterAstarStrategy<'a, R> { pub layout: &'a mut Layout, - pub navcord: &'a mut NavcordStepper, + pub navcord: &'a mut Navcord, pub target: FixedDotIndex, pub probe_ghosts: Vec, pub probe_obstacles: Vec, } impl<'a, R> RouterAstarStrategy<'a, R> { - pub fn new( - layout: &'a mut Layout, - navcord: &'a mut NavcordStepper, - target: FixedDotIndex, - ) -> Self { + pub fn new(layout: &'a mut Layout, navcord: &'a mut Navcord, target: FixedDotIndex) -> Self { Self { layout, navcord, @@ -103,7 +99,7 @@ impl AstarStrategy for RouterAst } let prev_bihead_length = self.bihead_length(); - let result = self.navcord.step(self.layout, navmesh, edge.target()); + let result = self.navcord.step_to(self.layout, navmesh, edge.target()); let probe_length = self.bihead_length() - prev_bihead_length; match result {