mesh: Remove `Visitable`, `VisitMap` trait impls

I don't know why the original A* implementation needed tem.
This commit is contained in:
Mikolaj Wielgus 2023-11-03 11:16:58 +00:00
parent 13e38c6889
commit 66d5b3e605
2 changed files with 3 additions and 47 deletions

View File

@ -10,7 +10,7 @@ use std::collections::{BinaryHeap, HashMap};
use std::hash::Hash; use std::hash::Hash;
use petgraph::algo::Measure; use petgraph::algo::Measure;
use petgraph::visit::{EdgeRef, GraphBase, IntoEdges, Visitable}; use petgraph::visit::{EdgeRef, GraphBase, IntoEdges};
use std::cmp::Ordering; use std::cmp::Ordering;
@ -96,7 +96,7 @@ where
pub trait AstarStrategy<G, K> pub trait AstarStrategy<G, K>
where where
G: IntoEdges + Visitable, G: IntoEdges,
K: Measure + Copy, K: Measure + Copy,
G::NodeId: Eq + Hash, G::NodeId: Eq + Hash,
{ {
@ -111,7 +111,7 @@ pub fn astar<G, K>(
strategy: &mut impl AstarStrategy<G, K>, strategy: &mut impl AstarStrategy<G, K>,
) -> Option<(K, Vec<G::NodeId>)> ) -> Option<(K, Vec<G::NodeId>)>
where where
G: IntoEdges + Visitable, G: IntoEdges,
G::NodeId: Eq + Hash, G::NodeId: Eq + Hash,
K: Measure + Copy, K: Measure + Copy,
{ {

View File

@ -91,50 +91,6 @@ impl visit::GraphBase for Mesh {
type EdgeId = (VertexIndex, VertexIndex); type EdgeId = (VertexIndex, VertexIndex);
} }
pub struct MeshVisitMap {
fixedbitset: FixedBitSet,
}
impl MeshVisitMap {
pub fn with_capacity(bits: usize) -> Self {
Self {
fixedbitset: FixedBitSet::with_capacity(bits),
}
}
pub fn clear(&mut self) {
self.fixedbitset.clear();
}
pub fn grow(&mut self, bits: usize) {
self.fixedbitset.grow(bits);
}
}
impl<T: GetNodeIndex> visit::VisitMap<T> for MeshVisitMap {
fn visit(&mut self, a: T) -> bool {
!self.fixedbitset.put(a.node_index().index())
}
fn is_visited(&self, a: &T) -> bool {
self.fixedbitset.contains(a.node_index().index())
}
}
impl visit::Visitable for Mesh {
type Map = MeshVisitMap;
fn visit_map(&self) -> Self::Map {
// FIXME: This seems wrong, but pathfinding works for some reason. Investigate.
MeshVisitMap::with_capacity(self.triangulation.num_vertices())
}
fn reset_map(&self, map: &mut Self::Map) {
map.clear();
map.grow(self.triangulation.num_vertices());
}
}
impl visit::Data for Mesh { impl visit::Data for Mesh {
type NodeWeight = (); type NodeWeight = ();
type EdgeWeight = (); type EdgeWeight = ();