From 4346be437fe30bba2ad91595372966ffcada7b04 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 31 Oct 2022 14:15:34 +0100 Subject: [PATCH 1/5] Simplify method return value --- crates/fj-kernel/src/objects/edge.rs | 6 ++---- crates/fj-kernel/src/partial/maybe_partial.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 6 ++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/objects/edge.rs b/crates/fj-kernel/src/objects/edge.rs index a82f0b795..39749cb3e 100644 --- a/crates/fj-kernel/src/objects/edge.rs +++ b/crates/fj-kernel/src/objects/edge.rs @@ -56,12 +56,10 @@ impl HalfEdge { assert_eq!( vertices_in_normalized_order .access_in_normalized_order() - .clone() .map(|global_vertex| global_vertex.id()), global_form .vertices() .access_in_normalized_order() - .clone() .map(|global_vertex| global_vertex.id()), "The global forms of a half-edge's vertices must match the \ vertices of the half-edge's global form" @@ -192,8 +190,8 @@ impl VerticesInNormalizedOrder { /// Access the vertices /// /// The vertices in the returned array will be in normalized order. - pub fn access_in_normalized_order(&self) -> &[Handle; 2] { - &self.0 + pub fn access_in_normalized_order(&self) -> [Handle; 2] { + self.0.clone() } } diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 647038d4e..ca39d1bfc 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -118,12 +118,12 @@ impl MaybePartial { } /// Access the vertices - pub fn vertices(&self) -> Option<&[Handle; 2]> { + pub fn vertices(&self) -> Option<[Handle; 2]> { match self { Self::Full(full) => { Some(full.vertices().access_in_normalized_order()) } - Self::Partial(partial) => partial.vertices.as_ref(), + Self::Partial(partial) => partial.vertices.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 669ca7986..52f551d38 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -43,7 +43,7 @@ impl PartialHalfEdge { /// Access the vertices of the global form, if available pub fn extract_global_vertices(&self) -> Option<[Handle; 2]> { - self.global_form.vertices().cloned() + self.global_form.vertices() } /// Update the partial half-edge with the given surface @@ -377,9 +377,7 @@ impl From<&GlobalEdge> for PartialGlobalEdge { fn from(global_edge: &GlobalEdge) -> Self { Self { curve: Some(global_edge.curve().clone().into()), - vertices: Some( - global_edge.vertices().access_in_normalized_order().clone(), - ), + vertices: Some(global_edge.vertices().access_in_normalized_order()), } } } From 52b0fb8c67f124d557320f1817e67b9297c12495 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 31 Oct 2022 14:21:04 +0100 Subject: [PATCH 2/5] Make return value more general --- crates/fj-kernel/src/partial/objects/edge.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 52f551d38..4e4662ce2 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -42,8 +42,12 @@ impl PartialHalfEdge { } /// Access the vertices of the global form, if available - pub fn extract_global_vertices(&self) -> Option<[Handle; 2]> { - self.global_form.vertices() + pub fn extract_global_vertices( + &self, + ) -> Option<[MaybePartial; 2]> { + self.global_form + .vertices() + .map(|vertices| vertices.map(Into::into)) } /// Update the partial half-edge with the given surface @@ -136,7 +140,7 @@ impl PartialHalfEdge { let global_vertex = self .extract_global_vertices() - .map(|[global_form, _]| MaybePartial::from(global_form)) + .map(|[global_form, _]| global_form) .unwrap_or_else(|| { GlobalVertex::partial() .from_curve_and_position(curve.clone(), a_curve) From 80bee662616682dd1f4bbd33e376203e7c356c0c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Mon, 31 Oct 2022 14:21:55 +0100 Subject: [PATCH 3/5] Make return value more general --- crates/fj-kernel/src/partial/maybe_partial.rs | 13 ++++++++----- crates/fj-kernel/src/partial/objects/edge.rs | 4 +--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index ca39d1bfc..452190548 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -118,12 +118,15 @@ impl MaybePartial { } /// Access the vertices - pub fn vertices(&self) -> Option<[Handle; 2]> { + pub fn vertices(&self) -> Option<[MaybePartial; 2]> { match self { - Self::Full(full) => { - Some(full.vertices().access_in_normalized_order()) - } - Self::Partial(partial) => partial.vertices.clone(), + Self::Full(full) => Some( + full.vertices().access_in_normalized_order().map(Into::into), + ), + Self::Partial(partial) => partial + .vertices + .clone() + .map(|vertices| vertices.map(Into::into)), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 4e4662ce2..b9eca7712 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -45,9 +45,7 @@ impl PartialHalfEdge { pub fn extract_global_vertices( &self, ) -> Option<[MaybePartial; 2]> { - self.global_form - .vertices() - .map(|vertices| vertices.map(Into::into)) + self.global_form.vertices() } /// Update the partial half-edge with the given surface From 4780beac819e7045979a900c45126db5bf47803f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 1 Nov 2022 12:43:12 +0100 Subject: [PATCH 4/5] Make struct field more general --- crates/fj-kernel/src/partial/maybe_partial.rs | 5 +---- crates/fj-kernel/src/partial/objects/edge.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 452190548..71406b779 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -123,10 +123,7 @@ impl MaybePartial { Self::Full(full) => Some( full.vertices().access_in_normalized_order().map(Into::into), ), - Self::Partial(partial) => partial - .vertices - .clone() - .map(|vertices| vertices.map(Into::into)), + Self::Partial(partial) => partial.vertices.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index b9eca7712..e1df84733 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -322,7 +322,7 @@ pub struct PartialGlobalEdge { /// The vertices that bound the [`GlobalEdge`] in the curve /// /// Must be provided before [`PartialGlobalEdge::build`] is called. - pub vertices: Option<[Handle; 2]>, + pub vertices: Option<[MaybePartial; 2]>, } impl PartialGlobalEdge { @@ -340,7 +340,7 @@ impl PartialGlobalEdge { vertices: Option<[Handle; 2]>, ) -> Self { if let Some(vertices) = vertices { - self.vertices = Some(vertices); + self.vertices = Some(vertices.map(Into::into)); } self } @@ -367,7 +367,8 @@ impl PartialGlobalEdge { .expect("Can't build `GlobalEdge` without `GlobalCurve`"); let vertices = self .vertices - .expect("Can't build `GlobalEdge` without vertices"); + .expect("Can't build `GlobalEdge` without vertices") + .try_map_ext(|global_vertex| global_vertex.into_full(objects))?; Ok(objects .global_edges @@ -379,7 +380,12 @@ impl From<&GlobalEdge> for PartialGlobalEdge { fn from(global_edge: &GlobalEdge) -> Self { Self { curve: Some(global_edge.curve().clone().into()), - vertices: Some(global_edge.vertices().access_in_normalized_order()), + vertices: Some( + global_edge + .vertices() + .access_in_normalized_order() + .map(Into::into), + ), } } } From 2b266959224a1550eafabb7294532f064aefa0d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 1 Nov 2022 12:45:34 +0100 Subject: [PATCH 5/5] Make method argument more general --- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index e1df84733..5faf78ef3 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -337,7 +337,7 @@ impl PartialGlobalEdge { /// Update the partial global edge with the given vertices pub fn with_vertices( mut self, - vertices: Option<[Handle; 2]>, + vertices: Option<[impl Into>; 2]>, ) -> Self { if let Some(vertices) = vertices { self.vertices = Some(vertices.map(Into::into));