This commit is contained in:
Manuel Vögele
2022-02-02 10:51:30 +01:00
parent 4d6543174a
commit 78b1e8cc4e
2 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -125,7 +125,7 @@ impl Line {
vertical = other; vertical = other;
regular = self; regular = self;
} }
return Some(Point::from_line_x(&regular, vertical.p1.x)); return Some(Point::from_line_x(regular, vertical.p1.x));
} }
// Calculate x coordinate of intersection point between both lines // Calculate x coordinate of intersection point between both lines
@@ -133,9 +133,9 @@ impl Line {
// Solve for x: x = (b1 - b2) / (m2 - m1) // Solve for x: x = (b1 - b2) / (m2 - m1)
let x = (self.b - other.b) / (other.m - self.m); let x = (self.b - other.b) / (other.m - self.m);
if self.m.abs() < other.m.abs() { if self.m.abs() < other.m.abs() {
Some(Point::from_line_x(&self, x)) Some(Point::from_line_x(self, x))
} else { } else {
Some(Point::from_line_x(&other, x)) Some(Point::from_line_x(other, x))
} }
} }
+8 -8
View File
@@ -70,6 +70,11 @@ pub struct NodeStorage {
final_node: Option<NodePtr>, final_node: Option<NodePtr>,
} }
pub type NodeStorageIterator<'a> = std::iter::Chain<
std::slice::Iter<'a, Rc<RefCell<Node>>>,
std::option::Iter<'a, Rc<RefCell<Node>>>,
>;
impl NodeStorage { impl NodeStorage {
fn new() -> Self { fn new() -> Self {
Self::default() Self::default()
@@ -79,7 +84,7 @@ impl NodeStorage {
self.regular_nodes.push(node); self.regular_nodes.push(node);
} }
fn initialize_edges(&mut self, node: &NodePtr, walls: &Vec<LineSegment>) { fn initialize_edges(&mut self, node: &NodePtr, walls: &[LineSegment]) {
if node.borrow().final_edge.is_none() { if node.borrow().final_edge.is_none() {
let final_edge = self let final_edge = self
.final_node .final_node
@@ -118,7 +123,7 @@ impl NodeStorage {
node.borrow_mut().edges = Some(edges); node.borrow_mut().edges = Some(edges);
} }
fn collides_with_wall(&self, line: &LineSegment, walls: &Vec<LineSegment>) -> bool { fn collides_with_wall(&self, line: &LineSegment, walls: &[LineSegment]) -> bool {
walls.iter().any(|wall| line.intersection(wall).is_some()) walls.iter().any(|wall| line.intersection(wall).is_some())
} }
@@ -128,12 +133,7 @@ impl NodeStorage {
} }
} }
pub fn iter( pub fn iter(&self) -> NodeStorageIterator {
&self,
) -> std::iter::Chain<
std::slice::Iter<'_, Rc<RefCell<Node>>>,
std::option::Iter<'_, Rc<RefCell<Node>>>,
> {
self.regular_nodes.iter().chain(self.final_node.iter()) self.regular_nodes.iter().chain(self.final_node.iter())
} }
} }