diff --git a/src/draw.rs b/src/draw.rs index e7a22f7..54abd1d 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -171,6 +171,7 @@ impl<'a> Draw<'a> { .prev() .map(|prev_dot| { self.layout.remove_interior(&segbend); + self.layout.remove(head.dot); Head { dot: prev_dot, diff --git a/src/main.rs b/src/main.rs index bed772b..d497c21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -307,14 +307,14 @@ fn render_times( } } } - let envelope = shape.envelope(); + /*let envelope = shape.envelope(); let _ = canvas.rectangle( envelope.lower()[0] as i16, envelope.lower()[1] as i16, envelope.upper()[0] as i16, envelope.upper()[1] as i16, Color::RGB(100, 100, 100), - ); + );*/ } /*for edge in router.routeedges() { diff --git a/src/route.rs b/src/route.rs index 171d3de..cf89d36 100644 --- a/src/route.rs +++ b/src/route.rs @@ -36,17 +36,17 @@ impl<'a> Route<'a> { } } - pub fn finish(&mut self, trace: Trace, into: VertexIndex, width: f64) -> Result<(), ()> { + pub fn finish(&mut self, trace: &mut Trace, into: VertexIndex, width: f64) -> Result<(), ()> { let into_dot = self.mesh.dot(into); self.draw().finish(trace.head, into_dot, width) } pub fn rework_path( &mut self, - mut trace: Trace, + trace: &mut Trace, path: &[VertexIndex], width: f64, - ) -> Result { + ) -> Result<(), ()> { let prefix_length = trace .path .iter() @@ -55,41 +55,37 @@ impl<'a> Route<'a> { .count(); let length = trace.path.len(); - trace = self.undo_path(trace, length - prefix_length)?; + self.undo_path(trace, length - prefix_length)?; self.path(trace, &path[prefix_length..], width) } - pub fn path( - &mut self, - mut trace: Trace, - path: &[VertexIndex], - width: f64, - ) -> Result { + pub fn path(&mut self, trace: &mut Trace, path: &[VertexIndex], width: f64) -> Result<(), ()> { for vertex in path { - trace = self.step(trace, *vertex, width)?; + self.step(trace, *vertex, width)?; } - Ok(trace) + Ok(()) } - pub fn undo_path(&mut self, mut trace: Trace, step_count: usize) -> Result { + pub fn undo_path(&mut self, trace: &mut Trace, step_count: usize) -> Result<(), ()> { for _ in 0..step_count { - trace = self.undo_step(trace)?; + self.undo_step(trace)?; } - Ok(trace) + Ok(()) } - pub fn step(&mut self, mut trace: Trace, to: VertexIndex, width: f64) -> Result { + pub fn step(&mut self, trace: &mut Trace, to: VertexIndex, width: f64) -> Result<(), ()> { let to_dot = self.mesh.dot(to); trace.head = self .draw() .segbend_around_dot(trace.head, to_dot, true, width)?; - Ok(trace) + trace.path.push(to); + Ok(()) } - pub fn undo_step(&mut self, mut trace: Trace) -> Result { + pub fn undo_step(&mut self, trace: &mut Trace) -> Result<(), ()> { trace.head = self.draw().undo_segbend(trace.head).unwrap(); trace.path.pop(); - Ok(trace) + Ok(()) } fn draw(&mut self) -> Draw { diff --git a/src/router.rs b/src/router.rs index 73815bd..d4b816c 100644 --- a/src/router.rs +++ b/src/router.rs @@ -36,31 +36,32 @@ impl Router { let mut mesh = Mesh::new(); mesh.triangulate(&self.layout)?; + let mut route = self.route(&mesh); + let mut trace = route.start(mesh.vertex(from)); + let (_cost, path) = astar( &mesh, mesh.vertex(from), |node, tracker| { let new_path = tracker.reconstruct_path_to(node); - (node != mesh.vertex(to)).then_some(0) + if node == mesh.vertex(to) { + route + .rework_path(&mut trace, &new_path[..new_path.len() - 1], 5.0) + .ok(); + route + .finish(&mut trace, new_path[new_path.len() - 1], 5.0) + .ok(); + None + } else { + route.rework_path(&mut trace, &new_path, 5.0).ok(); + Some(0) + } }, |_edge| 1, |_| 0, ) .unwrap(); // TODO. - - /*let path: Vec = mesh_path - .iter() - .map(|vertex| self.mesh.dot(*vertex)) - .collect();*/ - - let mut trace = self.route(&mesh).start(path[0]); - trace = self - .route(&mesh) - .path(trace, &path[1..(path.len() - 1)], 5.0) - .unwrap(); // TODO. - let _ = self.route(&mesh).finish(trace, path[path.len() - 1], 5.0); - Ok(()) }