feat(router/thetastar): Highlight currently attempted navedge

This commit is contained in:
Mikolaj Wielgus 2025-11-29 19:03:12 +01:00
parent b9b52fb977
commit 2c94b50290
2 changed files with 49 additions and 19 deletions

View File

@ -28,6 +28,7 @@ use topola::{
navmesh::{BinavnodeNodeIndex, Navmesh, NavnodeIndex},
ng::pie,
prenavmesh::PrenavmeshConstraint,
thetastar::ThetastarState,
},
};
@ -223,25 +224,26 @@ impl<'a> Displayer<'a> {
}
}
let stroke = 'blk: {
if let Some(navcord) = activity.maybe_navcord() {
if let (Some(source_pos), Some(target_pos)) = (
navcord.path.iter().position(|node| *node == edge.source()),
navcord.path.iter().position(|node| *node == edge.target()),
) {
if target_pos == source_pos + 1 || source_pos == target_pos + 1 {
break 'blk egui::Stroke::new(
5.0,
egui::Color32::from_rgb(250, 250, 0),
);
if menu_bar.show_navmesh {
let stroke = 'blk: {
if let Some(navcord) = activity.maybe_navcord() {
if let (Some(source_pos), Some(target_pos)) = (
navcord.path.iter().position(|node| *node == edge.source()),
navcord.path.iter().position(|node| *node == edge.target()),
) {
if target_pos == source_pos + 1 || source_pos == target_pos + 1
{
break 'blk egui::Stroke::new(
5.0,
egui::Color32::from_rgb(250, 250, 0),
);
}
}
}
}
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
};
egui::Stroke::new(1.0, egui::Color32::from_rgb(125, 125, 125))
};
if menu_bar.show_navmesh {
self.painter.paint_line_segment(from, to, stroke);
}
@ -277,6 +279,34 @@ impl<'a> Displayer<'a> {
}
}
if menu_bar.show_navmesh {
match thetastar.state() {
ThetastarState::BacktrackAndProbeOnLineOfSight(_, edge)
| ThetastarState::ProbeOnNavedge(_, edge) => {
let edge_from = PrimitiveIndex::from(
navmesh.node_weight(edge.0).unwrap().binavnode,
)
.primitive_ref(board.layout().drawing())
.shape()
.center();
let edge_to = PrimitiveIndex::from(
navmesh.node_weight(edge.1).unwrap().binavnode,
)
.primitive_ref(board.layout().drawing())
.shape()
.center();
self.painter.paint_line_segment(
edge_from,
edge_to,
egui::Stroke::new(5.0, egui::Color32::from_rgb(255, 0, 255)),
);
}
_ => (),
}
}
for index in navmesh.graph().node_indices() {
if menu_bar.show_guide_circles {
if let Some(navcord) = activity.maybe_navcord() {

View File

@ -116,10 +116,10 @@ pub enum ThetastarState<N: Copy, E: Copy> {
/// on the navmesh.
///
/// Conditional repeated backtracking is our improvement to Theta*: if
/// line-of-sight routing fails if a condition is met, continue trying to draw
/// from parent of the parent navnode, and so on. This is different from Theta*
/// because in Theta* there is only one backtracking step -- only one attempt to
/// do line-of-sight routing.
/// line-of-sight routing fails, for as long as a condition is met, continue
/// trying to draw from parent of the parent navnode, and so on. This is
/// different from Theta* because in Theta* there is only one backtracking step
/// -- only one attempt to do line-of-sight routing.
#[derive(Getters)]
pub struct ThetastarStepper<G, K>
where