From f9b1cc2cbf5b02deb30c1b411197750c7e498177 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Fri, 16 May 2025 18:46:21 +0200 Subject: [PATCH] refactor(autorouter/invoker): Add default impls. to invoker's stepper traits --- src/autorouter/autoroute.rs | 12 +--------- src/autorouter/compare_detours.rs | 10 +------- src/autorouter/invoker.rs | 25 +++++++++++++++----- src/autorouter/measure_length.rs | 38 ++++--------------------------- src/autorouter/place_via.rs | 38 ++++--------------------------- src/autorouter/remove_bands.rs | 38 ++++--------------------------- 6 files changed, 36 insertions(+), 125 deletions(-) diff --git a/src/autorouter/autoroute.rs b/src/autorouter/autoroute.rs index bf7d91e..445f74e 100644 --- a/src/autorouter/autoroute.rs +++ b/src/autorouter/autoroute.rs @@ -189,14 +189,4 @@ impl GetObstacles for AutorouteExecutionStepper { } } -impl GetNavmeshDebugTexts for AutorouteExecutionStepper { - fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { - // Add debug text here. - None - } - - fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { - // Add debug text here. - None - } -} +impl GetNavmeshDebugTexts for AutorouteExecutionStepper {} diff --git a/src/autorouter/compare_detours.rs b/src/autorouter/compare_detours.rs index 11e118a..7f7f9b8 100644 --- a/src/autorouter/compare_detours.rs +++ b/src/autorouter/compare_detours.rs @@ -130,12 +130,4 @@ impl GetObstacles for CompareDetoursExecutionStepper { } } -impl GetNavmeshDebugTexts for CompareDetoursExecutionStepper { - fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { - None - } - - fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { - None - } -} +impl GetNavmeshDebugTexts for CompareDetoursExecutionStepper {} diff --git a/src/autorouter/invoker.rs b/src/autorouter/invoker.rs index f3c5f69..6517514 100644 --- a/src/autorouter/invoker.rs +++ b/src/autorouter/invoker.rs @@ -38,13 +38,17 @@ use super::{ /// most importantly the navmesh which is owned by the A* stepper. #[enum_dispatch] pub trait GetMaybeAstarStepper { - fn maybe_astar(&self) -> Option<&AstarStepper>; + fn maybe_astar(&self) -> Option<&AstarStepper> { + None + } } /// Trait for getting the navcord to display it on the debug overlay. #[enum_dispatch] pub trait GetMaybeNavcord { - fn maybe_navcord(&self) -> Option<&Navcord>; + fn maybe_navcord(&self) -> Option<&Navcord> { + None + } } /// Trait for getting ghosts to display on the debug overlay. Ghosts are the @@ -52,7 +56,9 @@ pub trait GetMaybeNavcord { /// other shapes. #[enum_dispatch] pub trait GetGhosts { - fn ghosts(&self) -> &[PrimitiveShape]; + fn ghosts(&self) -> &[PrimitiveShape] { + &[] + } } /// Trait for getting the obstacles that prevented Topola from creating @@ -61,15 +67,22 @@ pub trait GetGhosts { /// debug overlay. #[enum_dispatch] pub trait GetObstacles { - fn obstacles(&self) -> &[PrimitiveIndex]; + fn obstacles(&self) -> &[PrimitiveIndex] { + &[] + } } #[enum_dispatch] /// Trait for getting text strings with debug information attached to navmesh /// edges and vertices. pub trait GetNavmeshDebugTexts { - fn navvertex_debug_text(&self, navvertex: NavvertexIndex) -> Option<&str>; - fn navedge_debug_text(&self, navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str>; + fn navvertex_debug_text(&self, navvertex: NavvertexIndex) -> Option<&str> { + None + } + + fn navedge_debug_text(&self, navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { + None + } } /// Error types that can occur during the invocation of commands. diff --git a/src/autorouter/measure_length.rs b/src/autorouter/measure_length.rs index fb0a433..9b86ad3 100644 --- a/src/autorouter/measure_length.rs +++ b/src/autorouter/measure_length.rs @@ -61,36 +61,8 @@ impl MeasureLengthExecutionStepper { } } -impl GetMaybeAstarStepper for MeasureLengthExecutionStepper { - fn maybe_astar(&self) -> Option<&AstarStepper> { - None - } -} - -impl GetMaybeNavcord for MeasureLengthExecutionStepper { - fn maybe_navcord(&self) -> Option<&Navcord> { - None - } -} - -impl GetGhosts for MeasureLengthExecutionStepper { - fn ghosts(&self) -> &[PrimitiveShape] { - &[] - } -} - -impl GetObstacles for MeasureLengthExecutionStepper { - fn obstacles(&self) -> &[PrimitiveIndex] { - &[] - } -} - -impl GetNavmeshDebugTexts for MeasureLengthExecutionStepper { - fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { - None - } - - fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { - None - } -} +impl GetMaybeAstarStepper for MeasureLengthExecutionStepper {} +impl GetMaybeNavcord for MeasureLengthExecutionStepper {} +impl GetGhosts for MeasureLengthExecutionStepper {} +impl GetObstacles for MeasureLengthExecutionStepper {} +impl GetNavmeshDebugTexts for MeasureLengthExecutionStepper {} diff --git a/src/autorouter/place_via.rs b/src/autorouter/place_via.rs index c828fb2..9f47f51 100644 --- a/src/autorouter/place_via.rs +++ b/src/autorouter/place_via.rs @@ -58,36 +58,8 @@ impl PlaceViaExecutionStepper { } } -impl GetMaybeAstarStepper for PlaceViaExecutionStepper { - fn maybe_astar(&self) -> Option<&AstarStepper> { - None - } -} - -impl GetMaybeNavcord for PlaceViaExecutionStepper { - fn maybe_navcord(&self) -> Option<&Navcord> { - None - } -} - -impl GetGhosts for PlaceViaExecutionStepper { - fn ghosts(&self) -> &[PrimitiveShape] { - &[] - } -} - -impl GetObstacles for PlaceViaExecutionStepper { - fn obstacles(&self) -> &[PrimitiveIndex] { - &[] - } -} - -impl GetNavmeshDebugTexts for PlaceViaExecutionStepper { - fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { - None - } - - fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { - None - } -} +impl GetMaybeAstarStepper for PlaceViaExecutionStepper {} +impl GetMaybeNavcord for PlaceViaExecutionStepper {} +impl GetGhosts for PlaceViaExecutionStepper {} +impl GetObstacles for PlaceViaExecutionStepper {} +impl GetNavmeshDebugTexts for PlaceViaExecutionStepper {} diff --git a/src/autorouter/remove_bands.rs b/src/autorouter/remove_bands.rs index 47dce6a..19967c5 100644 --- a/src/autorouter/remove_bands.rs +++ b/src/autorouter/remove_bands.rs @@ -57,36 +57,8 @@ impl RemoveBandsExecutionStepper { } } -impl GetMaybeAstarStepper for RemoveBandsExecutionStepper { - fn maybe_astar(&self) -> Option<&AstarStepper> { - None - } -} - -impl GetMaybeNavcord for RemoveBandsExecutionStepper { - fn maybe_navcord(&self) -> Option<&Navcord> { - None - } -} - -impl GetGhosts for RemoveBandsExecutionStepper { - fn ghosts(&self) -> &[PrimitiveShape] { - &[] - } -} - -impl GetObstacles for RemoveBandsExecutionStepper { - fn obstacles(&self) -> &[PrimitiveIndex] { - &[] - } -} - -impl GetNavmeshDebugTexts for RemoveBandsExecutionStepper { - fn navvertex_debug_text(&self, _navvertex: NavvertexIndex) -> Option<&str> { - None - } - - fn navedge_debug_text(&self, _navedge: (NavvertexIndex, NavvertexIndex)) -> Option<&str> { - None - } -} +impl GetMaybeAstarStepper for RemoveBandsExecutionStepper {} +impl GetMaybeNavcord for RemoveBandsExecutionStepper {} +impl GetGhosts for RemoveBandsExecutionStepper {} +impl GetObstacles for RemoveBandsExecutionStepper {} +impl GetNavmeshDebugTexts for RemoveBandsExecutionStepper {}