refactor(autorouter/invoker): Expose getter for whole A* stepper, not just navmesh

Besides owning the navmesh, the A* stepper stores g-scores and f-scores,
displaying which will be helpful for debugging, so we want to be able to
access the whole A* stepper instead of only the navmesh.
This commit is contained in:
Mikolaj Wielgus 2025-05-13 12:34:28 +02:00 committed by mikolaj
parent 7d5da2c797
commit 97b1315eee
11 changed files with 58 additions and 40 deletions

View File

@ -12,7 +12,7 @@ use topola::{
autorouter::{ autorouter::{
execution::Command, execution::Command,
invoker::{ invoker::{
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles, GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
}, },
}, },
board::AccessMesadata, board::AccessMesadata,
@ -252,7 +252,9 @@ impl Viewport {
if menu_bar.show_navmesh { if menu_bar.show_navmesh {
if let Some(activity) = workspace.interactor.maybe_activity() { if let Some(activity) = workspace.interactor.maybe_activity() {
if let Some(navmesh) = activity.maybe_navmesh() { if let Some(ref navmesh) =
activity.maybe_astar().map(|astar| &astar.graph)
{
for edge in navmesh.edge_references() { for edge in navmesh.edge_references() {
let mut from = PrimitiveIndex::from( let mut from = PrimitiveIndex::from(
navmesh.node_weight(edge.source()).unwrap().node, navmesh.node_weight(edge.source()).unwrap().node,
@ -448,7 +450,9 @@ impl Viewport {
.paint_primitive(ghost, egui::Color32::from_rgb(75, 75, 150)); .paint_primitive(ghost, egui::Color32::from_rgb(75, 75, 150));
} }
if let Some(navmesh) = activity.maybe_navmesh() { if let Some(ref navmesh) =
activity.maybe_astar().map(|astar| &astar.graph)
{
if menu_bar.show_origin_destination { if menu_bar.show_origin_destination {
let (origin, destination) = let (origin, destination) =
(navmesh.origin(), navmesh.destination()); (navmesh.origin(), navmesh.destination());

View File

@ -15,6 +15,7 @@ use crate::{
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
layout::LayoutEdit, layout::LayoutEdit,
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
RouteStepper, Router, RouteStepper, Router,
@ -23,7 +24,9 @@ use crate::{
}; };
use super::{ use super::{
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles}, invoker::{
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
},
Autorouter, AutorouterError, AutorouterOptions, Autorouter, AutorouterError, AutorouterOptions,
}; };
@ -162,9 +165,9 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<LayoutEdit>, AutorouteContinu
} }
} }
impl GetMaybeNavmesh for AutorouteExecutionStepper { impl GetMaybeAstarStepper for AutorouteExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
self.route.as_ref().map(|route| route.navmesh()) self.route.as_ref().map(|route| route.astar())
} }
} }

View File

@ -15,6 +15,7 @@ use crate::{
geometry::{primitive::PrimitiveShape, shape::MeasureLength}, geometry::{primitive::PrimitiveShape, shape::MeasureLength},
graph::MakeRef, graph::MakeRef,
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
@ -23,7 +24,9 @@ use crate::{
use super::{ use super::{
autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper}, autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper},
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles}, invoker::{
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
},
Autorouter, AutorouterError, AutorouterOptions, Autorouter, AutorouterError, AutorouterOptions,
}; };
@ -103,9 +106,9 @@ impl<M: AccessMesadata> Step<Autorouter<M>, (f64, f64)> for CompareDetoursExecut
} }
} }
impl GetMaybeNavmesh for CompareDetoursExecutionStepper { impl GetMaybeAstarStepper for CompareDetoursExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
self.autoroute.maybe_navmesh() self.autoroute.maybe_astar()
} }
} }

View File

@ -36,7 +36,7 @@ pub enum Command {
} }
#[enum_dispatch( #[enum_dispatch(
GetMaybeNavmesh, GetMaybeAstarStepper,
GetMaybeNavcord, GetMaybeNavcord,
GetGhosts, GetGhosts,
GetObstacles, GetObstacles,

View File

