Fix object duplication in PartialHalfEdge::build

This commit is contained in:
Hanno Braun 2022-10-12 16:08:21 +02:00
parent 6e446a23ad
commit 4794eded4b

View File

@ -163,14 +163,41 @@ impl PartialCycle {
pub fn build(self, objects: &Objects) -> Cycle { pub fn build(self, objects: &Objects) -> Cycle {
let surface = self.surface.expect("Need surface to build `Cycle`"); let surface = self.surface.expect("Need surface to build `Cycle`");
let surface_for_edges = surface.clone(); let surface_for_edges = surface.clone();
let half_edges = self.half_edges.into_iter().map(|half_edge| { let half_edges = {
half_edge let (half_edges, _) = self.half_edges.into_iter().fold(
.update_partial(|half_edge| { (Vec::new(), None),
half_edge.with_surface(Some(surface_for_edges.clone())) |(mut half_edges, previous), next| {
}) let previous_half_edge: Option<HalfEdge> = previous;
.into_full(objects)
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) Cycle::new(surface, half_edges)
} }
} }