mirror of https://codeberg.org/topola/topola.git
refactor(router/astar): Use getters instead of `pub` members
This commit is contained in:
parent
cfd20ed381
commit
0702b7eb8c
|
|
@ -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) =
|
||||
|
|
|
|||
|
|
@ -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<G, K>
|
||||
where
|
||||
G: GraphBase,
|
||||
|
|
@ -129,18 +131,23 @@ where
|
|||
for<'a> &'a G: IntoEdges<NodeId = G::NodeId, EdgeId = G::EdgeId> + MakeEdgeRef,
|
||||
K: Measure + Copy,
|
||||
{
|
||||
pub graph: G,
|
||||
pub visit_next: BinaryHeap<MinScored<K, G::NodeId>>,
|
||||
graph: G,
|
||||
#[getter(skip)]
|
||||
visit_next: BinaryHeap<MinScored<K, G::NodeId>>,
|
||||
/// Also known as the g-scores, or just g.
|
||||
pub scores: BTreeMap<G::NodeId, K>,
|
||||
scores: BTreeMap<G::NodeId, K>,
|
||||
/// Also known as the f-scores, or just f.
|
||||
pub estimate_scores: BTreeMap<G::NodeId, K>,
|
||||
pub path_tracker: PathTracker<G>,
|
||||
pub maybe_curr_node: Option<G::NodeId>,
|
||||
estimate_scores: BTreeMap<G::NodeId, K>,
|
||||
#[getter(skip)]
|
||||
path_tracker: PathTracker<G>,
|
||||
#[getter(skip)]
|
||||
maybe_curr_node: Option<G::NodeId>,
|
||||
// FIXME: To work around edge references borrowing from the graph we collect then reiterate over them.
|
||||
pub edge_ids: VecDeque<G::EdgeId>,
|
||||
#[getter(skip)]
|
||||
edge_ids: VecDeque<G::EdgeId>,
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ impl<R: AccessRules> Step<Router<'_, R>, BandTermsegIndex> for RouteStepper {
|
|||
router: &mut Router<R>,
|
||||
) -> Result<ControlFlow<BandTermsegIndex>, 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue