Merge pull request #1222 from hannobraun/duplication

Fix another object duplication issue
This commit is contained in:
Hanno Braun 2022-10-14 17:14:54 +02:00 committed by GitHub
commit 2ff3275d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 13 deletions

View File

@ -105,6 +105,28 @@ impl MaybePartial<GlobalEdge> {
}
impl MaybePartial<HalfEdge> {
/// Access the back vertex
pub fn back(&self) -> Option<MaybePartial<Vertex>> {
match self {
Self::Full(full) => Some(full.back().clone().into()),
Self::Partial(partial) => {
let [back, _] = &partial.vertices;
back.clone()
}
}
}
/// Access the front vertex
pub fn front(&self) -> Option<MaybePartial<Vertex>> {
match self {
Self::Full(full) => Some(full.front().clone().into()),
Self::Partial(partial) => {
let [_, front] = &partial.vertices;
front.clone()
}
}
}
/// Access the vertices
pub fn vertices(&self) -> [Option<MaybePartial<Vertex>>; 2] {
match self {

View File

@ -160,21 +160,46 @@ impl PartialCycle {
}
/// Build a full [`Cycle`] from the partial cycle
pub fn build(self, objects: &Objects) -> Cycle {
pub fn build(mut self, objects: &Objects) -> Cycle {
let surface = self.surface.expect("Need surface to build `Cycle`");
let surface_for_edges = surface.clone();
let half_edges = {
let last_vertex = self
.half_edges
.last_mut()
.and_then(|half_edge| {
half_edge.front().map(|vertex| (half_edge, vertex))
})
.and_then(|(half_edge, vertex)| {
vertex.surface_form().map(|surface_vertex| {
(half_edge, vertex, surface_vertex)
})
})
.map(|(half_edge, vertex, surface_vertex)| {
let surface_vertex = surface_vertex
.update_partial(|surface_vertex| {
surface_vertex.with_surface(Some(surface.clone()))
})
.into_full(objects);
*half_edge =
half_edge.clone().update_partial(|half_edge| {
half_edge.with_front_vertex(Some(
vertex.update_partial(|vertex| {
vertex.with_surface_form(Some(
surface_vertex.clone(),
))
}),
))
});
surface_vertex
});
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
(Vec::new(), last_vertex),
|(mut half_edges, previous_vertex), half_edge| {
let half_edge = half_edge
.update_partial(|half_edge| {
let [from, _] = half_edge.vertices.clone();
let from = from.map(|vertex| {
@ -189,9 +214,10 @@ impl PartialCycle {
})
.into_full(objects);
half_edges.push(next.clone());
let front = half_edge.front().surface_form().clone();
half_edges.push(half_edge);
(half_edges, Some(next))
(half_edges, Some(front))
},
);