diff --git a/crates/topola-egui/src/viewport.rs b/crates/topola-egui/src/viewport.rs index 2a0cf56..2275ba4 100644 --- a/crates/topola-egui/src/viewport.rs +++ b/crates/topola-egui/src/viewport.rs @@ -251,7 +251,7 @@ impl Viewport { if menu_bar.show_navmesh { if let Some(activity) = workspace.interactor.maybe_activity() { if let Some(astar) = activity.maybe_astar() { - let navmesh = &astar.graph; + let navmesh = astar.graph(); for edge in navmesh.edge_references() { let mut from = PrimitiveIndex::from( @@ -354,12 +354,12 @@ impl Viewport { }; //TODO "{astar.scores[index]} ({astar.estimate_scores[index]}) (...)" - let score_text = &astar - .scores + let score_text = astar + .scores() .get(&navnode) .map_or_else(String::new, |s| format!("g={:.2}", s)); - let estimate_score_text = &astar - .estimate_scores + let estimate_score_text = astar + .estimate_scores() .get(&navnode) .map_or_else(String::new, |s| format!("(f={:.2})", s)); let debug_text = @@ -460,7 +460,7 @@ impl Viewport { } if let Some(ref navmesh) = - activity.maybe_astar().map(|astar| &astar.graph) + activity.maybe_astar().map(|astar| astar.graph()) { if menu_bar.show_origin_destination { let (origin, destination) = diff --git a/src/router/astar.rs b/src/router/astar.rs index 5f3a8cd..64f42e2 100644 --- a/src/router/astar.rs +++ b/src/router/astar.rs @@ -7,6 +7,7 @@ use std::collections::{btree_map::Entry, BTreeMap, BinaryHeap, VecDeque}; use std::ops::ControlFlow; +use derive_getters::Getters; use petgraph::algo::Measure; use petgraph::visit::{EdgeRef, GraphBase, IntoEdgeReferences, IntoEdges}; use thiserror::Error; @@ -122,6 +123,7 @@ pub trait MakeEdgeRef: IntoEdgeReferences { fn edge_ref(&self, edge_id: Self::EdgeId) -> Self::EdgeRef; } +#[derive(Getters)] pub struct AstarStepper where G: GraphBase, @@ -129,18 +131,23 @@ where for<'a> &'a G: IntoEdges + MakeEdgeRef, K: Measure + Copy, { - pub graph: G, - pub visit_next: BinaryHeap>, + graph: G, + #[getter(skip)] + visit_next: BinaryHeap>, /// Also known as the g-scores, or just g. - pub scores: BTreeMap, + scores: BTreeMap, /// Also known as the f-scores, or just f. - pub estimate_scores: BTreeMap, - pub path_tracker: PathTracker, - pub maybe_curr_node: Option, + estimate_scores: BTreeMap, + #[getter(skip)] + path_tracker: PathTracker, + #[getter(skip)] + maybe_curr_node: Option, // FIXME: To work around edge references borrowing from the graph we collect then reiterate over them. - pub edge_ids: VecDeque, + #[getter(skip)] + edge_ids: VecDeque, // TODO: Rewrite this to be a well-designed state machine. Booleans are a code smell. - pub is_probing: bool, + #[getter(skip)] + is_probing: bool, } /// The status enum of the A* stepper returned when there is no failure or diff --git a/src/router/route.rs b/src/router/route.rs index 6477013..cd2d527 100644 --- a/src/router/route.rs +++ b/src/router/route.rs @@ -77,7 +77,7 @@ impl Step, BandTermsegIndex> for RouteStepper { router: &mut Router, ) -> Result, AstarError> { let layout = router.layout_mut(); - let target = self.astar.graph.destination(); + let target = self.astar.graph().destination(); let mut strategy = RouterAstarStrategy::new(layout, &mut self.navcord, target); let result = self.astar.step(&mut strategy); self.ghosts = strategy.probe_ghosts;