From 7f3519a98e55a04483bdcf90f9ffa50bbbe1e37d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 14:45:02 +0200 Subject: [PATCH 1/4] Add vertex getters to `MaybePartial` --- crates/fj-kernel/src/partial/maybe_partial.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 973f0ccb6..dc8edd741 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -105,6 +105,28 @@ impl MaybePartial { } impl MaybePartial { + /// Access the back vertex + pub fn back(&self) -> Option> { + 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> { + 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>; 2] { match self { From b39c3ba09701a88c2613802a866beb4ee1ec581e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 14:54:34 +0200 Subject: [PATCH 2/4] Refactor --- crates/fj-kernel/src/partial/objects/cycle.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 3b3167b70..bbb15c2c6 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -166,14 +166,7 @@ impl PartialCycle { 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 = previous; - - let previous_vertex = previous_half_edge.map(|half_edge| { - let [_, vertex] = half_edge.vertices().clone(); - vertex.surface_form().clone() - }); - + |(mut half_edges, previous_vertex), next| { let next = next .update_partial(|half_edge| { let [from, _] = half_edge.vertices.clone(); @@ -189,9 +182,10 @@ impl PartialCycle { }) .into_full(objects); - half_edges.push(next.clone()); + let front = next.front().surface_form().clone(); + half_edges.push(next); - (half_edges, Some(next)) + (half_edges, Some(front)) }, ); From b0ac9a9d70a888f5a3400e0f067c0969b71df560 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 15:06:44 +0200 Subject: [PATCH 3/4] Update variable names The previous ones no long fit the current code. --- crates/fj-kernel/src/partial/objects/cycle.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index bbb15c2c6..2c791cadc 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -166,8 +166,8 @@ impl PartialCycle { let half_edges = { let (half_edges, _) = self.half_edges.into_iter().fold( (Vec::new(), None), - |(mut half_edges, previous_vertex), next| { - let next = next + |(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| { @@ -182,8 +182,8 @@ impl PartialCycle { }) .into_full(objects); - let front = next.front().surface_form().clone(); - half_edges.push(next); + let front = half_edge.front().surface_form().clone(); + half_edges.push(half_edge); (half_edges, Some(front)) }, From 048db7f1fc55082e9cf50dac7918da1b316c3861 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 14 Oct 2022 16:43:33 +0200 Subject: [PATCH 4/4] Fix `SurfaceVertex` duplication issue The first and last `SurfaceVertex` of the `Cycle` built in this code wasn't the same. --- crates/fj-kernel/src/partial/objects/cycle.rs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index 2c791cadc..f4df40e7c 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -160,12 +160,44 @@ 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), + (Vec::new(), last_vertex), |(mut half_edges, previous_vertex), half_edge| { let half_edge = half_edge .update_partial(|half_edge| {