mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-17 00:12:36 -06:00
docs: post-creation neighbor edges, no ignore result err
This commit is contained in:
@@ -61,11 +61,6 @@ impl Intersection {
|
|||||||
[self.up, self.down, self.left, self.right].into_iter().flatten()
|
[self.up, self.down, self.left, self.right].into_iter().flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over all directions that don't have an edge.
|
|
||||||
pub fn empty_directions(&self) -> impl Iterator<Item = Direction> + '_ {
|
|
||||||
DIRECTIONS.into_iter().filter(|dir| self.get(*dir).is_none())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the edge in the specified direction, if it exists.
|
/// Retrieves the edge in the specified direction, if it exists.
|
||||||
pub fn get(&self, direction: Direction) -> Option<Edge> {
|
pub fn get(&self, direction: Direction) -> Option<Edge> {
|
||||||
match direction {
|
match direction {
|
||||||
|
|||||||
@@ -168,12 +168,15 @@ impl Map {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// While most nodes are already connected to their neighbors, some may not be
|
||||||
for (grid_pos, &node_id) in &grid_to_node {
|
for (grid_pos, &node_id) in &grid_to_node {
|
||||||
for dir in DIRECTIONS {
|
for dir in DIRECTIONS {
|
||||||
|
// If the node doesn't have an edge in this direction, look for a neighbor in that direction
|
||||||
if graph.adjacency_list[node_id].get(dir).is_none() {
|
if graph.adjacency_list[node_id].get(dir).is_none() {
|
||||||
let neighbor = grid_pos + dir.to_ivec2();
|
let neighbor = grid_pos + dir.to_ivec2();
|
||||||
|
// If the neighbor exists, connect the node to it
|
||||||
if let Some(&neighbor_id) = grid_to_node.get(&neighbor) {
|
if let Some(&neighbor_id) = grid_to_node.get(&neighbor) {
|
||||||
let _ = graph.connect(node_id, neighbor_id, None, dir);
|
graph.connect(node_id, neighbor_id, None, dir).expect("Failed to add edge");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user