diff --git a/rust/src/geometry.rs b/rust/src/geometry.rs index f5b724b..0c219d0 100644 --- a/rust/src/geometry.rs +++ b/rust/src/geometry.rs @@ -125,7 +125,7 @@ impl Line { vertical = other; regular = self; } - return Some(Point::from_line_x(®ular, vertical.p1.x)); + return Some(Point::from_line_x(regular, vertical.p1.x)); } // Calculate x coordinate of intersection point between both lines @@ -133,9 +133,9 @@ impl Line { // Solve for x: x = (b1 - b2) / (m2 - m1) let x = (self.b - other.b) / (other.m - self.m); if self.m.abs() < other.m.abs() { - Some(Point::from_line_x(&self, x)) + Some(Point::from_line_x(self, x)) } else { - Some(Point::from_line_x(&other, x)) + Some(Point::from_line_x(other, x)) } } diff --git a/rust/src/pathfinder.rs b/rust/src/pathfinder.rs index 42a7526..7696357 100644 --- a/rust/src/pathfinder.rs +++ b/rust/src/pathfinder.rs @@ -70,6 +70,11 @@ pub struct NodeStorage { final_node: Option, } +pub type NodeStorageIterator<'a> = std::iter::Chain< + std::slice::Iter<'a, Rc>>, + std::option::Iter<'a, Rc>>, +>; + impl NodeStorage { fn new() -> Self { Self::default() @@ -79,7 +84,7 @@ impl NodeStorage { self.regular_nodes.push(node); } - fn initialize_edges(&mut self, node: &NodePtr, walls: &Vec) { + fn initialize_edges(&mut self, node: &NodePtr, walls: &[LineSegment]) { if node.borrow().final_edge.is_none() { let final_edge = self .final_node @@ -118,7 +123,7 @@ impl NodeStorage { node.borrow_mut().edges = Some(edges); } - fn collides_with_wall(&self, line: &LineSegment, walls: &Vec) -> bool { + fn collides_with_wall(&self, line: &LineSegment, walls: &[LineSegment]) -> bool { walls.iter().any(|wall| line.intersection(wall).is_some()) } @@ -128,12 +133,7 @@ impl NodeStorage { } } - pub fn iter( - &self, - ) -> std::iter::Chain< - std::slice::Iter<'_, Rc>>, - std::option::Iter<'_, Rc>>, - > { + pub fn iter(&self) -> NodeStorageIterator { self.regular_nodes.iter().chain(self.final_node.iter()) } }