diff --git a/src/router/mesh.rs b/src/router/mesh.rs index 9d7cac4..a6f8f9e 100644 --- a/src/router/mesh.rs +++ b/src/router/mesh.rs @@ -83,30 +83,27 @@ pub struct Mesh { } impl Mesh { - pub fn new(layout: &Layout) -> Self { + pub fn new(layout: &Layout) -> Result { let mut this = Self { triangulation: Triangulation::new(layout.drawing()), vertex_to_triangulation_vertex: Vec::new(), }; this.vertex_to_triangulation_vertex .resize(layout.drawing().geometry().graph().node_bound(), None); - this - } - pub fn generate(&mut self, layout: &Layout) -> Result<(), InsertionError> { for node in layout.drawing().primitive_nodes() { let center = node.primitive(layout.drawing()).shape().center(); match node { PrimitiveIndex::FixedDot(dot) => { - self.triangulation.add_vertex(TriangulationWeight { + this.triangulation.add_vertex(TriangulationWeight { vertex: dot.into(), rails: vec![], pos: center, })?; } PrimitiveIndex::FixedBend(bend) => { - self.triangulation.add_vertex(TriangulationWeight { + this.triangulation.add_vertex(TriangulationWeight { vertex: bend.into(), rails: vec![], pos: center, @@ -120,18 +117,18 @@ impl Mesh { // Add rails as vertices. This is how the mesh differs from the triangulation. match node { PrimitiveIndex::LooseBend(bend) => { - self.triangulation + this.triangulation .weight_mut(layout.drawing().primitive(bend).core().into()) .rails .push(bend.into()); - self.vertex_to_triangulation_vertex[bend.node_index().index()] = + this.vertex_to_triangulation_vertex[bend.node_index().index()] = Some(layout.drawing().primitive(bend).core().into()); } _ => (), } } - Ok(()) + Ok(this) } pub fn triangulation_vertex(&self, vertex: VertexIndex) -> TriangulationVertexIndex { diff --git a/src/router/router.rs b/src/router/router.rs index 11bb853..7d34515 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -149,8 +149,7 @@ impl Router { // XXX: Should we actually store the mesh? May be useful for debugging, but doesn't look // right. //self.mesh.triangulate(&self.layout)?; - let mut mesh = Mesh::new(&self.layout); - mesh.generate(&self.layout).map_err(|err| RoutingError { + let mesh = Mesh::new(&self.layout).map_err(|err| RoutingError { from, to, source: err.into(),