From 3ff5bd34bbfb50d84816b5df124146119ebfb96e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Nov 2022 13:14:25 +0100 Subject: [PATCH 1/4] Remove `PartialHalfEdge::with_curve` --- .../src/algorithms/transform/edge.rs | 10 +++-- crates/fj-kernel/src/builder/cycle.rs | 10 +++-- crates/fj-kernel/src/builder/edge.rs | 12 ++++-- crates/fj-kernel/src/builder/shell.rs | 40 ++++++++++--------- crates/fj-kernel/src/partial/objects/edge.rs | 7 ---- 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 1d960cf20..8590e0d77 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -30,10 +30,12 @@ impl TransformObject for PartialHalfEdge { .transform(transform, objects)?; global_form.curve = curve.global_form(); - Ok(Self::default() - .with_curve(curve) - .with_vertices(vertices) - .with_global_form(global_form)) + Ok(Self { + curve, + ..Default::default() + } + .with_vertices(vertices) + .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index bbdf5a6d6..e1051b2cf 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -3,7 +3,7 @@ use fj_math::Point; use crate::{ objects::{HalfEdge, Surface, SurfaceVertex}, partial::{ - HasPartial, MaybePartial, PartialCurve, PartialCycle, + HasPartial, MaybePartial, PartialCurve, PartialCycle, PartialHalfEdge, PartialSurfaceVertex, PartialVertex, }, storage::Handle, @@ -83,9 +83,11 @@ impl CycleBuilder for PartialCycle { ); half_edges.push( - HalfEdge::partial() - .with_curve(curve) - .with_vertices(vertices), + PartialHalfEdge { + curve: curve.into(), + ..Default::default() + } + .with_vertices(vertices), ); continue; diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index ad24ac9b2..d2aaf70e0 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -61,7 +61,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { } fn update_as_circle_from_radius( - self, + mut self, radius: impl Into, objects: &Objects, ) -> Result { @@ -90,7 +90,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface_form: surface_vertex.clone().into(), }); - Ok(self.with_curve(curve).with_vertices([back, front])) + self.curve = curve.into(); + + Ok(self.with_vertices([back, front])) } fn update_as_line_segment_from_points( @@ -115,7 +117,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { self.with_vertices(vertices).update_as_line_segment() } - fn update_as_line_segment(self) -> Self { + fn update_as_line_segment(mut self) -> Self { let [from, to] = self.vertices.clone(); let [from_surface, to_surface] = [&from, &to].map(|vertex| vertex.surface_form()); @@ -190,7 +192,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { }) }; - self.with_curve(curve).with_vertices([back, front]) + self.curve = curve.into(); + + self.with_vertices([back, front]) } fn infer_global_form(self) -> Self { diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index ad575271c..3aa4ddfcc 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -10,8 +10,8 @@ use crate::{ insert::Insert, objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell}, partial::{ - HasPartial, PartialCurve, PartialSurface, PartialSurfaceVertex, - PartialVertex, + HasPartial, PartialCurve, PartialHalfEdge, PartialSurface, + PartialSurfaceVertex, PartialVertex, }, storage::Handle, }; @@ -169,23 +169,25 @@ impl<'a> ShellBuilder<'a> { ..Default::default() }; - HalfEdge::partial() - .with_curve(curve) - .with_vertices([ - PartialVertex { - surface_form: from.into(), - ..Default::default() - }, - PartialVertex { - surface_form: to.into(), - ..Default::default() - }, - ]) - .update_as_line_segment() - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap() + PartialHalfEdge { + curve: curve.into(), + ..Default::default() + } + .with_vertices([ + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, + ]) + .update_as_line_segment() + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap() }) .collect::>() }; diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 50633d4be..450afebed 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,13 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Update the partial half-edge with the given curve - pub fn with_curve(mut self, curve: impl Into>) -> Self { - self.curve = curve.into(); - - self - } - /// Update the partial half-edge with the given vertices pub fn with_vertices( mut self, From b684550431f8b7de2402e864f4192b32c1609f0f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Nov 2022 13:26:55 +0100 Subject: [PATCH 2/4] Remove `PartialHalfEdge::with_vertices` --- .../src/algorithms/transform/edge.rs | 2 +- crates/fj-kernel/src/builder/cycle.rs | 12 ++- crates/fj-kernel/src/builder/edge.rs | 25 +++++-- crates/fj-kernel/src/builder/shell.rs | 74 ++++++++++--------- crates/fj-kernel/src/partial/objects/cycle.rs | 10 ++- crates/fj-kernel/src/partial/objects/edge.rs | 9 --- 6 files changed, 71 insertions(+), 61 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index 8590e0d77..a69b67341 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -32,9 +32,9 @@ impl TransformObject for PartialHalfEdge { Ok(Self { curve, + vertices: vertices.map(Into::into), ..Default::default() } - .with_vertices(vertices) .with_global_form(global_form)) } } diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index e1051b2cf..62e34b27a 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -82,13 +82,11 @@ impl CycleBuilder for PartialCycle { }, ); - half_edges.push( - PartialHalfEdge { - curve: curve.into(), - ..Default::default() - } - .with_vertices(vertices), - ); + half_edges.push(PartialHalfEdge { + curve: curve.into(), + vertices: vertices.map(Into::into), + ..Default::default() + }); continue; } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index d2aaf70e0..3e3f45279 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -50,14 +50,22 @@ pub trait HalfEdgeBuilder: Sized { } impl HalfEdgeBuilder for PartialHalfEdge { - fn with_back_vertex(self, back: impl Into>) -> Self { + fn with_back_vertex( + mut self, + back: impl Into>, + ) -> Self { let [_, front] = self.vertices.clone(); - self.with_vertices([back.into(), front]) + self.vertices = [back.into(), front]; + self } - fn with_front_vertex(self, front: impl Into>) -> Self { + fn with_front_vertex( + mut self, + front: impl Into>, + ) -> Self { let [back, _] = self.vertices.clone(); - self.with_vertices([back, front.into()]) + self.vertices = [back, front.into()]; + self } fn update_as_circle_from_radius( @@ -91,8 +99,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { }); self.curve = curve.into(); + self.vertices = [back, front].map(Into::into); - Ok(self.with_vertices([back, front])) + Ok(self) } fn update_as_line_segment_from_points( @@ -114,7 +123,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { }); self.replace(surface); - self.with_vertices(vertices).update_as_line_segment() + self.vertices = vertices.map(Into::into); + self.update_as_line_segment() } fn update_as_line_segment(mut self) -> Self { @@ -193,8 +203,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { }; self.curve = curve.into(); + self.vertices = [back, front]; - self.with_vertices([back, front]) + self } fn infer_global_form(self) -> Self { diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 3aa4ddfcc..83c81a7c6 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -121,8 +121,8 @@ impl<'a> ShellBuilder<'a> { ..Default::default() }; - HalfEdge::partial() - .with_vertices([ + PartialHalfEdge { + vertices: [ PartialVertex { surface_form: from.into(), ..Default::default() @@ -131,12 +131,15 @@ impl<'a> ShellBuilder<'a> { surface_form: to.into(), ..Default::default() }, - ]) - .update_as_line_segment() - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap() + ] + .map(Into::into), + ..Default::default() + } + .update_as_line_segment() + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap() }) .collect::>(); @@ -171,18 +174,19 @@ impl<'a> ShellBuilder<'a> { PartialHalfEdge { curve: curve.into(), + vertices: [ + PartialVertex { + surface_form: from.into(), + ..Default::default() + }, + PartialVertex { + surface_form: to.into(), + ..Default::default() + }, + ] + .map(Into::into), ..Default::default() } - .with_vertices([ - PartialVertex { - surface_form: from.into(), - ..Default::default() - }, - PartialVertex { - surface_form: to.into(), - ..Default::default() - }, - ]) .update_as_line_segment() .build(self.objects) .unwrap() @@ -212,13 +216,15 @@ impl<'a> ShellBuilder<'a> { ..Default::default() }; - HalfEdge::partial() - .with_vertices([from, to]) - .update_as_line_segment() - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap() + PartialHalfEdge { + vertices: [from, to].map(Into::into), + ..Default::default() + } + .update_as_line_segment() + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap() }) .collect::>(); @@ -303,14 +309,16 @@ impl<'a> ShellBuilder<'a> { }); edges.push( - HalfEdge::partial() - .with_vertices(vertices) - .with_global_form(edge.global_form().clone()) - .update_as_line_segment() - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap(), + PartialHalfEdge { + vertices: vertices.map(Into::into), + ..Default::default() + } + .with_global_form(edge.global_form().clone()) + .update_as_line_segment() + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap(), ); } diff --git a/crates/fj-kernel/src/partial/objects/cycle.rs b/crates/fj-kernel/src/partial/objects/cycle.rs index e3fd458a3..9d6d1fa8d 100644 --- a/crates/fj-kernel/src/partial/objects/cycle.rs +++ b/crates/fj-kernel/src/partial/objects/cycle.rs @@ -98,8 +98,8 @@ impl PartialCycle { let front_vertex = half_edge.front().surface_form().into_full(objects)?; - *half_edge = half_edge.clone().merge_with( - PartialHalfEdge::default().with_vertices([ + *half_edge = half_edge.clone().merge_with(PartialHalfEdge { + vertices: [ PartialVertex { surface_form: back_vertex, ..Default::default() @@ -108,8 +108,10 @@ impl PartialCycle { surface_form: front_vertex.clone().into(), ..Default::default() }, - ]), - ); + ] + .map(Into::into), + ..Default::default() + }); previous_vertex = Some(MaybePartial::from(front_vertex)); } diff --git a/crates/fj-kernel/src/partial/objects/edge.rs b/crates/fj-kernel/src/partial/objects/edge.rs index 450afebed..e2460f265 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 { - /// Update the partial half-edge with the given vertices - pub fn with_vertices( - mut self, - vertices: [impl Into>; 2], - ) -> Self { - self.vertices = vertices.map(Into::into); - self - } - /// Update the partial half-edge with the given global form pub fn with_global_form( mut self, From 33ece82867af79bc04eb67000d1c333fb27e4ac0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Nov 2022 13:29:10 +0100 Subject: [PATCH 3/4] Remove `PartialHalfEdge::with_global_form` --- .../src/algorithms/transform/edge.rs | 5 ++-- crates/fj-kernel/src/builder/edge.rs | 5 ++-- crates/fj-kernel/src/builder/shell.rs | 26 ++++++++++--------- crates/fj-kernel/src/partial/objects/edge.rs | 10 ------- 4 files changed, 19 insertions(+), 27 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index a69b67341..c9557c45f 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -33,9 +33,8 @@ impl TransformObject for PartialHalfEdge { Ok(Self { curve, vertices: vertices.map(Into::into), - ..Default::default() - } - .with_global_form(global_form)) + global_form: global_form.into(), + }) } } diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3e3f45279..c6fd5c4fb 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -208,8 +208,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { self } - fn infer_global_form(self) -> Self { - self.with_global_form(PartialGlobalEdge::default()) + fn infer_global_form(mut self) -> Self { + self.global_form = PartialGlobalEdge::default().into(); + self } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 83c81a7c6..73a4a07d3 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -8,7 +8,7 @@ use crate::{ algorithms::transform::TransformObject, builder::{FaceBuilder, HalfEdgeBuilder, SurfaceBuilder}, insert::Insert, - objects::{Cycle, Face, FaceSet, HalfEdge, Objects, Shell}, + objects::{Cycle, Face, FaceSet, Objects, Shell}, partial::{ HasPartial, PartialCurve, PartialHalfEdge, PartialSurface, PartialSurfaceVertex, PartialVertex, @@ -94,16 +94,18 @@ impl<'a> ShellBuilder<'a> { .half_edges() .zip(&surfaces) .map(|(half_edge, surface)| { - HalfEdge::partial() - .with_global_form(half_edge.global_form().clone()) - .update_as_line_segment_from_points( - surface.clone(), - [[Z, Z], [edge_length, Z]], - ) - .build(self.objects) - .unwrap() - .insert(self.objects) - .unwrap() + PartialHalfEdge { + global_form: half_edge.global_form().clone().into(), + ..Default::default() + } + .update_as_line_segment_from_points( + surface.clone(), + [[Z, Z], [edge_length, Z]], + ) + .build(self.objects) + .unwrap() + .insert(self.objects) + .unwrap() }) .collect::>(); @@ -311,9 +313,9 @@ impl<'a> ShellBuilder<'a> { edges.push( PartialHalfEdge { vertices: vertices.map(Into::into), + global_form: edge.global_form().clone().into(), ..Default::default() } - .with_global_form(edge.global_form().clone()) .update_as_line_segment() .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 e2460f265..1f5dd3089 100644 --- a/crates/fj-kernel/src/partial/objects/edge.rs +++ b/crates/fj-kernel/src/partial/objects/edge.rs @@ -27,16 +27,6 @@ pub struct PartialHalfEdge { } impl PartialHalfEdge { - /// Update the partial half-edge with the given global form - pub fn with_global_form( - mut self, - global_form: impl Into>, - ) -> Self { - self.global_form = global_form.into(); - - self - } - /// Build a full [`HalfEdge`] from the partial half-edge pub fn build( mut self, From a8919a5a62dc8372cff5b5fa1fb78a2ef8b3e78a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Nov 2022 14:14:44 +0100 Subject: [PATCH 4/4] Remove redundant code The curve merging/replacement is already done in `PartialHalfEdge::build`. --- .../src/algorithms/transform/edge.rs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform/edge.rs b/crates/fj-kernel/src/algorithms/transform/edge.rs index c9557c45f..0b7717268 100644 --- a/crates/fj-kernel/src/algorithms/transform/edge.rs +++ b/crates/fj-kernel/src/algorithms/transform/edge.rs @@ -16,24 +16,15 @@ impl TransformObject for PartialHalfEdge { objects: &Objects, ) -> Result { let curve = self.curve.transform(transform, objects)?; - let vertices = self.vertices.try_map_ext( - |vertex| -> Result<_, ValidationError> { - let mut vertex = - vertex.into_partial().transform(transform, objects)?; - vertex.curve = curve.clone(); - Ok(vertex) - }, - )?; - let mut global_form = self - .global_form - .into_partial() - .transform(transform, objects)?; - global_form.curve = curve.global_form(); + let vertices = self + .vertices + .try_map_ext(|vertex| vertex.transform(transform, objects))?; + let global_form = self.global_form.transform(transform, objects)?; Ok(Self { curve, - vertices: vertices.map(Into::into), - global_form: global_form.into(), + vertices, + global_form, }) } }