From 30287c3e580397c98e8d1b4fe6f67736cf5284aa Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:22:51 +0100 Subject: [PATCH 01/24] Make field of `PartialGlobalVertex` public --- crates/fj-kernel/src/partial/objects/vertex.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index eaa7ac355..7fc7525ff 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -218,7 +218,8 @@ impl From<&SurfaceVertex> for PartialSurfaceVertex { /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct PartialGlobalVertex { - position: Option>, + /// The position of the [`GlobalVertex`] + pub position: Option>, } impl PartialGlobalVertex { From 360cc589c33c37b8d35a071533fa9a1763dcc3f1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:23:17 +0100 Subject: [PATCH 02/24] Remove `PartialGlobalVertex::position` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index b9db0f704..d3122690b 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -57,7 +57,7 @@ impl TransformObject for PartialGlobalVertex { _: &Objects, ) -> Result { let position = self - .position() + .position .map(|position| transform.transform_point(&position)); Ok(Self::default().with_position(position)) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 7fc7525ff..bbdc66ff4 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -223,11 +223,6 @@ pub struct PartialGlobalVertex { } impl PartialGlobalVertex { - /// Access the position of the [`GlobalVertex`] - pub fn position(&self) -> Option> { - self.position - } - /// Provide a position for the partial global vertex pub fn with_position( mut self, From ce35a765228ae6872c8d83ba9b12af3b7005575c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:24:13 +0100 Subject: [PATCH 03/24] Remove `PartialGlobalVertex::with_position` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/builder/vertex.rs | 5 +++-- crates/fj-kernel/src/partial/objects/vertex.rs | 11 ----------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index d3122690b..67b9aaf35 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -60,6 +60,6 @@ impl TransformObject for PartialGlobalVertex { .position .map(|position| transform.transform_point(&position)); - Ok(Self::default().with_position(position)) + Ok(Self { position }) } } diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index ca2776ff8..4125445c2 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -69,10 +69,11 @@ impl GlobalVertexBuilder for PartialGlobalVertex { } fn update_from_surface_and_position( - self, + mut self, surface: &Surface, position: impl Into>, ) -> Self { - self.with_position(Some(surface.point_from_surface_coords(position))) + self.position = Some(surface.point_from_surface_coords(position)); + self } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index bbdc66ff4..c06529d6d 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -223,17 +223,6 @@ pub struct PartialGlobalVertex { } impl PartialGlobalVertex { - /// Provide a position for the partial global vertex - pub fn with_position( - mut self, - position: Option>>, - ) -> Self { - if let Some(position) = position { - self.position = Some(position.into()); - } - self - } - /// Build a full [`GlobalVertex`] from the partial global vertex pub fn build(self, _: &Objects) -> Result { let position = self From ec019bfd79b33f6640a77ac627bd7dfc482d644a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:25:40 +0100 Subject: [PATCH 04/24] Change style of `update_from_surface_and_position` --- crates/fj-kernel/src/builder/vertex.rs | 13 +++++++------ crates/fj-kernel/src/partial/objects/vertex.rs | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 4125445c2..9203581ce 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -43,15 +43,15 @@ pub trait GlobalVertexBuilder { /// Update partial global vertex from the given surface and position on it fn update_from_surface_and_position( - self, + &mut self, surface: &Surface, position: impl Into>, - ) -> Self; + ) -> &mut Self; } impl GlobalVertexBuilder for PartialGlobalVertex { fn update_from_curve_and_position( - self, + mut self, curve: impl Into>, position: impl Into>, ) -> Self { @@ -65,14 +65,15 @@ impl GlobalVertexBuilder for PartialGlobalVertex { ); let position_surface = path.point_from_path_coords(position); - self.update_from_surface_and_position(&surface, position_surface) + self.update_from_surface_and_position(&surface, position_surface); + self } fn update_from_surface_and_position( - mut self, + &mut self, surface: &Surface, position: impl Into>, - ) -> Self { + ) -> &mut Self { self.position = Some(surface.point_from_surface_coords(position)); self } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index c06529d6d..444e335a8 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -182,8 +182,10 @@ impl PartialSurfaceVertex { let global_form = self .global_form - .update_partial(|global_form| { - global_form.update_from_surface_and_position(&surface, position) + .update_partial(|mut global_form| { + global_form + .update_from_surface_and_position(&surface, position); + global_form }) .into_full(objects)?; From d038668f128413c27e0162a9bb9771d84035411c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:27:15 +0100 Subject: [PATCH 05/24] Change style of `update_from_curve_and_position` --- crates/fj-kernel/src/builder/edge.rs | 7 ++++--- crates/fj-kernel/src/builder/vertex.rs | 11 +++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 2fc232795..8b529f6b1 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -82,9 +82,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { .vertices() .map(|[global_form, _]| global_form) .unwrap_or_else(|| { - GlobalVertex::partial() - .update_from_curve_and_position(curve.clone(), a_curve) - .into() + let mut global_vertex = GlobalVertex::partial(); + global_vertex + .update_from_curve_and_position(curve.clone(), a_curve); + global_vertex.into() }); let surface_vertex = SurfaceVertex::partial() diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 9203581ce..a058303ba 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -36,10 +36,10 @@ impl SurfaceVertexBuilder for PartialSurfaceVertex { pub trait GlobalVertexBuilder { /// Update partial global vertex from the given curve and position on it fn update_from_curve_and_position( - self, + &mut self, curve: impl Into>, position: impl Into>, - ) -> Self; + ) -> &mut Self; /// Update partial global vertex from the given surface and position on it fn update_from_surface_and_position( @@ -51,10 +51,10 @@ pub trait GlobalVertexBuilder { impl GlobalVertexBuilder for PartialGlobalVertex { fn update_from_curve_and_position( - mut self, + &mut self, curve: impl Into>, position: impl Into>, - ) -> Self { + ) -> &mut Self { let curve = curve.into().into_partial(); let path = curve.path.expect( @@ -65,8 +65,7 @@ impl GlobalVertexBuilder for PartialGlobalVertex { ); let position_surface = path.point_from_path_coords(position); - self.update_from_surface_and_position(&surface, position_surface); - self + self.update_from_surface_and_position(&surface, position_surface) } fn update_from_surface_and_position( From 9c653f8f7ce4956c076fc7024e63af3ba849baab Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:28:18 +0100 Subject: [PATCH 06/24] Make fields of `PartialSurfaceVertex` public --- crates/fj-kernel/src/partial/objects/vertex.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 444e335a8..5a54adf77 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -117,9 +117,14 @@ impl From<&Vertex> for PartialVertex { /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd)] pub struct PartialSurfaceVertex { - position: Option>, - surface: Option>, - global_form: MaybePartial, + /// The position of the [`SurfaceVertex`] + pub position: Option>, + + /// The surface that the [`SurfaceVertex`] is defined in + pub surface: Option>, + + /// The global form of the [`SurfaceVertex`] + pub global_form: MaybePartial, } impl PartialSurfaceVertex { From 37e06c209c3e9ee551a0acc826d941454ebea2e1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:28:44 +0100 Subject: [PATCH 07/24] Remove `PartialSurfaceVertex::position` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 67b9aaf35..19881dcac 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -44,7 +44,7 @@ impl TransformObject for PartialSurfaceVertex { // Don't need to transform `self.position`, as that is in surface // coordinates and thus transforming the surface takes care of it. Ok(Self::default() - .with_position(self.position()) + .with_position(self.position) .with_surface(surface) .with_global_form(Some(global_form))) } diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 3db76684d..8597682b2 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -217,7 +217,7 @@ impl MaybePartial { pub fn position(&self) -> Option> { match self { Self::Full(full) => Some(full.position()), - Self::Partial(partial) => partial.position(), + Self::Partial(partial) => partial.position, } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 5a54adf77..237284137 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -128,11 +128,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Access the position of the [`SurfaceVertex`] - pub fn position(&self) -> Option> { - self.position - } - /// Access the surface that the [`SurfaceVertex`] is defined in pub fn surface(&self) -> Option> { self.surface.clone() From 918fa1db5d2cc5d6d9d220d9bfbb358354d74955 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:31:09 +0100 Subject: [PATCH 08/24] Remove `PartialSurfaceVertex::surface` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 3 ++- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 19881dcac..923ec113b 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -36,7 +36,8 @@ impl TransformObject for PartialSurfaceVertex { objects: &Objects, ) -> Result { let surface = self - .surface() + .surface + .clone() .map(|surface| surface.transform(transform, objects)) .transpose()?; let global_form = self.global_form().transform(transform, objects)?; diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 8597682b2..5c4ec4c7a 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -225,7 +225,7 @@ impl MaybePartial { pub fn surface(&self) -> Option> { match self { Self::Full(full) => Some(full.surface().clone()), - Self::Partial(partial) => partial.surface(), + Self::Partial(partial) => partial.surface.clone(), } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 237284137..fd08906d8 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -128,11 +128,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Access the surface that the [`SurfaceVertex`] is defined in - pub fn surface(&self) -> Option> { - self.surface.clone() - } - /// Access the global form of the [`SurfaceVertex`] pub fn global_form(&self) -> MaybePartial { self.global_form.clone() From 8293b47e4437a4d0685626b71784f9f1c332a993 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:31:46 +0100 Subject: [PATCH 09/24] Remove `PartialSurfaceVertex::global_form` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 923ec113b..1c6bd891e 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -40,7 +40,7 @@ impl TransformObject for PartialSurfaceVertex { .clone() .map(|surface| surface.transform(transform, objects)) .transpose()?; - let global_form = self.global_form().transform(transform, objects)?; + let global_form = self.global_form.transform(transform, objects)?; // Don't need to transform `self.position`, as that is in surface // coordinates and thus transforming the surface takes care of it. diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 5c4ec4c7a..2f2f83522 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -233,7 +233,7 @@ impl MaybePartial { pub fn global_form(&self) -> MaybePartial { match self { Self::Full(full) => full.global_form().clone().into(), - Self::Partial(partial) => partial.global_form(), + Self::Partial(partial) => partial.global_form.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index fd08906d8..3a4438ca2 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -128,11 +128,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Access the global form of the [`SurfaceVertex`] - pub fn global_form(&self) -> MaybePartial { - self.global_form.clone() - } - /// Provide a position for the partial surface vertex pub fn with_position( mut self, From d992ea04fab925967907299308d79819c5d83351 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:38:59 +0100 Subject: [PATCH 10/24] Remove `PartialSurfaceVertex::with_position` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 14 ++++-- .../src/algorithms/transform/vertex.rs | 10 +++-- crates/fj-kernel/src/builder/cycle.rs | 13 ++++-- crates/fj-kernel/src/builder/edge.rs | 26 ++++++----- crates/fj-kernel/src/builder/shell.rs | 45 ++++++++++--------- .../fj-kernel/src/partial/objects/vertex.rs | 18 ++------ crates/fj-kernel/src/validate/vertex.rs | 28 +++++------- 7 files changed, 78 insertions(+), 76 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 09ade40ac..01b70720f 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -199,8 +199,8 @@ mod tests { algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::{Cycle, Face, HalfEdge, Objects, SurfaceVertex, Vertex}, - partial::HasPartial, + objects::{Cycle, Face, HalfEdge, Objects, Vertex}, + partial::{HasPartial, PartialSurfaceVertex}, }; #[test] @@ -235,7 +235,10 @@ mod tests { bottom.front().surface_form().clone(), )) .with_front_vertex(Vertex::partial().with_surface_form( - SurfaceVertex::partial().with_position(Some([1., 1.])), + PartialSurfaceVertex { + position: Some([1., 1.].into()), + ..Default::default() + }, )) .update_as_line_segment() .build(&objects)? @@ -243,7 +246,10 @@ mod tests { let top = HalfEdge::partial() .with_surface(surface.clone()) .with_back_vertex(Vertex::partial().with_surface_form( - SurfaceVertex::partial().with_position(Some([0., 1.])), + PartialSurfaceVertex { + position: Some([0., 1.].into()), + ..Default::default() + }, )) .with_front_vertex(Vertex::partial().with_surface_form( side_up.front().surface_form().clone(), diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 1c6bd891e..bab943f26 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -44,10 +44,12 @@ impl TransformObject for PartialSurfaceVertex { // Don't need to transform `self.position`, as that is in surface // coordinates and thus transforming the surface takes care of it. - Ok(Self::default() - .with_position(self.position) - .with_surface(surface) - .with_global_form(Some(global_form))) + Ok(Self { + position: self.position, + ..Default::default() + } + .with_surface(surface) + .with_global_form(Some(global_form))) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 64ba97be6..a38819861 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -2,7 +2,10 @@ use fj_math::Point; use crate::{ objects::{HalfEdge, Surface, SurfaceVertex, Vertex}, - partial::{HasPartial, MaybePartial, PartialCurve, PartialCycle}, + partial::{ + HasPartial, MaybePartial, PartialCurve, PartialCycle, + PartialSurfaceVertex, + }, storage::Handle, }; @@ -101,9 +104,11 @@ impl CycleBuilder for PartialCycle { points: impl IntoIterator>>, ) -> Self { self.with_poly_chain(points.into_iter().map(|position| { - SurfaceVertex::partial() - .with_surface(Some(surface.clone())) - .with_position(Some(position)) + PartialSurfaceVertex { + position: Some(position.into()), + ..Default::default() + } + .with_surface(Some(surface.clone())) })) } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 8b529f6b1..677cacc39 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -4,12 +4,12 @@ use iter_fixed::IntoIteratorFixed; use crate::{ insert::Insert, objects::{ - Curve, GlobalVertex, Objects, Surface, SurfaceVertex, Vertex, + Curve, GlobalVertex, Objects, Surface, Vertex, VerticesInNormalizedOrder, }, partial::{ HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, - PartialHalfEdge, + PartialHalfEdge, PartialSurfaceVertex, }, storage::Handle, validate::ValidationError, @@ -88,12 +88,14 @@ impl HalfEdgeBuilder for PartialHalfEdge { global_vertex.into() }); - let surface_vertex = SurfaceVertex::partial() - .with_position(Some(path.point_from_path_coords(a_curve))) - .with_surface(curve.surface.clone()) - .with_global_form(Some(global_vertex)) - .build(objects)? - .insert(objects)?; + let surface_vertex = PartialSurfaceVertex { + position: Some(path.point_from_path_coords(a_curve)), + ..Default::default() + } + .with_surface(curve.surface.clone()) + .with_global_form(Some(global_vertex)) + .build(objects)? + .insert(objects)?; let [back, front] = [a_curve, b_curve].map(|point_curve| { Vertex::partial() @@ -111,9 +113,11 @@ impl HalfEdgeBuilder for PartialHalfEdge { points: [impl Into>; 2], ) -> Self { let vertices = points.map(|point| { - let surface_form = SurfaceVertex::partial() - .with_surface(Some(surface.clone())) - .with_position(Some(point)); + let surface_form = PartialSurfaceVertex { + position: Some(point.into()), + ..Default::default() + } + .with_surface(Some(surface.clone())); Vertex::partial().with_surface_form(surface_form) }); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index fcd8a61f3..ae49ad095 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -9,10 +9,9 @@ use crate::{ builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, objects::{ - Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, SurfaceVertex, - Vertex, + Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, }, - partial::{HasPartial, PartialCurve}, + partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, storage::Handle, }; @@ -114,9 +113,11 @@ impl<'a> ShellBuilder<'a> { let [_, from] = bottom.vertices(); let from = from.surface_form().clone(); - let to = SurfaceVertex::partial() - .with_position(Some(from.position() + [Z, edge_length])) - .with_surface(Some(surface.clone())); + let to = PartialSurfaceVertex { + position: Some(from.position() + [Z, edge_length]), + ..Default::default() + } + .with_surface(Some(surface.clone())); HalfEdge::partial() .with_vertices([ @@ -145,12 +146,12 @@ impl<'a> ShellBuilder<'a> { let [to, _] = bottom.vertices(); let to = to.surface_form().clone(); - let from = SurfaceVertex::partial() - .with_position(Some( - to.position() + [Z, edge_length], - )) - .with_surface(Some(surface.clone())) - .with_global_form(Some(from.global_form().clone())); + let from = PartialSurfaceVertex { + position: Some(to.position() + [Z, edge_length]), + ..Default::default() + } + .with_surface(Some(surface.clone())) + .with_global_form(Some(from.global_form().clone())); let curve = PartialCurve { global_form: Some( @@ -250,16 +251,16 @@ impl<'a> ShellBuilder<'a> { .map(|(point, edge)| { let vertex = edge.back(); - SurfaceVertex::partial() - .with_position(Some(point)) - .with_surface(Some(surface.clone())) - .with_global_form(Some( - vertex.global_form().clone(), - )) - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap() + PartialSurfaceVertex { + position: Some(point.into()), + ..Default::default() + } + .with_surface(Some(surface.clone())) + .with_global_form(Some(vertex.global_form().clone())) + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap() }); [a.clone(), b, c, d, a] diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 3a4438ca2..172f0a3d6 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -75,14 +75,13 @@ impl PartialVertex { let surface_form = self .surface_form - .update_partial(|partial| { + .update_partial(|mut partial| { let position = partial.position.unwrap_or_else(|| { curve.path().point_from_path_coords(position) }); - partial - .with_position(Some(position)) - .with_surface(Some(curve.surface().clone())) + partial.position = Some(position); + partial.with_surface(Some(curve.surface().clone())) }) .into_full(objects)?; @@ -128,17 +127,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Provide a position for the partial surface vertex - pub fn with_position( - mut self, - position: Option>>, - ) -> Self { - if let Some(position) = position { - self.position = Some(position.into()); - } - self - } - /// Provide a surface for the partial surface vertex pub fn with_surface(mut self, surface: Option>) -> Self { if let Some(surface) = surface { diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 6b76257b1..1d429ae05 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -182,7 +182,7 @@ mod tests { builder::{CurveBuilder, SurfaceVertexBuilder}, insert::Insert, objects::{GlobalVertex, Objects, SurfaceVertex, Vertex}, - partial::{HasPartial, PartialCurve}, + partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, validate::Validate, }; @@ -233,17 +233,11 @@ mod tests { .with_curve(curve) .build(&objects)? }; - let invalid = Vertex::new( - valid.position(), - valid.curve().clone(), - valid - .surface_form() - .to_partial() - .with_position(Some([1., 0.])) - .infer_global_form() - .build(&objects)? - .insert(&objects)?, - ); + let invalid = Vertex::new(valid.position(), valid.curve().clone(), { + let mut tmp = valid.surface_form().to_partial(); + tmp.position = Some([1., 0.].into()); + tmp.infer_global_form().build(&objects)?.insert(&objects)? + }); assert!(valid.validate().is_ok()); assert!(invalid.validate().is_err()); @@ -255,10 +249,12 @@ mod tests { fn surface_vertex_position_mismatch() -> anyhow::Result<()> { let objects = Objects::new(); - let valid = SurfaceVertex::partial() - .with_position(Some([0., 0.])) - .with_surface(Some(objects.surfaces.xy_plane())) - .build(&objects)?; + let valid = PartialSurfaceVertex { + position: Some([0., 0.].into()), + ..Default::default() + } + .with_surface(Some(objects.surfaces.xy_plane())) + .build(&objects)?; let invalid = SurfaceVertex::new( valid.position(), valid.surface().clone(), From e39374eb3b991bbf46e903b9bfd1296cd19688b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:42:12 +0100 Subject: [PATCH 11/24] Remove `SurfaceVertex::with_surface` --- .../src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 6 +++--- crates/fj-kernel/src/builder/shell.rs | 8 ++++---- crates/fj-kernel/src/partial/objects/edge.rs | 10 ++++++---- crates/fj-kernel/src/partial/objects/vertex.rs | 12 +++--------- crates/fj-kernel/src/validate/vertex.rs | 17 ++++++----------- 7 files changed, 24 insertions(+), 33 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index bab943f26..903837fd6 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -46,9 +46,9 @@ impl TransformObject for PartialSurfaceVertex { // coordinates and thus transforming the surface takes care of it. Ok(Self { position: self.position, + surface, ..Default::default() } - .with_surface(surface) .with_global_form(Some(global_form))) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index a38819861..85458a107 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -106,9 +106,9 @@ impl CycleBuilder for PartialCycle { self.with_poly_chain(points.into_iter().map(|position| { PartialSurfaceVertex { position: Some(position.into()), + surface: Some(surface.clone()), ..Default::default() } - .with_surface(Some(surface.clone())) })) } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 677cacc39..c33f27ec0 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -90,9 +90,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let surface_vertex = PartialSurfaceVertex { position: Some(path.point_from_path_coords(a_curve)), + surface: curve.surface.clone(), ..Default::default() } - .with_surface(curve.surface.clone()) .with_global_form(Some(global_vertex)) .build(objects)? .insert(objects)?; @@ -115,9 +115,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let vertices = points.map(|point| { let surface_form = PartialSurfaceVertex { position: Some(point.into()), + surface: Some(surface.clone()), ..Default::default() - } - .with_surface(Some(surface.clone())); + }; Vertex::partial().with_surface_form(surface_form) }); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index ae49ad095..8df311052 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -115,9 +115,9 @@ impl<'a> ShellBuilder<'a> { let from = from.surface_form().clone(); let to = PartialSurfaceVertex { position: Some(from.position() + [Z, edge_length]), + surface: Some(surface.clone()), ..Default::default() - } - .with_surface(Some(surface.clone())); + }; HalfEdge::partial() .with_vertices([ @@ -148,9 +148,9 @@ impl<'a> ShellBuilder<'a> { let to = to.surface_form().clone(); let from = PartialSurfaceVertex { position: Some(to.position() + [Z, edge_length]), + surface: Some(surface.clone()), ..Default::default() } - .with_surface(Some(surface.clone())) .with_global_form(Some(from.global_form().clone())); let curve = PartialCurve { @@ -253,9 +253,9 @@ impl<'a> ShellBuilder<'a> { PartialSurfaceVertex { position: Some(point.into()), + surface: Some(surface.clone()), ..Default::default() } - .with_surface(Some(surface.clone())) .with_global_form(Some(vertex.global_form().clone())) .build(self.objects) .unwrap() diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index aaaf6d33a..a41eb8d61 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -55,10 +55,12 @@ impl PartialHalfEdge { self.vertices = self.vertices.map(|vertex| { vertex.update_partial(|vertex| { - let surface_form = - vertex.surface_form().update_partial(|surface_vertex| { - surface_vertex.with_surface(Some(surface.clone())) - }); + let surface_form = vertex.surface_form().update_partial( + |mut surface_vertex| { + surface_vertex.surface = Some(surface.clone()); + surface_vertex + }, + ); vertex.with_surface_form(surface_form) }) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 172f0a3d6..f37074fba 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -81,7 +81,9 @@ impl PartialVertex { }); partial.position = Some(position); - partial.with_surface(Some(curve.surface().clone())) + partial.surface = Some(curve.surface().clone()); + + partial }) .into_full(objects)?; @@ -127,14 +129,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Provide a surface for the partial surface vertex - pub fn with_surface(mut self, surface: Option>) -> Self { - if let Some(surface) = surface { - self.surface = Some(surface); - } - self - } - /// Provide a global form for the partial surface vertex pub fn with_global_form( mut self, diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 1d429ae05..673e73314 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -200,16 +200,11 @@ mod tests { .with_position(Some([0.])) .with_curve(curve) .build(&objects)?; - let invalid = Vertex::new( - valid.position(), - valid.curve().clone(), - valid - .surface_form() - .to_partial() - .with_surface(Some(objects.surfaces.xz_plane())) - .build(&objects)? - .insert(&objects)?, - ); + let invalid = Vertex::new(valid.position(), valid.curve().clone(), { + let mut tmp = valid.surface_form().to_partial(); + tmp.surface = Some(objects.surfaces.xz_plane()); + tmp.build(&objects)?.insert(&objects)? + }); assert!(valid.validate().is_ok()); assert!(invalid.validate().is_err()); @@ -251,9 +246,9 @@ mod tests { let valid = PartialSurfaceVertex { position: Some([0., 0.].into()), + surface: Some(objects.surfaces.xy_plane()), ..Default::default() } - .with_surface(Some(objects.surfaces.xy_plane())) .build(&objects)?; let invalid = SurfaceVertex::new( valid.position(), From a8ff4ee17820e01ba670eec3588cac372facab0e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:48:41 +0100 Subject: [PATCH 12/24] Remove `PartialSurfaceVertex::with_global_form` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 5 ++--- crates/fj-kernel/src/builder/edge.rs | 11 +++++++---- crates/fj-kernel/src/builder/shell.rs | 8 +++----- crates/fj-kernel/src/builder/vertex.rs | 5 +++-- crates/fj-kernel/src/partial/objects/vertex.rs | 11 ----------- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 903837fd6..778e202ec 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -47,9 +47,8 @@ impl TransformObject for PartialSurfaceVertex { Ok(Self { position: self.position, surface, - ..Default::default() - } - .with_global_form(Some(global_form))) + global_form, + }) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index c33f27ec0..68928b294 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -91,9 +91,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { let surface_vertex = PartialSurfaceVertex { position: Some(path.point_from_path_coords(a_curve)), surface: curve.surface.clone(), - ..Default::default() + global_form: global_vertex, } - .with_global_form(Some(global_vertex)) .build(objects)? .insert(objects)?; @@ -203,8 +202,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { vertex.update_partial(|vertex| { vertex.clone().with_surface_form( vertex.surface_form().update_partial( - |surface_vertex| { - surface_vertex.with_global_form(global_form) + |mut surface_vertex| { + if let Some(global_form) = global_form { + surface_vertex.global_form = + global_form; + } + surface_vertex }, ), ) diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 8df311052..3ba3cccd2 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -149,9 +149,8 @@ impl<'a> ShellBuilder<'a> { let from = PartialSurfaceVertex { position: Some(to.position() + [Z, edge_length]), surface: Some(surface.clone()), - ..Default::default() - } - .with_global_form(Some(from.global_form().clone())); + global_form: from.global_form().clone().into(), + }; let curve = PartialCurve { global_form: Some( @@ -254,9 +253,8 @@ impl<'a> ShellBuilder<'a> { PartialSurfaceVertex { position: Some(point.into()), surface: Some(surface.clone()), - ..Default::default() + global_form: vertex.global_form().clone().into(), } - .with_global_form(Some(vertex.global_form().clone())) .build(self.objects) .unwrap() .insert(self.objects) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index a058303ba..a47b99cd3 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -27,8 +27,9 @@ pub trait SurfaceVertexBuilder { } impl SurfaceVertexBuilder for PartialSurfaceVertex { - fn infer_global_form(self) -> Self { - self.with_global_form(Some(GlobalVertex::partial())) + fn infer_global_form(mut self) -> Self { + self.global_form = GlobalVertex::partial().into(); + self } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index f37074fba..18a15e11e 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -129,17 +129,6 @@ pub struct PartialSurfaceVertex { } impl PartialSurfaceVertex { - /// Provide a global form for the partial surface vertex - pub fn with_global_form( - mut self, - global_form: Option>>, - ) -> Self { - if let Some(global_form) = global_form { - self.global_form = global_form.into(); - } - self - } - /// Build a full [`SurfaceVertex`] from the partial surface vertex pub fn build( self, From ba8db877e602cc6f5e533b51e6b7d5e1c464f962 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:50:18 +0100 Subject: [PATCH 13/24] Change style of `infer_global_form` --- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/validate/vertex.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index a47b99cd3..30a0d3f0e 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -23,11 +23,11 @@ impl VertexBuilder for PartialVertex { /// Builder API for [`PartialSurfaceVertex`] pub trait SurfaceVertexBuilder { /// Infer the global form of the partial vertex - fn infer_global_form(self) -> Self; + fn infer_global_form(&mut self) -> &mut Self; } impl SurfaceVertexBuilder for PartialSurfaceVertex { - fn infer_global_form(mut self) -> Self { + fn infer_global_form(&mut self) -> &mut Self { self.global_form = GlobalVertex::partial().into(); self } diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 673e73314..11a6dc4be 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -231,7 +231,8 @@ mod tests { let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial(); tmp.position = Some([1., 0.].into()); - tmp.infer_global_form().build(&objects)?.insert(&objects)? + tmp.infer_global_form(); + tmp.build(&objects)?.insert(&objects)? }); assert!(valid.validate().is_ok()); From 637f8154e77b8256ed7c8ea700c758003bb49c73 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:52:16 +0100 Subject: [PATCH 14/24] Make fields of `PartialVertex` public --- crates/fj-kernel/src/partial/objects/vertex.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 18a15e11e..cac225435 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -13,9 +13,14 @@ use crate::{ /// See [`crate::partial`] for more information. #[derive(Clone, Debug, Default)] pub struct PartialVertex { - position: Option>, - curve: MaybePartial, - surface_form: MaybePartial, + /// The position of the [`Vertex`] + pub position: Option>, + + /// The curve that the [`Vertex`] is defined in + pub curve: MaybePartial, + + /// The surface form of the [`Vertex`] + pub surface_form: MaybePartial, } impl PartialVertex { From 9666696a13c4cfbf1c5641223e1cd59b1f7f73b2 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:52:37 +0100 Subject: [PATCH 15/24] Remove `PartialVertex::position` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 778e202ec..adbbe7af0 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -23,7 +23,7 @@ impl TransformObject for PartialVertex { // Don't need to transform `self.position`, as that is in curve // coordinates and thus transforming the curve takes care of it. Ok(Self::default() - .with_position(self.position()) + .with_position(self.position) .with_curve(curve) .with_surface_form(surface_form)) } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index cac225435..2ab533e0b 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,11 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Access the position of the [`Vertex`] on the curve - pub fn position(&self) -> Option> { - self.position - } - /// Access the curve that the [`Vertex`] is defined in pub fn curve(&self) -> MaybePartial { self.curve.clone() From 3bfb5f6da8691fc67b468ecdfe1069826429ce63 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:53:08 +0100 Subject: [PATCH 16/24] Remove `PartialVertex::curve` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index adbbe7af0..0401c5de3 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -14,7 +14,7 @@ impl TransformObject for PartialVertex { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self.curve().transform(transform, objects)?; + let curve = self.curve.clone().transform(transform, objects)?; let surface_form = self .surface_form() .into_partial() diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 2ab533e0b..ce1de5abd 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,11 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Access the curve that the [`Vertex`] is defined in - pub fn curve(&self) -> MaybePartial { - self.curve.clone() - } - /// Access the surface form of the [`Vertex`] pub fn surface_form(&self) -> MaybePartial { self.surface_form.clone() From b71665a895cb68c38ebc53f325223aeb923ade1d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 15:54:18 +0100 Subject: [PATCH 17/24] Remove `PartialVertex::surface_form` --- crates/fj-kernel/src/algorithms/transform/vertex.rs | 4 ++-- crates/fj-kernel/src/builder/edge.rs | 2 +- crates/fj-kernel/src/partial/maybe_partial.rs | 2 +- crates/fj-kernel/src/partial/objects/edge.rs | 2 +- crates/fj-kernel/src/partial/objects/vertex.rs | 5 ----- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 0401c5de3..84ebeab51 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -14,9 +14,9 @@ impl TransformObject for PartialVertex { transform: &Transform, objects: &Objects, ) -> Result { - let curve = self.curve.clone().transform(transform, objects)?; + let curve = self.curve.transform(transform, objects)?; let surface_form = self - .surface_form() + .surface_form .into_partial() .transform(transform, objects)?; diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 68928b294..fc6bc557f 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -201,7 +201,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { .map(|(vertex, global_form)| { vertex.update_partial(|vertex| { vertex.clone().with_surface_form( - vertex.surface_form().update_partial( + vertex.surface_form.update_partial( |mut surface_vertex| { if let Some(global_form) = global_form { surface_vertex.global_form = diff --git a/crates/fj-kernel/src/partial/maybe_partial.rs b/crates/fj-kernel/src/partial/maybe_partial.rs index 2f2f83522..0fef15070 100644 --- a/crates/fj-kernel/src/partial/maybe_partial.rs +++ b/crates/fj-kernel/src/partial/maybe_partial.rs @@ -243,7 +243,7 @@ impl MaybePartial { pub fn surface_form(&self) -> MaybePartial { match self { Self::Full(full) => full.surface_form().clone().into(), - Self::Partial(partial) => partial.surface_form(), + Self::Partial(partial) => partial.surface_form.clone(), } } } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index a41eb8d61..b41df3915 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -55,7 +55,7 @@ impl PartialHalfEdge { self.vertices = self.vertices.map(|vertex| { vertex.update_partial(|vertex| { - let surface_form = vertex.surface_form().update_partial( + let surface_form = vertex.surface_form.clone().update_partial( |mut surface_vertex| { surface_vertex.surface = Some(surface.clone()); surface_vertex diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index ce1de5abd..3a519b11a 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,11 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Access the surface form of the [`Vertex`] - pub fn surface_form(&self) -> MaybePartial { - self.surface_form.clone() - } - /// Provide a position for the partial vertex pub fn with_position( mut self, From 4f4ddeffe9ac3558a5a648ca0640b7d505962e1f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:07:21 +0100 Subject: [PATCH 18/24] Remove `PartialVertex::with_position` --- .../fj-kernel/src/algorithms/sweep/vertex.rs | 16 +++++++------ .../src/algorithms/transform/vertex.rs | 10 ++++---- crates/fj-kernel/src/builder/cycle.rs | 14 ++++++----- crates/fj-kernel/src/builder/edge.rs | 19 ++++++++------- crates/fj-kernel/src/builder/shell.rs | 10 ++++---- .../fj-kernel/src/partial/objects/vertex.rs | 11 --------- crates/fj-kernel/src/validate/edge.rs | 4 ++-- crates/fj-kernel/src/validate/vertex.rs | 24 ++++++++++++------- 8 files changed, 56 insertions(+), 52 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 69c557727..b572a9f65 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -170,8 +170,8 @@ mod tests { algorithms::sweep::Sweep, builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{HalfEdge, Objects, Vertex}, - partial::{HasPartial, PartialCurve}, + objects::{HalfEdge, Objects}, + partial::{HasPartial, PartialCurve, PartialVertex}, }; #[test] @@ -185,11 +185,13 @@ mod tests { }; curve.update_as_u_axis(); let curve = curve.build(&objects)?.insert(&objects)?; - let vertex = Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)? - .insert(&objects)?; + let vertex = PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)? + .insert(&objects)?; let half_edge = (vertex, surface.clone()).sweep([0., 0., 1.], &objects)?; diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 84ebeab51..442d4a50a 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -22,10 +22,12 @@ impl TransformObject for PartialVertex { // Don't need to transform `self.position`, as that is in curve // coordinates and thus transforming the curve takes care of it. - Ok(Self::default() - .with_position(self.position) - .with_curve(curve) - .with_surface_form(surface_form)) + Ok(Self { + position: self.position, + ..Default::default() + } + .with_curve(curve) + .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 85458a107..65317238b 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,10 +1,10 @@ use fj_math::Point; use crate::{ - objects::{HalfEdge, Surface, SurfaceVertex, Vertex}, + objects::{HalfEdge, Surface, SurfaceVertex}, partial::{ HasPartial, MaybePartial, PartialCurve, PartialCycle, - PartialSurfaceVertex, + PartialSurfaceVertex, PartialVertex, }, storage::Handle, }; @@ -76,10 +76,12 @@ impl CycleBuilder for PartialCycle { let vertices = [(0., vertex_prev), (1., vertex_next)].map( |(position, surface_form)| { - Vertex::partial() - .with_curve(curve.clone()) - .with_position(Some([position])) - .with_surface_form(surface_form) + PartialVertex { + position: Some([position].into()), + ..Default::default() + } + .with_curve(curve.clone()) + .with_surface_form(surface_form) }, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index fc6bc557f..a246fc0b5 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -9,7 +9,7 @@ use crate::{ }, partial::{ HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, - PartialHalfEdge, PartialSurfaceVertex, + PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, validate::ValidationError, @@ -97,10 +97,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .insert(objects)?; let [back, front] = [a_curve, b_curve].map(|point_curve| { - Vertex::partial() - .with_position(Some(point_curve)) - .with_curve(curve.clone()) - .with_surface_form(surface_vertex.clone()) + PartialVertex { + position: Some(point_curve), + ..Default::default() + } + .with_curve(curve.clone()) + .with_surface_form(surface_vertex.clone()) }); Ok(self.with_curve(curve).with_vertices([back, front])) @@ -152,10 +154,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { - vertex.update_partial(|vertex| { - vertex - .with_position(Some([position])) - .with_curve(curve.clone()) + vertex.update_partial(|mut vertex| { + vertex.position = Some([position].into()); + vertex.with_curve(curve.clone()) }) }); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 3ba3cccd2..eb86fb61e 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -11,7 +11,7 @@ use crate::{ objects::{ Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, }, - partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, + partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex}, storage::Handle, }; @@ -277,9 +277,11 @@ impl<'a> ShellBuilder<'a> { .zip(surface_vertices.clone()) .collect::<[_; 2]>() .map(|(vertex, surface_form)| { - Vertex::partial() - .with_position(Some(vertex.position())) - .with_surface_form(surface_form) + PartialVertex { + position: Some(vertex.position()), + ..Default::default() + } + .with_surface_form(surface_form) }); edges.push( diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 3a519b11a..1149c9206 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,17 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Provide a position for the partial vertex - pub fn with_position( - mut self, - position: Option>>, - ) -> Self { - if let Some(position) = position { - self.position = Some(position.into()); - } - self - } - /// Provide a curve for the partial vertex pub fn with_curve(mut self, curve: impl Into>) -> Self { self.curve = curve.into(); diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 7a4b837d1..809c735dd 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -308,9 +308,9 @@ mod tests { let invalid = HalfEdge::new( valid.vertices().clone().try_map_ext( |vertex| -> anyhow::Result<_, ValidationError> { + let mut vertex = vertex.to_partial(); + vertex.position = Some([0.].into()); Ok(vertex - .to_partial() - .with_position(Some([0.])) .infer_surface_form() .build(&objects)? .insert(&objects)?) diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index 11a6dc4be..b27d46f08 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -182,7 +182,9 @@ mod tests { builder::{CurveBuilder, SurfaceVertexBuilder}, insert::Insert, objects::{GlobalVertex, Objects, SurfaceVertex, Vertex}, - partial::{HasPartial, PartialCurve, PartialSurfaceVertex}, + partial::{ + HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex, + }, validate::Validate, }; @@ -196,10 +198,12 @@ mod tests { }; curve.update_as_u_axis(); - let valid = Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)?; + let valid = PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)?; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial(); tmp.surface = Some(objects.surfaces.xz_plane()); @@ -223,10 +227,12 @@ mod tests { }; curve.update_as_u_axis(); - Vertex::partial() - .with_position(Some([0.])) - .with_curve(curve) - .build(&objects)? + PartialVertex { + position: Some([0.].into()), + ..Default::default() + } + .with_curve(curve) + .build(&objects)? }; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial(); From 8c1077ae2a333d0652219cad710fa7211849233c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:20:10 +0100 Subject: [PATCH 19/24] Remove `PartialVertex::with_curve` --- crates/fj-kernel/src/algorithms/sweep/vertex.rs | 2 +- crates/fj-kernel/src/algorithms/transform/edge.rs | 8 ++++---- crates/fj-kernel/src/algorithms/transform/vertex.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 2 +- crates/fj-kernel/src/builder/edge.rs | 5 +++-- crates/fj-kernel/src/partial/objects/edge.rs | 5 ++++- crates/fj-kernel/src/partial/objects/vertex.rs | 6 ------ crates/fj-kernel/src/validate/edge.rs | 10 ++++------ crates/fj-kernel/src/validate/vertex.rs | 4 ++-- 9 files changed, 20 insertions(+), 24 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index b572a9f65..e07754a62 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -187,9 +187,9 @@ mod tests { let curve = curve.build(&objects)?.insert(&objects)?; let vertex = PartialVertex { position: Some([0.].into()), + curve: curve.into(), ..Default::default() } - .with_curve(curve) .build(&objects)? .insert(&objects)?; diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 5e96fbc03..7daf35f31 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -22,10 +22,10 @@ impl TransformObject for PartialHalfEdge { .into(); let vertices = self.vertices().try_map_ext( |vertex| -> Result<_, ValidationError> { - Ok(vertex - .into_partial() - .transform(transform, objects)? - .with_curve(curve.clone())) + let mut vertex = + vertex.into_partial().transform(transform, objects)?; + vertex.curve = curve.clone(); + Ok(vertex) }, )?; let global_form = self diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index 442d4a50a..fc66e5642 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -24,9 +24,9 @@ impl TransformObject for PartialVertex { // coordinates and thus transforming the curve takes care of it. Ok(Self { position: self.position, + curve, ..Default::default() } - .with_curve(curve) .with_surface_form(surface_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 65317238b..5e0c2c794 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -78,9 +78,9 @@ impl CycleBuilder for PartialCycle { |(position, surface_form)| { PartialVertex { position: Some([position].into()), + curve: curve.clone().into(), ..Default::default() } - .with_curve(curve.clone()) .with_surface_form(surface_form) }, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index a246fc0b5..b5362bc55 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -99,9 +99,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = [a_curve, b_curve].map(|point_curve| { PartialVertex { position: Some(point_curve), + curve: curve.clone().into(), ..Default::default() } - .with_curve(curve.clone()) .with_surface_form(surface_vertex.clone()) }); @@ -156,7 +156,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { let vertices = [(from, 0.), (to, 1.)].map(|(vertex, position)| { vertex.update_partial(|mut vertex| { vertex.position = Some([position].into()); - vertex.with_curve(curve.clone()) + vertex.curve = curve.clone().into(); + vertex }) }); diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index b41df3915..d26f806a3 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -100,7 +100,10 @@ impl PartialHalfEdge { let curve = self.curve.into_full(objects)?; let vertices = self.vertices.try_map_ext(|vertex| { vertex - .update_partial(|vertex| vertex.with_curve(curve.clone())) + .update_partial(|mut vertex| { + vertex.curve = curve.clone().into(); + vertex + }) .into_full(objects) })?; diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 1149c9206..9f2330b7b 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,12 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Provide a curve for the partial vertex - pub fn with_curve(mut self, curve: impl Into>) -> Self { - self.curve = curve.into(); - self - } - /// Provide a surface form for the partial vertex pub fn with_surface_form( mut self, diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 809c735dd..9e2fdb744 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -220,12 +220,10 @@ mod tests { .build(&objects)?; let invalid = { let mut vertices = valid.vertices().clone(); - vertices[1] = vertices[1] - .to_partial() - // Arranging for an equal but not identical curve here. - .with_curve(valid.curve().to_partial()) - .build(&objects)? - .insert(&objects)?; + let mut vertex = vertices[1].to_partial(); + // Arranging for an equal but not identical curve here. + vertex.curve = valid.curve().to_partial().into(); + vertices[1] = vertex.build(&objects)?.insert(&objects)?; HalfEdge::new(vertices, valid.global_form().clone()) }; diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index b27d46f08..186fab353 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -200,9 +200,9 @@ mod tests { let valid = PartialVertex { position: Some([0.].into()), + curve: curve.into(), ..Default::default() } - .with_curve(curve) .build(&objects)?; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { let mut tmp = valid.surface_form().to_partial(); @@ -229,9 +229,9 @@ mod tests { PartialVertex { position: Some([0.].into()), + curve: curve.into(), ..Default::default() } - .with_curve(curve) .build(&objects)? }; let invalid = Vertex::new(valid.position(), valid.curve().clone(), { From 807f824746a3ee7eca911d54da8ce1a83c820e0c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:41:15 +0100 Subject: [PATCH 20/24] Remove `PartialVertex::with_surface_form` --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 130 +++++++++--------- .../src/algorithms/transform/vertex.rs | 5 +- crates/fj-kernel/src/builder/cycle.rs | 11 +- crates/fj-kernel/src/builder/edge.rs | 37 +++-- crates/fj-kernel/src/builder/shell.rs | 44 ++++-- crates/fj-kernel/src/builder/vertex.rs | 5 +- crates/fj-kernel/src/partial/objects/cycle.rs | 18 ++- crates/fj-kernel/src/partial/objects/edge.rs | 5 +- .../fj-kernel/src/partial/objects/vertex.rs | 9 -- 9 files changed, 139 insertions(+), 125 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 01b70720f..901533c47 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -199,8 +199,8 @@ mod tests { algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::{Cycle, Face, HalfEdge, Objects, Vertex}, - partial::{HasPartial, PartialSurfaceVertex}, + objects::{Cycle, Face, HalfEdge, Objects}, + partial::{HasPartial, PartialSurfaceVertex, PartialVertex}, }; #[test] @@ -218,69 +218,75 @@ mod tests { let face = (half_edge, Color::default()).sweep([0., 0., 1.], &objects)?; - let expected_face = - { - let surface = objects.surfaces.xz_plane(); + let expected_face = { + let surface = objects.surfaces.xz_plane(); - let bottom = HalfEdge::partial() - .update_as_line_segment_from_points( - surface.clone(), - [[0., 0.], [1., 0.]], - ) - .build(&objects)? - .insert(&objects)?; - let side_up = HalfEdge::partial() - .with_surface(surface.clone()) - .with_back_vertex(Vertex::partial().with_surface_form( - bottom.front().surface_form().clone(), - )) - .with_front_vertex(Vertex::partial().with_surface_form( - PartialSurfaceVertex { - position: Some([1., 1.].into()), - ..Default::default() - }, - )) - .update_as_line_segment() - .build(&objects)? - .insert(&objects)?; - let top = HalfEdge::partial() - .with_surface(surface.clone()) - .with_back_vertex(Vertex::partial().with_surface_form( - PartialSurfaceVertex { - position: Some([0., 1.].into()), - ..Default::default() - }, - )) - .with_front_vertex(Vertex::partial().with_surface_form( - side_up.front().surface_form().clone(), - )) - .update_as_line_segment() - .build(&objects)? - .insert(&objects)? - .reverse(&objects)?; - let side_down = - HalfEdge::partial() - .with_surface(surface) - .with_back_vertex(Vertex::partial().with_surface_form( - bottom.back().surface_form().clone(), - )) - .with_front_vertex(Vertex::partial().with_surface_form( - top.front().surface_form().clone(), - )) - .update_as_line_segment() - .build(&objects)? - .insert(&objects)? - .reverse(&objects)?; + let bottom = HalfEdge::partial() + .update_as_line_segment_from_points( + surface.clone(), + [[0., 0.], [1., 0.]], + ) + .build(&objects)? + .insert(&objects)?; + let side_up = HalfEdge::partial() + .with_surface(surface.clone()) + .with_back_vertex(PartialVertex { + surface_form: bottom.front().surface_form().clone().into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: PartialSurfaceVertex { + position: Some([1., 1.].into()), + ..Default::default() + } + .into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&objects)?; + let top = HalfEdge::partial() + .with_surface(surface.clone()) + .with_back_vertex(PartialVertex { + surface_form: PartialSurfaceVertex { + position: Some([0., 1.].into()), + ..Default::default() + } + .into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: side_up.front().surface_form().clone().into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&objects)? + .reverse(&objects)?; + let side_down = HalfEdge::partial() + .with_surface(surface) + .with_back_vertex(PartialVertex { + surface_form: bottom.back().surface_form().clone().into(), + ..Default::default() + }) + .with_front_vertex(PartialVertex { + surface_form: top.front().surface_form().clone().into(), + ..Default::default() + }) + .update_as_line_segment() + .build(&objects)? + .insert(&objects)? + .reverse(&objects)?; - let cycle = objects - .cycles - .insert(Cycle::new([bottom, side_up, top, side_down]))?; + let cycle = objects + .cycles + .insert(Cycle::new([bottom, side_up, top, side_down]))?; - Face::partial() - .with_exterior(cycle) - .build(&objects)? - .insert(&objects)? - }; + Face::partial() + .with_exterior(cycle) + .build(&objects)? + .insert(&objects)? + }; assert_eq!(face, expected_face); Ok(()) diff --git a/crates/fj-kernel/src/algorithms/transform/vertex.rs b/crates/fj-kernel/src/algorithms/transform/vertex.rs index fc66e5642..d925898bb 100644 --- a/crates/fj-kernel/src/algorithms/transform/vertex.rs +++ b/crates/fj-kernel/src/algorithms/transform/vertex.rs @@ -25,9 +25,8 @@ impl TransformObject for PartialVertex { Ok(Self { position: self.position, curve, - ..Default::default() - } - .with_surface_form(surface_form)) + surface_form: surface_form.into(), + }) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 5e0c2c794..bbdf5a6d6 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -75,13 +75,10 @@ impl CycleBuilder for PartialCycle { .update_as_line_from_points([position_prev, position_next]); let vertices = [(0., vertex_prev), (1., vertex_next)].map( - |(position, surface_form)| { - PartialVertex { - position: Some([position].into()), - curve: curve.clone().into(), - ..Default::default() - } - .with_surface_form(surface_form) + |(position, surface_form)| PartialVertex { + position: Some([position].into()), + curve: curve.clone().into(), + surface_form, }, ); diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index b5362bc55..06468f3c8 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -96,14 +96,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { .build(objects)? .insert(objects)?; - let [back, front] = [a_curve, b_curve].map(|point_curve| { - PartialVertex { + let [back, front] = + [a_curve, b_curve].map(|point_curve| PartialVertex { position: Some(point_curve), curve: curve.clone().into(), - ..Default::default() - } - .with_surface_form(surface_vertex.clone()) - }); + surface_form: surface_vertex.clone().into(), + }); Ok(self.with_curve(curve).with_vertices([back, front])) } @@ -120,7 +118,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { ..Default::default() }; - Vertex::partial().with_surface_form(surface_form) + PartialVertex { + surface_form: surface_form.into(), + ..Default::default() + } }); self.with_surface(surface) @@ -201,18 +202,16 @@ impl HalfEdgeBuilder for PartialHalfEdge { .zip(global_forms) .collect::<[_; 2]>() .map(|(vertex, global_form)| { - vertex.update_partial(|vertex| { - vertex.clone().with_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 - }, - ), - ) + 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 + }); + vertex }) }) }; diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index eb86fb61e..343b45857 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -8,9 +8,7 @@ use crate::{ algorithms::transform::TransformObject, builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{ - Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface, Vertex, - }, + objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell, Surface}, partial::{HasPartial, PartialCurve, PartialSurfaceVertex, PartialVertex}, storage::Handle, }; @@ -121,8 +119,14 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_vertices([ - Vertex::partial().with_surface_form(from), - Vertex::partial().with_surface_form(to), + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, ]) .update_as_line_segment() .build(self.objects) @@ -166,8 +170,14 @@ impl<'a> ShellBuilder<'a> { HalfEdge::partial() .with_curve(curve) .with_vertices([ - Vertex::partial().with_surface_form(from), - Vertex::partial().with_surface_form(to), + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, ]) .update_as_line_segment() .build(self.objects) @@ -189,8 +199,14 @@ impl<'a> ShellBuilder<'a> { let from = from.surface_form().clone(); let to = to.surface_form().clone(); - let from = Vertex::partial().with_surface_form(from); - let to = Vertex::partial().with_surface_form(to); + let from = PartialVertex { + surface_form: from.into(), + ..Default::default() + }; + let to = PartialVertex { + surface_form: to.into(), + ..Default::default() + }; HalfEdge::partial() .with_vertices([from, to]) @@ -276,12 +292,10 @@ impl<'a> ShellBuilder<'a> { .into_iter_fixed() .zip(surface_vertices.clone()) .collect::<[_; 2]>() - .map(|(vertex, surface_form)| { - PartialVertex { - position: Some(vertex.position()), - ..Default::default() - } - .with_surface_form(surface_form) + .map(|(vertex, surface_form)| PartialVertex { + position: Some(vertex.position()), + surface_form: surface_form.into(), + ..Default::default() }); edges.push( diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 30a0d3f0e..fda3e8873 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -15,8 +15,9 @@ pub trait VertexBuilder { } impl VertexBuilder for PartialVertex { - fn infer_surface_form(self) -> Self { - self.with_surface_form(PartialSurfaceVertex::default()) + fn infer_surface_form(mut self) -> Self { + self.surface_form = PartialSurfaceVertex::default().into(); + self } } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index a802133e3..eedf39ff8 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -96,9 +96,14 @@ impl PartialCycle { *half_edge = half_edge.clone().merge_with( PartialHalfEdge::default().with_vertices([ - PartialVertex::default().with_surface_form(back_vertex), - PartialVertex::default() - .with_surface_form(front_vertex.clone()), + PartialVertex { + surface_form: back_vertex, + ..Default::default() + }, + PartialVertex { + surface_form: front_vertex.clone().into(), + ..Default::default() + }, ]), ); @@ -111,9 +116,10 @@ impl PartialCycle { let back_vertex = previous_vertex.unwrap_or_default(); *half_edge = half_edge.clone().merge_with( - PartialHalfEdge::default().with_back_vertex( - PartialVertex::default().with_surface_form(back_vertex), - ), + PartialHalfEdge::default().with_back_vertex(PartialVertex { + surface_form: back_vertex, + ..Default::default() + }), ); } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index d26f806a3..cbace6209 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -54,7 +54,7 @@ impl PartialHalfEdge { }); self.vertices = self.vertices.map(|vertex| { - vertex.update_partial(|vertex| { + vertex.update_partial(|mut vertex| { let surface_form = vertex.surface_form.clone().update_partial( |mut surface_vertex| { surface_vertex.surface = Some(surface.clone()); @@ -62,7 +62,8 @@ impl PartialHalfEdge { }, ); - vertex.with_surface_form(surface_form) + vertex.surface_form = surface_form; + vertex }) }); diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 9f2330b7b..39a1fffc3 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -24,15 +24,6 @@ pub struct PartialVertex { } impl PartialVertex { - /// Provide a surface form for the partial vertex - pub fn with_surface_form( - mut self, - surface_form: impl Into>, - ) -> Self { - self.surface_form = surface_form.into(); - self - } - /// Build a full [`Vertex`] from the partial vertex /// /// # Panics From 6f8f06f2611666ce17107e4b52aaac87beb6e642 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:42:51 +0100 Subject: [PATCH 21/24] Change style of `infer_surface_form` --- crates/fj-kernel/src/builder/vertex.rs | 4 ++-- crates/fj-kernel/src/validate/cycle.rs | 3 ++- crates/fj-kernel/src/validate/edge.rs | 6 ++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index fda3e8873..88028756e 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -11,11 +11,11 @@ use crate::{ /// Builder API for [`PartialVertex`] pub trait VertexBuilder { /// Remove the surface form of the partial vertex, inferring it on build - fn infer_surface_form(self) -> Self; + fn infer_surface_form(&mut self) -> &mut Self; } impl VertexBuilder for PartialVertex { - fn infer_surface_form(mut self) -> Self { + fn infer_surface_form(&mut self) -> &mut Self { self.surface_form = PartialSurfaceVertex::default().into(); self } diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index 45824c301..b30ddaa9a 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -95,7 +95,8 @@ mod tests { // Sever connection between the last and first half-edge in the // cycle. - let first_vertex = first_vertex.into_partial().infer_surface_form(); + let mut first_vertex = first_vertex.into_partial(); + first_vertex.infer_surface_form(); *first_half_edge = first_half_edge .clone() .with_back_vertex(first_vertex) diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 9e2fdb744..0a294d415 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -308,10 +308,8 @@ mod tests { |vertex| -> anyhow::Result<_, ValidationError> { let mut vertex = vertex.to_partial(); vertex.position = Some([0.].into()); - Ok(vertex - .infer_surface_form() - .build(&objects)? - .insert(&objects)?) + vertex.infer_surface_form(); + Ok(vertex.build(&objects)?.insert(&objects)?) }, )?, valid.global_form().clone(), From 674d33a6bac9409846295399b981169e23dca995 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:53:02 +0100 Subject: [PATCH 22/24] Update builder method --- crates/fj-kernel/src/builder/edge.rs | 16 +++++++--------- crates/fj-kernel/src/builder/vertex.rs | 16 +++++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 06468f3c8..74794c131 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -3,12 +3,9 @@ use iter_fixed::IntoIteratorFixed; use crate::{ insert::Insert, - objects::{ - Curve, GlobalVertex, Objects, Surface, Vertex, - VerticesInNormalizedOrder, - }, + objects::{Curve, Objects, Surface, Vertex, VerticesInNormalizedOrder}, partial::{ - HasPartial, MaybePartial, PartialCurve, PartialGlobalEdge, + MaybePartial, PartialCurve, PartialGlobalEdge, PartialGlobalVertex, PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, @@ -82,10 +79,11 @@ impl HalfEdgeBuilder for PartialHalfEdge { .vertices() .map(|[global_form, _]| global_form) .unwrap_or_else(|| { - let mut global_vertex = GlobalVertex::partial(); - global_vertex - .update_from_curve_and_position(curve.clone(), a_curve); - global_vertex.into() + PartialGlobalVertex::from_curve_and_position( + curve.clone(), + a_curve, + ) + .into() }); let surface_vertex = PartialSurfaceVertex { diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 88028756e..3328dcd1a 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -37,11 +37,10 @@ impl SurfaceVertexBuilder for PartialSurfaceVertex { /// Builder API for [`PartialGlobalVertex`] pub trait GlobalVertexBuilder { /// Update partial global vertex from the given curve and position on it - fn update_from_curve_and_position( - &mut self, + fn from_curve_and_position( curve: impl Into>, position: impl Into>, - ) -> &mut Self; + ) -> Self; /// Update partial global vertex from the given surface and position on it fn update_from_surface_and_position( @@ -52,11 +51,10 @@ pub trait GlobalVertexBuilder { } impl GlobalVertexBuilder for PartialGlobalVertex { - fn update_from_curve_and_position( - &mut self, + fn from_curve_and_position( curve: impl Into>, position: impl Into>, - ) -> &mut Self { + ) -> Self { let curve = curve.into().into_partial(); let path = curve.path.expect( @@ -67,7 +65,11 @@ impl GlobalVertexBuilder for PartialGlobalVertex { ); let position_surface = path.point_from_path_coords(position); - self.update_from_surface_and_position(&surface, position_surface) + + let mut global_vertex = PartialGlobalVertex::default(); + global_vertex + .update_from_surface_and_position(&surface, position_surface); + global_vertex } fn update_from_surface_and_position( From 73a411d9021730b23c594147eef03afc8f947902 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:56:12 +0100 Subject: [PATCH 23/24] Update builder method --- crates/fj-kernel/src/builder/vertex.rs | 20 ++++++++----------- .../fj-kernel/src/partial/objects/vertex.rs | 8 ++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 3328dcd1a..879d5533f 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -43,11 +43,10 @@ pub trait GlobalVertexBuilder { ) -> Self; /// Update partial global vertex from the given surface and position on it - fn update_from_surface_and_position( - &mut self, + fn from_surface_and_position( surface: &Surface, position: impl Into>, - ) -> &mut Self; + ) -> Self; } impl GlobalVertexBuilder for PartialGlobalVertex { @@ -66,18 +65,15 @@ impl GlobalVertexBuilder for PartialGlobalVertex { let position_surface = path.point_from_path_coords(position); - let mut global_vertex = PartialGlobalVertex::default(); - global_vertex - .update_from_surface_and_position(&surface, position_surface); - global_vertex + Self::from_surface_and_position(&surface, position_surface) } - fn update_from_surface_and_position( - &mut self, + fn from_surface_and_position( surface: &Surface, position: impl Into>, - ) -> &mut Self { - self.position = Some(surface.point_from_surface_coords(position)); - self + ) -> Self { + PartialGlobalVertex { + position: Some(surface.point_from_surface_coords(position)), + } } } diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index 39a1fffc3..ce6ba3c7e 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -107,10 +107,10 @@ impl PartialSurfaceVertex { let global_form = self .global_form - .update_partial(|mut global_form| { - global_form - .update_from_surface_and_position(&surface, position); - global_form + .update_partial(|_| { + PartialGlobalVertex::from_surface_and_position( + &surface, position, + ) }) .into_full(objects)?; From 6f158e1f189aa23b4cc10de3de3a4965c8191799 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 11 Nov 2022 16:58:03 +0100 Subject: [PATCH 24/24] Refactor --- crates/fj-kernel/src/partial/objects/vertex.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/partial/objects/vertex.rs b/crates/fj-kernel/src/partial/objects/vertex.rs index ce6ba3c7e..111ddf7fc 100644 --- a/crates/fj-kernel/src/partial/objects/vertex.rs +++ b/crates/fj-kernel/src/partial/objects/vertex.rs @@ -107,11 +107,9 @@ impl PartialSurfaceVertex { let global_form = self .global_form - .update_partial(|_| { - PartialGlobalVertex::from_surface_and_position( - &surface, position, - ) - }) + .merge_with(PartialGlobalVertex::from_surface_and_position( + &surface, position, + )) .into_full(objects)?; Ok(SurfaceVertex::new(position, surface, global_form))