implemented default implementation for WheightedGraph num_edges
This commit is contained in:
parent
f25b58448e
commit
ec1a255898
2 changed files with 4 additions and 45 deletions
|
|
@ -156,50 +156,6 @@ struct MapInternal<'a> {
|
|||
impl<'a> WheightedGraph for MapInternal<'a> {
|
||||
type Node = (Position, Direction);
|
||||
|
||||
fn num_edges(&self, node: &Self::Node) -> usize {
|
||||
todo!();
|
||||
// let next = node.0.in_direction(&node.1, 1);
|
||||
// if next
|
||||
// .in_range(
|
||||
// &Position::new(0, 0),
|
||||
// &Position::new(
|
||||
// self.map.width as PositionType,
|
||||
// self.map.height as PositionType,
|
||||
// ),
|
||||
// )
|
||||
// .is_some()
|
||||
// {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// if self.map.get(next.x as usize, next.y as usize).blocked {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// let mut count = 3;
|
||||
|
||||
// for l in 2..=6 {
|
||||
// let n = node.0.in_direction(&node.1, l);
|
||||
// dbg!(n, l);
|
||||
// if n.in_range(
|
||||
// &Position::new(0, 0),
|
||||
// &Position::new(
|
||||
// self.map.width as PositionType,
|
||||
// self.map.height as PositionType,
|
||||
// ),
|
||||
// )
|
||||
// .is_some()
|
||||
// {
|
||||
// return count;
|
||||
// }
|
||||
// if !self.map.get(n.x as usize, n.y as usize).blocked {
|
||||
// count += 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// count
|
||||
}
|
||||
|
||||
fn edge(&self, node: &Self::Node, num: usize) -> Option<(Self::Node, f64)> {
|
||||
let next = node.0.in_direction(&node.1, 1);
|
||||
if next
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ pub mod shortest_path;
|
|||
|
||||
pub trait WheightedGraph: Sized {
|
||||
type Node;
|
||||
fn num_edges(&self, node: &Self::Node) -> usize;
|
||||
fn num_edges(&self, node: &Self::Node) -> usize {
|
||||
self.edge_iter(node).count()
|
||||
}
|
||||
|
||||
fn edge(&self, node: &Self::Node, num: usize) -> Option<(Self::Node, f64)>;
|
||||
|
||||
fn edge_iter<'a, 'b>(&'a self, node: &'b Self::Node) -> WheightedGraphEdgeIter<'a, 'b, Self> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue