Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some SurfaceVertex duplication issues #1215

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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