Skip to content

Commit

Permalink
Merge pull request #1222 from hannobraun/duplication
Browse files Browse the repository at this point in the history
Fix another object duplication issue
  • Loading branch information
hannobraun authored Oct 14, 2022
2 parents c4d866f + 048db7f commit 2ff3275
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
22 changes: 22 additions & 0 deletions crates/fj-kernel/src/partial/maybe_partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 38 additions & 12 deletions crates/fj-kernel/src/partial/objects/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (half_edges, _) = self.half_edges.into_iter().fold(
(Vec::new(), None),
|(mut half_edges, previous), next| {
let previous_half_edge: Option<HalfEdge> = previous;
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);

let previous_vertex = previous_half_edge.map(|half_edge| {
let [_, vertex] = half_edge.vertices().clone();
vertex.surface_form().clone()
});
*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 next = next
let (half_edges, _) = self.half_edges.into_iter().fold(
(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| {
Expand All @@ -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))
},
);

Expand Down

0 comments on commit 2ff3275

Please sign in to comment.