router: impl. forgotten addition of edges to navmesh

This commit is contained in:
Mikolaj Wielgus 2024-06-20 18:50:50 +02:00
parent c24d748bea
commit 4540f5c96b
2 changed files with 18 additions and 2 deletions

View File

@ -1,9 +1,11 @@
use std::collections::HashMap;
use enum_dispatch::enum_dispatch; use enum_dispatch::enum_dispatch;
use geo::Point; use geo::Point;
use petgraph::{ use petgraph::{
graph::UnGraph, graph::UnGraph,
stable_graph::NodeIndex, stable_graph::NodeIndex,
visit::{IntoNodeIdentifiers, NodeIndexable}, visit::{EdgeRef, IntoEdgeReferences, IntoEdges, IntoNodeIdentifiers, NodeIndexable},
}; };
use spade::{HasPosition, InsertionError, Point2}; use spade::{HasPosition, InsertionError, Point2};
use thiserror::Error; use thiserror::Error;
@ -139,6 +141,9 @@ impl Navmesh {
let mut source_vertex = None; let mut source_vertex = None;
let mut target_vertex = None; let mut target_vertex = None;
// `HashMap` is obviously suboptimal here.
let mut map = HashMap::new();
for trianvertex in triangulation.node_identifiers() { for trianvertex in triangulation.node_identifiers() {
let navvertex = graph.add_node(NavvertexWeight { let navvertex = graph.add_node(NavvertexWeight {
node: trianvertex.into(), node: trianvertex.into(),
@ -149,6 +154,17 @@ impl Navmesh {
} else if trianvertex == target.into() { } else if trianvertex == target.into() {
target_vertex = Some(navvertex); target_vertex = Some(navvertex);
} }
map.insert(trianvertex, navvertex);
/*// TODO: iterate over triangulation's edges instead of vertices.
for edge in triangulation.edges(trianvertex) {
graph.add_edge(edge.source(), edge.target(), &edge.weight());
}*/
}
for edge in triangulation.edge_references() {
graph.add_edge(map[&edge.source()], map[&edge.target()], ());
} }
Ok(Self { Ok(Self {

View File

@ -109,7 +109,7 @@ impl<'a, R: RulesTrait> Tracer<'a, R> {
} }
} }
#[debug_ensures(ret.is_ok() -> matches!(trace.head, Head::Bare(..)))] #[debug_ensures(ret.is_ok() -> matches!(trace.head, Head::Cane(..)))]
#[debug_ensures(ret.is_ok() -> trace.path.len() == old(trace.path.len() + 1))] #[debug_ensures(ret.is_ok() -> trace.path.len() == old(trace.path.len() + 1))]
#[debug_ensures(ret.is_err() -> trace.path.len() == old(trace.path.len()))] #[debug_ensures(ret.is_err() -> trace.path.len() == old(trace.path.len()))]
pub fn step( pub fn step(