From 5c29b41f0136c6678bc32d58af582f095944fb1b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:11:09 +0100 Subject: [PATCH 01/21] Field fields of `PartialGlobalEdge` public --- crates/fj-kernel/src/partial/objects/edge.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index cbace6209..a72ab4ec8 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -149,8 +149,11 @@ impl From<&HalfEdge> for PartialHalfEdge { /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialGlobalEdge { - curve: MaybePartial, - vertices: Option<[MaybePartial; 2]>, + /// The curve that the [`GlobalEdge`] is defined in + pub curve: MaybePartial, + + /// The vertices that bound the [`GlobalEdge`] in the curve + pub vertices: Option<[MaybePartial; 2]>, } impl PartialGlobalEdge { From 9301babb440da91a0452250b3fbb2b6fbab000f2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:12:00 +0100 Subject: [PATCH 02/21] Remove `PartialGlobalEdge::curve` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 7daf35f31..a08de13d0 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -47,7 +47,7 @@ impl TransformObject for PartialGlobalEdge { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self.curve().transform(transform, objects)?; + let curve = self.curve.clone().transform(transform, objects)?; let vertices = self .vertices() .map(|vertices| { diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index cad49c181..58865456b 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -168,7 +168,7 @@ impl MaybePartial { pub fn curve(&self) -> MaybePartial { match self { Self::Full(full) => full.curve().clone().into(), - Self::Partial(partial) => partial.curve(), + Self::Partial(partial) => partial.curve.clone(), } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a72ab4ec8..ef5df3c59 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -157,11 +157,6 @@ pub struct PartialGlobalEdge { } impl PartialGlobalEdge { - /// Access the curve that the [`GlobalEdge`] is defined in - pub fn curve(&self) -> MaybePartial { - self.curve.clone() - } - /// Access the vertices that bound the [`GlobalEdge`] in the curve pub fn vertices(&self) -> Option<[MaybePartial; 2]> { self.vertices.clone() From f17c0f9db115a6b2950186fc067eaa01a7e31a4e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:12:51 +0100 Subject: [PATCH 03/21] Remove `PartialGlobalEdge::vertices` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 4 ++-- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 5 ----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index a08de13d0..a2535c683 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -47,9 +47,9 @@ impl TransformObject for PartialGlobalEdge { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self.curve.clone().transform(transform, objects)?; + let curve = self.curve.transform(transform, objects)?; let vertices = self - .vertices() + .vertices .map(|vertices| { vertices.try_map_ext(|vertex| -> Result<_, ValidationError> { vertex.transform(transform, objects) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 58865456b..013b51123 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -178,7 +178,7 @@ impl MaybePartial { Self::Full(full) => Some( full.vertices().access_in_normalized_order().map(Into::into), ), - Self::Partial(partial) => partial.vertices(), + 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 ef5df3c59..cbe71b5c8 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -157,11 +157,6 @@ pub struct PartialGlobalEdge { } impl PartialGlobalEdge { - /// Access the vertices that bound the [`GlobalEdge`] in the curve - pub fn vertices(&self) -> Option<[MaybePartial; 2]> { - self.vertices.clone() - } - /// Update the partial global edge with the given curve pub fn with_curve( mut self, From 6b53e964fdba4105e4b585244c6c8f182d9e36c5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:18:47 +0100 Subject: [PATCH 04/21] Remove `PartialGlobalEdge::with_curve` --- .../fj-kernel/src/algorithms/transform/edge.rs | 16 ++++++++++------ crates/fj-kernel/src/builder/edge.rs | 10 +++++----- crates/fj-kernel/src/partial/objects/edge.rs | 11 ----------- crates/fj-kernel/src/validate/edge.rs | 14 +++++--------- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index a2535c683..efdbbfb6e 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -28,11 +28,13 @@ impl TransformObject for PartialHalfEdge { Ok(vertex) }, )?; - let global_form = self + let mut global_form = self .global_form() .into_partial() - .transform(transform, objects)? - .with_curve(curve.global_form()); + .transform(transform, objects)?; + if let Some(curve) = curve.global_form() { + global_form.curve = curve; + } Ok(Self::default() .with_curve(curve) @@ -57,8 +59,10 @@ impl TransformObject for PartialGlobalEdge { }) .transpose()?; - Ok(Self::default() - .with_curve(Some(curve)) - .with_vertices(vertices)) + Ok(Self { + curve, + ..Default::default() + } + .with_vertices(vertices)) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3d276c505..f2218b366 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -235,13 +235,13 @@ pub trait GlobalEdgeBuilder { impl GlobalEdgeBuilder for PartialGlobalEdge { fn update_from_curve_and_vertices( - self, + mut self, curve: &Curve, vertices: &[Handle; 2], ) -> Self { - self.with_curve(Some(curve.global_form().clone())) - .with_vertices(Some( - vertices.clone().map(|vertex| vertex.global_form().clone()), - )) + self.curve = curve.global_form().clone().into(); + self.with_vertices(Some( + vertices.clone().map(|vertex| vertex.global_form().clone()), + )) } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index cbe71b5c8..2e8dcd86d 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -157,17 +157,6 @@ pub struct PartialGlobalEdge { } impl PartialGlobalEdge { - /// Update the partial global edge with the given curve - pub fn with_curve( - mut self, - curve: Option>>, - ) -> Self { - if let Some(curve) = curve { - self.curve = curve.into(); - } - self - } - /// Update the partial global edge with the given vertices pub fn with_vertices( mut self, diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 0a294d415..e7c738532 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -244,15 +244,11 @@ mod tests { [[0., 0.], [1., 0.]], ) .build(&objects)?; - let invalid = HalfEdge::new( - valid.vertices().clone(), - valid - .global_form() - .to_partial() - .with_curve(Some(objects.global_curves.insert(GlobalCurve)?)) - .build(&objects)? - .insert(&objects)?, - ); + let invalid = HalfEdge::new(valid.vertices().clone(), { + let mut tmp = valid.global_form().to_partial(); + tmp.curve = objects.global_curves.insert(GlobalCurve)?.into(); + tmp.build(&objects)?.insert(&objects)? + }); assert!(valid.validate().is_ok()); assert!(invalid.validate().is_err()); From 1451949426ce7ade5f0989b546fdcd29184892d2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:38:49 +0100 Subject: [PATCH 05/21] Remove `PartialGlobalEdge::with_vertices` --- .../src/algorithms/transform/edge.rs | 6 +--- crates/fj-kernel/src/builder/edge.rs | 9 ++++-- crates/fj-kernel/src/partial/objects/edge.rs | 11 -------- crates/fj-kernel/src/validate/edge.rs | 28 ++++++++----------- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index efdbbfb6e..6d0ce8b68 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -59,10 +59,6 @@ impl TransformObject for PartialGlobalEdge { }) .transpose()?; - Ok(Self { - curve, - ..Default::default() - } - .with_vertices(vertices)) + Ok(Self { curve, vertices }) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index f2218b366..49dd597de 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -240,8 +240,11 @@ impl GlobalEdgeBuilder for PartialGlobalEdge { vertices: &[Handle; 2], ) -> Self { self.curve = curve.global_form().clone().into(); - self.with_vertices(Some( - vertices.clone().map(|vertex| vertex.global_form().clone()), - )) + self.vertices = Some( + vertices + .clone() + .map(|vertex| vertex.global_form().clone().into()), + ); + self } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 2e8dcd86d..7e50d6580 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -157,17 +157,6 @@ pub struct PartialGlobalEdge { } impl PartialGlobalEdge { - /// Update the partial global edge with the given vertices - pub fn with_vertices( - mut self, - vertices: Option<[impl Into>; 2]>, - ) -> Self { - if let Some(vertices) = vertices { - self.vertices = Some(vertices.map(Into::into)); - } - self - } - /// Build a full [`GlobalEdge`] from the partial global edge pub fn build( self, diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index e7c738532..f65f6868d 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -266,22 +266,18 @@ mod tests { [[0., 0.], [1., 0.]], ) .build(&objects)?; - let invalid = HalfEdge::new( - valid.vertices().clone(), - valid - .global_form() - .to_partial() - .with_vertices(Some( - valid - .global_form() - .vertices() - .access_in_normalized_order() - // Creating equal but not identical vertices here. - .map(|vertex| vertex.to_partial()), - )) - .build(&objects)? - .insert(&objects)?, - ); + let invalid = HalfEdge::new(valid.vertices().clone(), { + let mut tmp = valid.global_form().to_partial(); + tmp.vertices = Some( + valid + .global_form() + .vertices() + .access_in_normalized_order() + // Creating equal but not identical vertices here. + .map(|vertex| vertex.to_partial().into()), + ); + tmp.build(&objects)?.insert(&objects)? + }); assert!(valid.validate().is_ok()); assert!(invalid.validate().is_err()); From 3a3de92b316ae54f11dd7f04c742132934eb4b27 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:54:32 +0100 Subject: [PATCH 06/21] Rewrite partial object update using merge --- crates/fj-kernel/src/builder/edge.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 49dd597de..e307992fa 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -202,14 +202,14 @@ impl HalfEdgeBuilder for PartialHalfEdge { .collect::<[_; 2]>() .map(|(vertex, global_form)| { vertex.update_partial(|mut vertex| { - vertex.surface_form = vertex - .surface_form - .update_partial(|mut surface_vertex| { - if let Some(global_form) = global_form { - surface_vertex.global_form = global_form; - } - surface_vertex - }); + let mut surface_form = PartialSurfaceVertex::default(); + if let Some(global_form) = global_form { + surface_form.global_form = global_form; + } + + vertex.surface_form = + vertex.surface_form.merge_with(surface_form); + vertex }) }) From b2e59169a15cdcbabee18ec74e28a63757815399 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 18:56:31 +0100 Subject: [PATCH 07/21] Simplify `vertices` field of `PartialGlobalEdge` --- .../src/algorithms/transform/edge.rs | 13 +++++-------- crates/fj-kernel/src/builder/edge.rs | 8 +++----- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 19 +++++++------------ crates/fj-kernel/src/validate/edge.rs | 14 ++++++-------- 5 files changed, 22 insertions(+), 34 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 6d0ce8b68..cded261d6 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -50,14 +50,11 @@ impl TransformObject for PartialGlobalEdge { objects: &Objects, ) -> Result { let curve = self.curve.transform(transform, objects)?; - let vertices = self - .vertices - .map(|vertices| { - vertices.try_map_ext(|vertex| -> Result<_, ValidationError> { - vertex.transform(transform, objects) - }) - }) - .transpose()?; + let vertices = self.vertices.try_map_ext( + |vertex| -> Result<_, ValidationError> { + vertex.transform(transform, objects) + }, + )?; Ok(Self { curve, vertices }) } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index e307992fa..52d10ee37 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -240,11 +240,9 @@ impl GlobalEdgeBuilder for PartialGlobalEdge { vertices: &[Handle; 2], ) -> Self { self.curve = curve.global_form().clone().into(); - self.vertices = Some( - vertices - .clone() - .map(|vertex| vertex.global_form().clone().into()), - ); + self.vertices = vertices + .clone() + .map(|vertex| vertex.global_form().clone().into()); self } } diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 013b51123..f27939536 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -178,7 +178,7 @@ impl MaybePartial { Self::Full(full) => Some( full.vertices().access_in_normalized_order().map(Into::into), ), - Self::Partial(partial) => partial.vertices.clone(), + Self::Partial(partial) => Some(partial.vertices.clone()), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 7e50d6580..cbc165959 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -6,7 +6,7 @@ use crate::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, Vertex, }, - partial::{MaybePartial, MergeWith, Mergeable}, + partial::{MaybePartial, MergeWith}, storage::Handle, validate::ValidationError, }; @@ -153,7 +153,7 @@ pub struct PartialGlobalEdge { pub curve: MaybePartial, /// The vertices that bound the [`GlobalEdge`] in the curve - pub vertices: Option<[MaybePartial; 2]>, + pub vertices: [MaybePartial; 2], } impl PartialGlobalEdge { @@ -165,7 +165,6 @@ impl PartialGlobalEdge { let curve = self.curve.into_full(objects)?; let vertices = self .vertices - .expect("Can't build `GlobalEdge` without vertices") .try_map_ext(|global_vertex| global_vertex.into_full(objects))?; Ok(GlobalEdge::new(curve, vertices)) @@ -178,9 +177,7 @@ impl MergeWith for PartialGlobalEdge { Self { curve: self.curve.merge_with(other.curve), - vertices: Mergeable(self.vertices) - .merge_with(Mergeable(other.vertices)) - .0, + vertices: self.vertices.merge_with(other.vertices), } } } @@ -189,12 +186,10 @@ impl From<&GlobalEdge> for PartialGlobalEdge { fn from(global_edge: &GlobalEdge) -> Self { Self { curve: global_edge.curve().clone().into(), - vertices: Some( - global_edge - .vertices() - .access_in_normalized_order() - .map(Into::into), - ), + vertices: global_edge + .vertices() + .access_in_normalized_order() + .map(Into::into), } } } diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index f65f6868d..54ee9ae74 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -268,14 +268,12 @@ mod tests { .build(&objects)?; let invalid = HalfEdge::new(valid.vertices().clone(), { let mut tmp = valid.global_form().to_partial(); - tmp.vertices = Some( - valid - .global_form() - .vertices() - .access_in_normalized_order() - // Creating equal but not identical vertices here. - .map(|vertex| vertex.to_partial().into()), - ); + tmp.vertices = valid + .global_form() + .vertices() + .access_in_normalized_order() + // Creating equal but not identical vertices here. + .map(|vertex| vertex.to_partial().into()); tmp.build(&objects)?.insert(&objects)? }); From a1a7b6fb449274fac2ee6a2a8d77831e25345423 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:00:31 +0100 Subject: [PATCH 08/21] Simplify return value --- crates/fj-kernel/src/builder/edge.rs | 33 ++++--------------- crates/fj-kernel/src/partial/maybe_partial.rs | 10 +++--- 2 files changed, 11 insertions(+), 32 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 52d10ee37..726139db9 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -6,14 +6,13 @@ use crate::{ objects::{Curve, Objects, Surface, Vertex, VerticesInNormalizedOrder}, partial::{ MaybePartial, MergeWith, PartialCurve, PartialGlobalEdge, - PartialGlobalVertex, PartialHalfEdge, PartialSurfaceVertex, - PartialVertex, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, validate::ValidationError, }; -use super::{CurveBuilder, GlobalVertexBuilder}; +use super::CurveBuilder; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder: Sized { @@ -75,17 +74,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - let global_vertex = self - .global_form() - .vertices() - .map(|[global_form, _]| global_form) - .unwrap_or_else(|| { - PartialGlobalVertex::from_curve_and_position( - curve.clone(), - a_curve, - ) - .into() - }); + let [global_vertex, _] = self.global_form().vertices(); let surface_vertex = PartialSurfaceVertex { position: Some(path.point_from_path_coords(a_curve)), @@ -181,19 +170,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { must_switch_order }; - self.global_form() - .vertices() - .map( - |[a, b]| { - if must_switch_order { - [b, a] - } else { - [a, b] - } - }, - ) - .map(|[a, b]| [Some(a), Some(b)]) - .unwrap_or([None, None]) + let [a, b] = self.global_form().vertices(); + let [a, b] = if must_switch_order { [b, a] } else { [a, b] }; + [Some(a), Some(b)] }; vertices diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index f27939536..dc79bafd9 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -173,12 +173,12 @@ impl MaybePartial { } /// Access the vertices - pub fn vertices(&self) -> Option<[MaybePartial; 2]> { + pub fn vertices(&self) -> [MaybePartial; 2] { match self { - Self::Full(full) => Some( - full.vertices().access_in_normalized_order().map(Into::into), - ), - Self::Partial(partial) => Some(partial.vertices.clone()), + Self::Full(full) => { + full.vertices().access_in_normalized_order().map(Into::into) + } + Self::Partial(partial) => partial.vertices.clone(), } } } From 78e5d0cda9fc9c0dfec4e834a8a55cade50a6b20 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:02:32 +0100 Subject: [PATCH 09/21] Refactor --- crates/fj-kernel/src/builder/edge.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 726139db9..f888be9d3 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -171,8 +171,11 @@ impl HalfEdgeBuilder for PartialHalfEdge { }; let [a, b] = self.global_form().vertices(); - let [a, b] = if must_switch_order { [b, a] } else { [a, b] }; - [Some(a), Some(b)] + if must_switch_order { + [b, a] + } else { + [a, b] + } }; vertices @@ -181,10 +184,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { .collect::<[_; 2]>() .map(|(vertex, global_form)| { vertex.update_partial(|mut vertex| { - let mut surface_form = PartialSurfaceVertex::default(); - if let Some(global_form) = global_form { - surface_form.global_form = global_form; - } + let surface_form = PartialSurfaceVertex { + global_form, + ..Default::default() + }; vertex.surface_form = vertex.surface_form.merge_with(surface_form); From b5b19b5ae9927430c83c45b5cc12c74fda393aad Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:03:08 +0100 Subject: [PATCH 10/21] Refactor --- crates/fj-kernel/src/builder/edge.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index f888be9d3..56c3126bc 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -184,14 +184,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .collect::<[_; 2]>() .map(|(vertex, global_form)| { vertex.update_partial(|mut vertex| { - let surface_form = PartialSurfaceVertex { - global_form, - ..Default::default() - }; - - vertex.surface_form = - vertex.surface_form.merge_with(surface_form); - + vertex.surface_form = vertex.surface_form.merge_with( + PartialSurfaceVertex { + global_form, + ..Default::default() + }, + ); vertex }) }) From 848573814e5428b625c9c904de8e86dce10c9ad6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:05:54 +0100 Subject: [PATCH 11/21] Make fields of `PartialHalfEdge` public --- crates/fj-kernel/src/partial/objects/edge.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index cbc165959..bc6597e4f 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -16,9 +16,14 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialHalfEdge { - curve: MaybePartial, - vertices: [MaybePartial; 2], - global_form: MaybePartial, + /// The curve that the [`HalfEdge`] is defined in + pub curve: MaybePartial, + + /// The vertices that bound the [`HalfEdge`] in the curve + pub vertices: [MaybePartial; 2], + + /// The global form of the [`HalfEdge`] + pub global_form: MaybePartial, } impl PartialHalfEdge { From 2b99b2156b52771f698786258bbb4625c2654929 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:07:10 +0100 Subject: [PATCH 12/21] Remove `PartialHalfEdge::curve` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 3 ++- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 5 ----- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index cded261d6..fb1b8d294 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -16,7 +16,8 @@ impl TransformObject for PartialHalfEdge { objects: &Objects, ) -> Result { let curve: MaybePartial<_> = self - .curve() + .curve + .clone() .into_partial() .transform(transform, objects)? .into(); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 56c3126bc..5b07d9a91 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -65,7 +65,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { radius: impl Into, objects: &Objects, ) -> Result { - let mut curve = self.curve().into_partial(); + let mut curve = self.curve.clone().into_partial(); curve.global_form = Some(self.extract_global_curve()); curve.update_as_circle_from_radius(radius); @@ -123,7 +123,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { [&from, &to].map(|vertex| vertex.surface_form()); let surface = self - .curve() + .curve .surface() .merge_with(from_surface.surface()) .merge_with(to_surface.surface()) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index dc79bafd9..ccf589d14 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -188,7 +188,7 @@ impl MaybePartial { pub fn curve(&self) -> MaybePartial { match self { Self::Full(full) => full.curve().clone().into(), - Self::Partial(partial) => partial.curve(), + Self::Partial(partial) => partial.curve.clone(), } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index bc6597e4f..4b036bc9d 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,11 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Access the curve that the [`HalfEdge`] is defined in - pub fn curve(&self) -> MaybePartial { - self.curve.clone() - } - /// Access the vertices that bound this [`HalfEdge`] in the [`Curve`] pub fn vertices(&self) -> [MaybePartial; 2] { self.vertices.clone() From 0bbe047570efe54de6d9a19a34ff8be75d814de4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:09:49 +0100 Subject: [PATCH 13/21] Remove `PartialHalfEdge::vertices` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 6 +++--- crates/fj-kernel/src/partial/maybe_partial.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 5 ----- crates/fj-kernel/src/validate/cycle.rs | 2 +- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index fb1b8d294..e91c5430c 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -21,7 +21,7 @@ impl TransformObject for PartialHalfEdge { .into_partial() .transform(transform, objects)? .into(); - let vertices = self.vertices().try_map_ext( + let vertices = self.vertices.clone().try_map_ext( |vertex| -> Result<_, ValidationError> { let mut vertex = vertex.into_partial().transform(transform, objects)?; diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 5b07d9a91..fa016f184 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -51,12 +51,12 @@ pub trait HalfEdgeBuilder: Sized { impl HalfEdgeBuilder for PartialHalfEdge { fn with_back_vertex(self, back: impl Into>) -> Self { - let [_, front] = self.vertices(); + let [_, front] = self.vertices.clone(); self.with_vertices([back.into(), front]) } fn with_front_vertex(self, front: impl Into>) -> Self { - let [back, _] = self.vertices(); + let [back, _] = self.vertices.clone(); self.with_vertices([back, front.into()]) } @@ -118,7 +118,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { } fn update_as_line_segment(self) -> Self { - let [from, to] = self.vertices(); + let [from, to] = self.vertices.clone(); let [from_surface, to_surface] = [&from, &to].map(|vertex| vertex.surface_form()); diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index ccf589d14..039b899a1 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -197,7 +197,7 @@ impl MaybePartial { match self { Self::Full(full) => full.front().clone().into(), Self::Partial(partial) => { - let [_, front] = &partial.vertices(); + let [_, front] = &partial.vertices; front.clone() } } @@ -207,7 +207,7 @@ impl MaybePartial { pub fn vertices(&self) -> [MaybePartial; 2] { match self { Self::Full(full) => full.vertices().clone().map(Into::into), - Self::Partial(partial) => partial.vertices(), + 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 4b036bc9d..ead66724b 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,11 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Access the vertices that bound this [`HalfEdge`] in the [`Curve`] - pub fn vertices(&self) -> [MaybePartial; 2] { - self.vertices.clone() - } - /// Access the global form of the [`HalfEdge`] pub fn global_form(&self) -> MaybePartial { self.global_form.clone() diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index b30ddaa9a..413953b54 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -91,7 +91,7 @@ mod tests { .collect::>(); let first_half_edge = &mut half_edges[0]; - let [first_vertex, _] = first_half_edge.vertices(); + let [first_vertex, _] = first_half_edge.vertices.clone(); // Sever connection between the last and first half-edge in the // cycle. From cb898b1670015311abd99f2340cfde4d12643c22 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:11:04 +0100 Subject: [PATCH 14/21] Remove `PartialHalfEdge::global_form` --- crates/fj-kernel/src/algorithms/transform/edge.rs | 5 ++--- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/partial/objects/edge.rs | 5 ----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index e91c5430c..12bb441d3 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -17,11 +17,10 @@ impl TransformObject for PartialHalfEdge { ) -> Result { let curve: MaybePartial<_> = self .curve - .clone() .into_partial() .transform(transform, objects)? .into(); - let vertices = self.vertices.clone().try_map_ext( + let vertices = self.vertices.try_map_ext( |vertex| -> Result<_, ValidationError> { let mut vertex = vertex.into_partial().transform(transform, objects)?; @@ -30,7 +29,7 @@ impl TransformObject for PartialHalfEdge { }, )?; let mut global_form = self - .global_form() + .global_form .into_partial() .transform(transform, objects)?; if let Some(curve) = curve.global_form() { diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index fa016f184..4eb95d93c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -74,7 +74,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - let [global_vertex, _] = self.global_form().vertices(); + let [global_vertex, _] = self.global_form.vertices(); let surface_vertex = PartialSurfaceVertex { position: Some(path.point_from_path_coords(a_curve)), @@ -170,7 +170,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { must_switch_order }; - let [a, b] = self.global_form().vertices(); + let [a, b] = self.global_form.vertices(); if must_switch_order { [b, a] } else { diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index ead66724b..c1cc1e56b 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,11 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Access the global form of the [`HalfEdge`] - pub fn global_form(&self) -> MaybePartial { - self.global_form.clone() - } - /// Extract the global curve from either the curve or global form /// /// If a global curve is available through both, the curve is preferred. From 8991c0968eb309efdb2ade05d7f13e697e5c0e55 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:35:05 +0100 Subject: [PATCH 15/21] Properly merge global curves of `PartialHalfEdge` --- crates/fj-kernel/src/partial/objects/edge.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index c1cc1e56b..ffaa8334c 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -33,6 +33,7 @@ impl PartialHalfEdge { pub fn extract_global_curve(&self) -> MaybePartial { self.curve .global_form() + .map(|global_form| global_form.merge_with(self.global_form.curve())) .unwrap_or_else(|| self.global_form.curve()) } From 385d5440c6feb5f6700cb1add03276923ee60e11 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:36:26 +0100 Subject: [PATCH 16/21] Simplify field of `PartialCurve` --- .../src/algorithms/transform/curve.rs | 5 +---- crates/fj-kernel/src/builder/edge.rs | 4 ++-- crates/fj-kernel/src/builder/shell.rs | 12 +++++----- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/curve.rs | 22 +++++-------------- 5 files changed, 14 insertions(+), 31 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/curve.rs b/crates/fj-kernel/src/algorithms/transform/curve.rs index a89192b7f..6b46215c5 100644 --- a/crates/fj-kernel/src/algorithms/transform/curve.rs +++ b/crates/fj-kernel/src/algorithms/transform/curve.rs @@ -32,10 +32,7 @@ impl TransformObject for PartialCurve { .surface .map(|surface| surface.transform(transform, objects)) .transpose()?; - let global_form = self - .global_form - .map(|global_form| global_form.transform(transform, objects)) - .transpose()?; + let global_form = self.global_form.transform(transform, objects)?; // Don't need to transform `self.path`, as that's defined in surface // coordinates, and thus transforming `surface` takes care of it. diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 4eb95d93c..43fce6871 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -66,7 +66,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { objects: &Objects, ) -> Result { let mut curve = self.curve.clone().into_partial(); - curve.global_form = Some(self.extract_global_curve()); + curve.global_form = self.extract_global_curve(); curve.update_as_circle_from_radius(radius); let path = curve.path.expect("Expected path that was just created"); @@ -136,7 +136,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let mut curve = PartialCurve { surface: Some(surface), - global_form: Some(self.extract_global_curve()), + global_form: self.extract_global_curve(), ..Default::default() }; curve.update_as_line_from_points(points); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 838295820..ad575271c 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -161,13 +161,11 @@ impl<'a> ShellBuilder<'a> { }; let curve = PartialCurve { - global_form: Some( - side_up_prev - .curve() - .global_form() - .clone() - .into(), - ), + global_form: side_up_prev + .curve() + .global_form() + .clone() + .into(), ..Default::default() }; diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 039b899a1..a8e67d5f4 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -158,7 +158,7 @@ impl MaybePartial { pub fn global_form(&self) -> Option> { match self { Self::Full(full) => Some(full.global_form().clone().into()), - Self::Partial(partial) => partial.global_form.clone(), + Self::Partial(partial) => Some(partial.global_form.clone()), } } } diff --git a/crates/fj-kernel/src/partial/objects/curve.rs b/crates/fj-kernel/src/partial/objects/curve.rs index a82a7af2f..0608dbd2e 100644 --- a/crates/fj-kernel/src/partial/objects/curve.rs +++ b/crates/fj-kernel/src/partial/objects/curve.rs @@ -1,7 +1,7 @@ use crate::{ geometry::path::SurfacePath, objects::{Curve, GlobalCurve, Objects, Surface}, - partial::{MaybePartial, MergeWith, Mergeable}, + partial::{MaybePartial, MergeWith}, storage::Handle, validate::ValidationError, }; @@ -18,13 +18,7 @@ pub struct PartialCurve { pub surface: Option>, /// The global form of the [`Curve`] - /// - /// # Implementation Note - /// - /// This can in principle be simplified to just `MaybePartial>, + pub global_form: MaybePartial, } impl PartialCurve { @@ -34,11 +28,7 @@ impl PartialCurve { let surface = self.surface.expect("Can't build `Curve` without surface"); - let global_form = match self.global_form { - Some(global_form) => global_form, - None => objects.global_curves.insert(GlobalCurve)?.into(), - } - .into_full(objects)?; + let global_form = self.global_form.into_full(objects)?; Ok(Curve::new(surface, path, global_form)) } @@ -51,9 +41,7 @@ impl MergeWith for PartialCurve { Self { path: self.path.merge_with(other.path), surface: self.surface.merge_with(other.surface), - global_form: Mergeable(self.global_form) - .merge_with(Mergeable(other.global_form)) - .0, + global_form: self.global_form.merge_with(other.global_form), } } } @@ -63,7 +51,7 @@ impl From<&Curve> for PartialCurve { Self { path: Some(curve.path()), surface: Some(curve.surface().clone()), - global_form: Some(curve.global_form().clone().into()), + global_form: curve.global_form().clone().into(), } } } From c5a4c8a9a1a5b90535f75e44816f709e9ebfc1fd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:38:32 +0100 Subject: [PATCH 17/21] Simplify return value --- crates/fj-kernel/src/algorithms/transform/edge.rs | 4 +--- crates/fj-kernel/src/partial/maybe_partial.rs | 6 +++--- crates/fj-kernel/src/partial/objects/edge.rs | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 12bb441d3..27d26e8d8 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -32,9 +32,7 @@ impl TransformObject for PartialHalfEdge { .global_form .into_partial() .transform(transform, objects)?; - if let Some(curve) = curve.global_form() { - global_form.curve = curve; - } + global_form.curve = curve.global_form(); Ok(Self::default() .with_curve(curve) diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index a8e67d5f4..dc5c32108 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -155,10 +155,10 @@ impl MaybePartial { } /// Access the global form - pub fn global_form(&self) -> Option> { + pub fn global_form(&self) -> MaybePartial { match self { - Self::Full(full) => Some(full.global_form().clone().into()), - Self::Partial(partial) => Some(partial.global_form.clone()), + Self::Full(full) => full.global_form().clone().into(), + Self::Partial(partial) => partial.global_form.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index ffaa8334c..a4c23e2ce 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -33,8 +33,7 @@ impl PartialHalfEdge { pub fn extract_global_curve(&self) -> MaybePartial { self.curve .global_form() - .map(|global_form| global_form.merge_with(self.global_form.curve())) - .unwrap_or_else(|| self.global_form.curve()) + .merge_with(self.global_form.curve()) } /// Update the partial half-edge with the given surface From 25c8a2cde4d57120ad762b289fb2ee597fbfb622 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:44:42 +0100 Subject: [PATCH 18/21] Refactor --- crates/fj-kernel/src/builder/edge.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 43fce6871..dd983c725 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -5,8 +5,8 @@ use crate::{ insert::Insert, objects::{Curve, Objects, Surface, Vertex, VerticesInNormalizedOrder}, partial::{ - MaybePartial, MergeWith, PartialCurve, PartialGlobalEdge, - PartialHalfEdge, PartialSurfaceVertex, PartialVertex, + MaybePartial, MergeWith, PartialGlobalEdge, PartialHalfEdge, + PartialSurfaceVertex, PartialVertex, }, storage::Handle, validate::ValidationError, @@ -134,11 +134,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { .expect("Can't infer line segment without surface position") }); - let mut curve = PartialCurve { - surface: Some(surface), - global_form: self.extract_global_curve(), - ..Default::default() - }; + let mut curve = self.curve.clone().into_partial(); + curve.surface = Some(surface); + curve.global_form = self.extract_global_curve(); curve.update_as_line_from_points(points); let [back, front] = { From 6576507135edaee6f123bf889da552bc8e55a1e8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:48:28 +0100 Subject: [PATCH 19/21] Make `PartialHalfEdge::build` smarter --- crates/fj-kernel/src/builder/edge.rs | 2 -- crates/fj-kernel/src/partial/objects/edge.rs | 21 +++++++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index dd983c725..f336ed587 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -66,7 +66,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { objects: &Objects, ) -> Result { let mut curve = self.curve.clone().into_partial(); - curve.global_form = self.extract_global_curve(); curve.update_as_circle_from_radius(radius); let path = curve.path.expect("Expected path that was just created"); @@ -136,7 +135,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { let mut curve = self.curve.clone().into_partial(); curve.surface = Some(surface); - curve.global_form = self.extract_global_curve(); curve.update_as_line_from_points(points); let [back, front] = { diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a4c23e2ce..ff58d55d1 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -6,7 +6,7 @@ use crate::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, Vertex, }, - partial::{MaybePartial, MergeWith}, + partial::{MaybePartial, MergeWith, PartialCurve}, storage::Handle, validate::ValidationError, }; @@ -87,8 +87,23 @@ impl PartialHalfEdge { } /// Build a full [`HalfEdge`] from the partial half-edge - pub fn build(self, objects: &Objects) -> Result { - let curve = self.curve.into_full(objects)?; + pub fn build( + mut self, + objects: &Objects, + ) -> Result { + let global_curve = self + .curve + .global_form() + .merge_with(self.global_form.curve()); + + let curve = { + self.curve = self.curve.merge_with(PartialCurve { + global_form: global_curve, + ..Default::default() + }); + + self.curve.into_full(objects)? + }; let vertices = self.vertices.try_map_ext(|vertex| { vertex .update_partial(|mut vertex| { From b804cb10b7e811828a372c172ba1aaf52f139d7b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:49:16 +0100 Subject: [PATCH 20/21] Remove unused method --- crates/fj-kernel/src/partial/objects/edge.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index ff58d55d1..62b85eac1 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,15 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Extract the global curve from either the curve or global form - /// - /// If a global curve is available through both, the curve is preferred. - pub fn extract_global_curve(&self) -> MaybePartial { - self.curve - .global_form() - .merge_with(self.global_form.curve()) - } - /// Update the partial half-edge with the given surface pub fn with_surface(mut self, surface: Handle) -> Self { self.curve = self.curve.update_partial(|mut curve| { From ba0aaabaf5aee72b6ac6a8fc90ecdae3409af1de Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 12 Nov 2022 19:57:17 +0100 Subject: [PATCH 21/21] Refactor --- crates/fj-kernel/src/partial/objects/edge.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 62b85eac1..6a44d916d 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -6,7 +6,7 @@ use crate::{ Curve, GlobalCurve, GlobalEdge, GlobalVertex, HalfEdge, Objects, Surface, Vertex, }, - partial::{MaybePartial, MergeWith, PartialCurve}, + partial::{MaybePartial, MergeWith, PartialCurve, PartialVertex}, storage::Handle, validate::ValidationError, }; @@ -97,9 +97,9 @@ impl PartialHalfEdge { }; let vertices = self.vertices.try_map_ext(|vertex| { vertex - .update_partial(|mut vertex| { - vertex.curve = curve.clone().into(); - vertex + .merge_with(PartialVertex { + curve: curve.clone().into(), + ..Default::default() }) .into_full(objects) })?;