diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 5bbd90650..17f3d7de0 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -169,7 +169,9 @@ impl Sweep for (HalfEdge, Color) { // Need to compare surface forms here, as the global forms might // be coincident when sweeping circles, despite the vertices // being different! - if prev_last.surface_form() != next_first.surface_form() { + if prev_last.surface_form().id() + != next_first.surface_form().id() + { edges[j] = edges[j].clone().reverse(); } diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 4238bd58a..8d96aa216 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -92,33 +92,25 @@ impl Sweep for (Vertex, Handle) { ) }; - // And now the vertices. Again, nothing wild here. - let vertices = { - // Can be cleaned up, once `zip` is stable: - // https://doc.rust-lang.org/std/primitive.array.html#method.zip - let [a_surface, b_surface] = points_surface; - let [a_global, b_global] = vertices_global; - let vertices_surface = - [(a_surface, a_global), (b_surface, b_global)].map( - |(point_surface, vertex_global)| { - SurfaceVertex::new( - point_surface, - surface.clone(), - vertex_global, - objects, - ) - }, - ); - - vertices_surface.map(|surface_form| { - Vertex::new( - [surface_form.position().v], - curve.clone(), - surface_form, - ) - }) + let vertices_surface = { + let [_, position] = points_surface; + let [_, global_form] = vertices_global; + + [ + vertex.surface_form().clone(), + SurfaceVertex::new(position, surface, global_form, objects), + ] }; + // And now the vertices. Again, nothing wild here. + let vertices = vertices_surface.map(|surface_form| { + Vertex::new( + [surface_form.position().v], + curve.clone(), + surface_form, + ) + }); + // And finally, creating the output `Edge` is just a matter of // assembling the pieces we've already created. HalfEdge::new(vertices, edge_global) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index f918b685d..9b35789dd 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -163,13 +163,40 @@ impl PartialCycle { pub fn build(self, objects: &Objects) -> Cycle { let surface = self.surface.expect("Need surface to build `Cycle`"); let surface_for_edges = surface.clone(); - let half_edges = self.half_edges.into_iter().map(|half_edge| { - half_edge - .update_partial(|half_edge| { - half_edge.with_surface(Some(surface_for_edges.clone())) - }) - .into_full(objects) - }); + let half_edges = { + let (half_edges, _) = self.half_edges.into_iter().fold( + (Vec::new(), None), + |(mut half_edges, previous), next| { + let previous_half_edge: Option = previous; + + let previous_vertex = previous_half_edge.map(|half_edge| { + let [_, vertex] = half_edge.vertices().clone(); + vertex.surface_form().clone() + }); + + let next = next + .update_partial(|half_edge| { + let [from, _] = half_edge.vertices.clone(); + let from = from.map(|vertex| { + vertex.update_partial(|partial| { + partial.with_surface_form(previous_vertex) + }) + }); + + half_edge + .with_surface(Some(surface_for_edges.clone())) + .with_from_vertex(from) + }) + .into_full(objects); + + half_edges.push(next.clone()); + + (half_edges, Some(next)) + }, + ); + + half_edges + }; Cycle::new(surface, half_edges) }