Skip to content

Commit

Permalink
Merge pull request #1215 from hannobraun/duplication
Browse files Browse the repository at this point in the history
Fix some `SurfaceVertex` duplication issues
  • Loading branch information
hannobraun authored Oct 12, 2022
2 parents 2dcd433 + 4794ede commit 9845024
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
4 changes: 3 additions & 1 deletion crates/fj-kernel/src/algorithms/sweep/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
42 changes: 17 additions & 25 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,33 +92,25 @@ impl Sweep for (Vertex, Handle<Surface>) {
)
};

// 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)
Expand Down
41 changes: 34 additions & 7 deletions crates/fj-kernel/src/partial/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HalfEdge> = 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)
}
Expand Down

0 comments on commit 9845024

Please sign in to comment.