@ -16,6 +16,7 @@ use crate::{
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::{edit::ApplyGeometryEdit, primitive::PrimitiveShape}, geometry::{edit::ApplyGeometryEdit, primitive::PrimitiveShape},
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
@ -33,31 +34,32 @@ use super::{
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
/// Trait for getting the A* stepper to display its data on the debug overlay,
/// most importantly the navmesh which is owned by the A* stepper.
#[enum_dispatch] #[enum_dispatch]
/// Trait for getting the navmesh to display it on the debug overlay. pub trait GetMaybeAstarStepper {
pub trait GetMaybeNavmesh { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>>;
fn maybe_navmesh(&self) -> Option<&Navmesh>;
} }
#[enum_dispatch]
/// Trait for getting the navcord to display it on the debug overlay. /// Trait for getting the navcord to display it on the debug overlay.
#[enum_dispatch]
pub trait GetMaybeNavcord { pub trait GetMaybeNavcord {
fn maybe_navcord(&self) -> Option<&Navcord>; fn maybe_navcord(&self) -> Option<&Navcord>;
} }
#[enum_dispatch]
/// Trait for getting ghosts to display on the debug overlay. Ghosts are the /// Trait for getting ghosts to display on the debug overlay. Ghosts are the
/// shapes that Topola attempted to create but failed due to them infringing on /// shapes that Topola attempted to create but failed due to them infringing on
/// other shapes. /// other shapes.
#[enum_dispatch]
pub trait GetGhosts { pub trait GetGhosts {
fn ghosts(&self) -> &[PrimitiveShape]; fn ghosts(&self) -> &[PrimitiveShape];
} }
#[enum_dispatch]
/// Trait for getting the obstacles that prevented Topola from creating /// Trait for getting the obstacles that prevented Topola from creating
/// new objects (the shapes of these objects can be obtained with the above /// new objects (the shapes of these objects can be obtained with the above
/// `GetGhosts` trait), for the purpose of displaying these obstacles on the /// `GetGhosts` trait), for the purpose of displaying these obstacles on the
/// debug overlay. /// debug overlay.
#[enum_dispatch]
pub trait GetObstacles { pub trait GetObstacles {
fn obstacles(&self) -> &[PrimitiveIndex]; fn obstacles(&self) -> &[PrimitiveIndex];
} }

View File

@ -12,13 +12,16 @@ use crate::{
geometry::{primitive::PrimitiveShape, shape::MeasureLength as MeasureLengthTrait}, geometry::{primitive::PrimitiveShape, shape::MeasureLength as MeasureLengthTrait},
graph::MakeRef, graph::MakeRef,
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
}; };
use super::{ use super::{
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles}, invoker::{
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
},
selection::BandSelection, selection::BandSelection,
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
@ -58,8 +61,8 @@ impl MeasureLengthExecutionStepper {
} }
} }
impl GetMaybeNavmesh for MeasureLengthExecutionStepper { impl GetMaybeAstarStepper for MeasureLengthExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
None None
} }
} }

View File

@ -12,13 +12,16 @@ use crate::{
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
layout::{via::ViaWeight, LayoutEdit}, layout::{via::ViaWeight, LayoutEdit},
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
}; };
use super::{ use super::{
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles}, invoker::{
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
},
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
@ -55,8 +58,8 @@ impl PlaceViaExecutionStepper {
} }
} }
impl GetMaybeNavmesh for PlaceViaExecutionStepper { impl GetMaybeAstarStepper for PlaceViaExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
None None
} }
} }

View File

@ -10,13 +10,16 @@ use crate::{
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
layout::LayoutEdit, layout::LayoutEdit,
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
}; };
use super::{ use super::{
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles}, invoker::{
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
},
selection::BandSelection, selection::BandSelection,
Autorouter, AutorouterError, Autorouter, AutorouterError,
}; };
@ -54,8 +57,8 @@ impl RemoveBandsExecutionStepper {
} }
} }
impl GetMaybeNavmesh for RemoveBandsExecutionStepper { impl GetMaybeAstarStepper for RemoveBandsExecutionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
None None
} }
} }

View File

@ -12,7 +12,7 @@ use crate::{
autorouter::{ autorouter::{
execution::ExecutionStepper, execution::ExecutionStepper,
invoker::{ invoker::{
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles, GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
Invoker, InvokerError, Invoker, InvokerError,
}, },
}, },
@ -21,6 +21,7 @@ use crate::{
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
interactor::interaction::{InteractionError, InteractionStepper}, interactor::interaction::{InteractionError, InteractionStepper},
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
@ -49,7 +50,7 @@ pub enum ActivityError {
/// An activity is either an interaction or an execution /// An activity is either an interaction or an execution
#[enum_dispatch( #[enum_dispatch(
GetMaybeNavmesh, GetMaybeAstarStepper,
GetMaybeNavcord, GetMaybeNavcord,
GetGhosts, GetGhosts,
GetObstacles, GetObstacles,
@ -124,9 +125,9 @@ impl<M: AccessMesadata> Abort<ActivityContext<'_, M>> for ActivityStepperWithSta
} }
} }
impl GetMaybeNavmesh for ActivityStepperWithStatus { impl GetMaybeAstarStepper for ActivityStepperWithStatus {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
self.activity.maybe_navmesh() self.activity.maybe_astar()
} }
} }

View File

@ -8,12 +8,13 @@ use thiserror::Error;
use crate::{ use crate::{
autorouter::invoker::{ autorouter::invoker::{
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles, GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
}, },
board::AccessMesadata, board::AccessMesadata,
drawing::graph::PrimitiveIndex, drawing::graph::PrimitiveIndex,
geometry::primitive::PrimitiveShape, geometry::primitive::PrimitiveShape,
router::{ router::{
astar::AstarStepper,
navcord::Navcord, navcord::Navcord,
navmesh::{Navmesh, NavvertexIndex}, navmesh::{Navmesh, NavvertexIndex},
}, },
@ -52,8 +53,8 @@ impl<M: AccessMesadata> Abort<ActivityContext<'_, M>> for InteractionStepper {
} }
} }
impl GetMaybeNavmesh for InteractionStepper { impl GetMaybeAstarStepper for InteractionStepper {
fn maybe_navmesh(&self) -> Option<&Navmesh> { fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
todo!() todo!()
} }
} }

View File

@ -24,7 +24,6 @@ use crate::{
#[derive(Getters, Dissolve)] #[derive(Getters, Dissolve)]
pub struct RouteStepper { pub struct RouteStepper {
#[getter(skip)]
astar: AstarStepper<Navmesh, f64>, astar: AstarStepper<Navmesh, f64>,
navcord: Navcord, navcord: Navcord,
ghosts: Vec<PrimitiveShape>, ghosts: Vec<PrimitiveShape>,
@ -68,10 +67,6 @@ impl RouteStepper {
obstacles, obstacles,
} }
} }
pub fn navmesh(&self) -> &Navmesh {
&self.astar.graph
}
} }
impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper { impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper {