mirror of https://codeberg.org/topola/topola.git
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:
parent
7d5da2c797
commit
97b1315eee
|
|
@ -12,7 +12,7 @@ use topola::{
|
|||
autorouter::{
|
||||
execution::Command,
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles,
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
},
|
||||
board::AccessMesadata,
|
||||
|
|
@ -252,7 +252,9 @@ impl Viewport {
|
|||
|
||||
if menu_bar.show_navmesh {
|
||||
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() {
|
||||
let mut from = PrimitiveIndex::from(
|
||||
navmesh.node_weight(edge.source()).unwrap().node,
|
||||
|
|
@ -448,7 +450,9 @@ impl Viewport {
|
|||
.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 {
|
||||
let (origin, destination) =
|
||||
(navmesh.origin(), navmesh.destination());
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::{
|
|||
geometry::primitive::PrimitiveShape,
|
||||
layout::LayoutEdit,
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
RouteStepper, Router,
|
||||
|
|
@ -23,7 +24,9 @@ use crate::{
|
|||
};
|
||||
|
||||
use super::{
|
||||
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles},
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
Autorouter, AutorouterError, AutorouterOptions,
|
||||
};
|
||||
|
||||
|
|
@ -162,9 +165,9 @@ impl<M: AccessMesadata> Step<Autorouter<M>, Option<LayoutEdit>, AutorouteContinu
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for AutorouteExecutionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
self.route.as_ref().map(|route| route.navmesh())
|
||||
impl GetMaybeAstarStepper for AutorouteExecutionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
self.route.as_ref().map(|route| route.astar())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use crate::{
|
|||
geometry::{primitive::PrimitiveShape, shape::MeasureLength},
|
||||
graph::MakeRef,
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
|
|
@ -23,7 +24,9 @@ use crate::{
|
|||
|
||||
use super::{
|
||||
autoroute::{AutorouteContinueStatus, AutorouteExecutionStepper},
|
||||
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles},
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
Autorouter, AutorouterError, AutorouterOptions,
|
||||
};
|
||||
|
||||
|
|
@ -103,9 +106,9 @@ impl<M: AccessMesadata> Step<Autorouter<M>, (f64, f64)> for CompareDetoursExecut
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for CompareDetoursExecutionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
self.autoroute.maybe_navmesh()
|
||||
impl GetMaybeAstarStepper for CompareDetoursExecutionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
self.autoroute.maybe_astar()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub enum Command {
|
|||
}
|
||||
|
||||
#[enum_dispatch(
|
||||
GetMaybeNavmesh,
|
||||
GetMaybeAstarStepper,
|
||||
GetMaybeNavcord,
|
||||
GetGhosts,
|
||||
GetObstacles,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use crate::{
|
|||
drawing::graph::PrimitiveIndex,
|
||||
geometry::{edit::ApplyGeometryEdit, primitive::PrimitiveShape},
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
|
|
@ -33,31 +34,32 @@ use super::{
|
|||
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]
|
||||
/// Trait for getting the navmesh to display it on the debug overlay.
|
||||
pub trait GetMaybeNavmesh {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh>;
|
||||
pub trait GetMaybeAstarStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>>;
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
/// Trait for getting the navcord to display it on the debug overlay.
|
||||
#[enum_dispatch]
|
||||
pub trait GetMaybeNavcord {
|
||||
fn maybe_navcord(&self) -> Option<&Navcord>;
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
/// 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
|
||||
/// other shapes.
|
||||
#[enum_dispatch]
|
||||
pub trait GetGhosts {
|
||||
fn ghosts(&self) -> &[PrimitiveShape];
|
||||
}
|
||||
|
||||
#[enum_dispatch]
|
||||
/// Trait for getting the obstacles that prevented Topola from creating
|
||||
/// new objects (the shapes of these objects can be obtained with the above
|
||||
/// `GetGhosts` trait), for the purpose of displaying these obstacles on the
|
||||
/// debug overlay.
|
||||
#[enum_dispatch]
|
||||
pub trait GetObstacles {
|
||||
fn obstacles(&self) -> &[PrimitiveIndex];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ use crate::{
|
|||
geometry::{primitive::PrimitiveShape, shape::MeasureLength as MeasureLengthTrait},
|
||||
graph::MakeRef,
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles},
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
selection::BandSelection,
|
||||
Autorouter, AutorouterError,
|
||||
};
|
||||
|
|
@ -58,8 +61,8 @@ impl MeasureLengthExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for MeasureLengthExecutionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
impl GetMaybeAstarStepper for MeasureLengthExecutionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,13 +12,16 @@ use crate::{
|
|||
geometry::primitive::PrimitiveShape,
|
||||
layout::{via::ViaWeight, LayoutEdit},
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles},
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
Autorouter, AutorouterError,
|
||||
};
|
||||
|
||||
|
|
@ -55,8 +58,8 @@ impl PlaceViaExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for PlaceViaExecutionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
impl GetMaybeAstarStepper for PlaceViaExecutionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,16 @@ use crate::{
|
|||
geometry::primitive::PrimitiveShape,
|
||||
layout::LayoutEdit,
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
};
|
||||
|
||||
use super::{
|
||||
invoker::{GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles},
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
selection::BandSelection,
|
||||
Autorouter, AutorouterError,
|
||||
};
|
||||
|
|
@ -54,8 +57,8 @@ impl RemoveBandsExecutionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for RemoveBandsExecutionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
impl GetMaybeAstarStepper for RemoveBandsExecutionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
autorouter::{
|
||||
execution::ExecutionStepper,
|
||||
invoker::{
|
||||
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles,
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
Invoker, InvokerError,
|
||||
},
|
||||
},
|
||||
|
|
@ -21,6 +21,7 @@ use crate::{
|
|||
geometry::primitive::PrimitiveShape,
|
||||
interactor::interaction::{InteractionError, InteractionStepper},
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
|
|
@ -49,7 +50,7 @@ pub enum ActivityError {
|
|||
|
||||
/// An activity is either an interaction or an execution
|
||||
#[enum_dispatch(
|
||||
GetMaybeNavmesh,
|
||||
GetMaybeAstarStepper,
|
||||
GetMaybeNavcord,
|
||||
GetGhosts,
|
||||
GetObstacles,
|
||||
|
|
@ -124,9 +125,9 @@ impl<M: AccessMesadata> Abort<ActivityContext<'_, M>> for ActivityStepperWithSta
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for ActivityStepperWithStatus {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
self.activity.maybe_navmesh()
|
||||
impl GetMaybeAstarStepper for ActivityStepperWithStatus {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
self.activity.maybe_astar()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,13 @@ use thiserror::Error;
|
|||
|
||||
use crate::{
|
||||
autorouter::invoker::{
|
||||
GetGhosts, GetMaybeNavcord, GetMaybeNavmesh, GetNavmeshDebugTexts, GetObstacles,
|
||||
GetGhosts, GetMaybeAstarStepper, GetMaybeNavcord, GetNavmeshDebugTexts, GetObstacles,
|
||||
},
|
||||
board::AccessMesadata,
|
||||
drawing::graph::PrimitiveIndex,
|
||||
geometry::primitive::PrimitiveShape,
|
||||
router::{
|
||||
astar::AstarStepper,
|
||||
navcord::Navcord,
|
||||
navmesh::{Navmesh, NavvertexIndex},
|
||||
},
|
||||
|
|
@ -52,8 +53,8 @@ impl<M: AccessMesadata> Abort<ActivityContext<'_, M>> for InteractionStepper {
|
|||
}
|
||||
}
|
||||
|
||||
impl GetMaybeNavmesh for InteractionStepper {
|
||||
fn maybe_navmesh(&self) -> Option<&Navmesh> {
|
||||
impl GetMaybeAstarStepper for InteractionStepper {
|
||||
fn maybe_astar(&self) -> Option<&AstarStepper<Navmesh, f64>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ use crate::{
|
|||
|
||||
#[derive(Getters, Dissolve)]
|
||||
pub struct RouteStepper {
|
||||
#[getter(skip)]
|
||||
astar: AstarStepper<Navmesh, f64>,
|
||||
navcord: Navcord,
|
||||
ghosts: Vec<PrimitiveShape>,
|
||||
|
|
@ -68,10 +67,6 @@ impl RouteStepper {
|
|||
obstacles,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn navmesh(&self) -> &Navmesh {
|
||||
&self.astar.graph
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper {
|
||||
|
|
|
|||
Loading…
Reference in New Issue