From 69eaf7665b78673d5d4b7b32c64147863d2ba3ec Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:25:45 +0100 Subject: [PATCH 01/25] Update documentation of `CurveBuilder` --- crates/fj-kernel/src/builder/curve.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/curve.rs b/crates/fj-kernel/src/builder/curve.rs index 85d71a63c..cc904b321 100644 --- a/crates/fj-kernel/src/builder/curve.rs +++ b/crates/fj-kernel/src/builder/curve.rs @@ -4,19 +4,19 @@ use crate::{geometry::path::SurfacePath, partial::PartialCurve}; /// Builder API for [`PartialCurve`] pub trait CurveBuilder { - /// Update partial curve to represent the u-axis + /// Update partial curve to represent the u-axis of the surface it is on fn update_as_u_axis(&mut self) -> &mut Self; - /// Update partial curve to represent the v-axis + /// Update partial curve to represent the v-axis of the surface it is on fn update_as_v_axis(&mut self) -> &mut Self; - /// Update partial curve as a circle, from the provided radius + /// Update partial curve to be a circle, from the provided radius fn update_as_circle_from_radius( &mut self, radius: impl Into, ) -> &mut Self; - /// Update partial curve as a line, from the provided points + /// Update partial curve to be a line, from the provided points fn update_as_line_from_points( &mut self, points: [impl Into>; 2], From bbe2f6db9eeda57f6f1b4604aca448e7cc21be53 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:33:46 +0100 Subject: [PATCH 02/25] Refactor --- crates/fj-kernel/src/validate/vertex.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/validate/vertex.rs b/crates/fj-kernel/src/validate/vertex.rs index bfa1cc5bc..600e840cc 100644 --- a/crates/fj-kernel/src/validate/vertex.rs +++ b/crates/fj-kernel/src/validate/vertex.rs @@ -180,7 +180,7 @@ impl SurfaceVertexValidationError { #[cfg(test)] mod tests { use crate::{ - builder::{CurveBuilder, SurfaceVertexBuilder}, + builder::CurveBuilder, insert::Insert, objects::{GlobalVertex, SurfaceVertex, Vertex}, partial::{ @@ -256,7 +256,7 @@ mod tests { let mut surface_form = Partial::from_full_entry_point(valid.surface_form().clone()); surface_form.write().position = Some([1., 0.].into()); - surface_form.write().infer_global_form(); + surface_form.write().global_form = Partial::new(); let surface_form = surface_form.build(&mut services.objects); Vertex::new(valid.position(), valid.curve().clone(), surface_form) From 257194f2a521f799a3ae3c175ae0f40137685c27 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:34:48 +0100 Subject: [PATCH 03/25] Remove unused vertex builder methods --- crates/fj-kernel/src/builder/vertex.rs | 69 +++----------------------- 1 file changed, 8 insertions(+), 61 deletions(-) diff --git a/crates/fj-kernel/src/builder/vertex.rs b/crates/fj-kernel/src/builder/vertex.rs index 2d12dd6d0..dcf1bac7a 100644 --- a/crates/fj-kernel/src/builder/vertex.rs +++ b/crates/fj-kernel/src/builder/vertex.rs @@ -1,33 +1,19 @@ -use fj_math::Point; - -use crate::{ - geometry::surface::SurfaceGeometry, - objects::Curve, - partial::{ - Partial, PartialGlobalVertex, PartialSurfaceVertex, PartialVertex, - }, +use crate::partial::{ + PartialGlobalVertex, PartialSurfaceVertex, PartialVertex, }; /// Builder API for [`PartialVertex`] pub trait VertexBuilder { - /// Remove the surface form of the partial vertex, inferring it on build - fn infer_surface_form(&mut self) -> &mut Self; + // No methods are currently defined. This trait serves as a placeholder, to + // make it clear where to add such methods, once necessary. } -impl VertexBuilder for PartialVertex { - fn infer_surface_form(&mut self) -> &mut Self { - self.surface_form = Partial::new(); - self - } -} +impl VertexBuilder for PartialVertex {} /// Builder API for [`PartialSurfaceVertex`] pub trait SurfaceVertexBuilder { /// Infer the position of the surface vertex' global form fn infer_global_position(&mut self) -> &mut Self; - - /// Infer the global form of the partial vertex - fn infer_global_form(&mut self) -> &mut Self; } impl SurfaceVertexBuilder for PartialSurfaceVertex { @@ -46,51 +32,12 @@ impl SurfaceVertexBuilder for PartialSurfaceVertex { self } - - fn infer_global_form(&mut self) -> &mut Self { - self.global_form = Partial::new(); - self - } } /// Builder API for [`PartialGlobalVertex`] -pub trait GlobalVertexBuilder { - /// Update partial global vertex from the given curve and position on it - fn from_curve_and_position( - curve: Partial, - position: impl Into>, - ) -> Self; - - /// Update partial global vertex from the given surface and position on it - fn from_surface_and_position( - surface: &SurfaceGeometry, - position: impl Into>, - ) -> Self; -} +pub trait GlobalVertexBuilder {} impl GlobalVertexBuilder for PartialGlobalVertex { - fn from_curve_and_position( - curve: Partial, - position: impl Into>, - ) -> Self { - let path = curve.read().path.expect( - "Need path to create `GlobalVertex` from curve and position", - ); - let surface = curve.read().surface.read().geometry.expect( - "Need surface to create `GlobalVertex` from curve and position", - ); - - let position_surface = path.point_from_path_coords(position); - - Self::from_surface_and_position(&surface, position_surface) - } - - fn from_surface_and_position( - surface: &SurfaceGeometry, - position: impl Into>, - ) -> Self { - Self { - position: Some(surface.point_from_surface_coords(position)), - } - } + // No methods are currently defined. This trait serves as a placeholder, to + // make it clear where to add such methods, once necessary. } From d70e3faf89bfa67de8f7f6c0993ac4cbdefe31e0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:37:19 +0100 Subject: [PATCH 04/25] Remove unused edge builder methods --- crates/fj-kernel/src/builder/edge.rs | 52 +++------------------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3efb4613e..8f6d9b7e2 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -2,21 +2,14 @@ use fj_interop::ext::ArrayExt; use fj_math::{Point, Scalar}; use crate::{ - objects::{Curve, Surface, Vertex}, + objects::Surface, partial::{Partial, PartialGlobalEdge, PartialHalfEdge}, - storage::Handle, }; use super::{CurveBuilder, SurfaceVertexBuilder}; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder: Sized { - /// Update the partial half-edge with the given back vertex - fn with_back_vertex(self, back: Partial) -> Self; - - /// Update the partial half-edge with the given front vertex - fn with_front_vertex(self, front: Partial) -> Self; - /// Update partial half-edge as a circle, from the given radius fn update_as_circle_from_radius(self, radius: impl Into) -> Self; @@ -29,24 +22,9 @@ pub trait HalfEdgeBuilder: Sized { /// Update partial half-edge as a line segment, reusing existing vertices fn update_as_line_segment(self) -> Self; - - /// Infer the global form of the partial half-edge - fn infer_global_form(self) -> Self; } impl HalfEdgeBuilder for PartialHalfEdge { - fn with_back_vertex(mut self, back: Partial) -> Self { - let [_, front] = self.vertices.clone(); - self.vertices = [back, front]; - self - } - - fn with_front_vertex(mut self, front: Partial) -> Self { - let [back, _] = self.vertices.clone(); - self.vertices = [back, front]; - self - } - fn update_as_circle_from_radius( mut self, radius: impl Into, @@ -133,34 +111,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { self } - - fn infer_global_form(mut self) -> Self { - self.global_form = Partial::new(); - self - } } /// Builder API for [`PartialGlobalEdge`] pub trait GlobalEdgeBuilder { - /// Update partial global edge from the given curve and vertices - fn update_from_curve_and_vertices( - self, - curve: &Curve, - vertices: &[Handle; 2], - ) -> Self; + // No methods are currently defined. This trait serves as a placeholder, to + // make it clear where to add such methods, once necessary. } -impl GlobalEdgeBuilder for PartialGlobalEdge { - fn update_from_curve_and_vertices( - mut self, - curve: &Curve, - vertices: &[Handle; 2], - ) -> Self { - self.curve = - Partial::from_full_entry_point(curve.global_form().clone()); - self.vertices = vertices.clone().map(|vertex| { - Partial::from_full_entry_point(vertex.global_form().clone()) - }); - self - } -} +impl GlobalEdgeBuilder for PartialGlobalEdge {} From 7fb7f1f485d60a1fde2817b98c90bac00c583e34 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:49:31 +0100 Subject: [PATCH 05/25] Update `HalfEdgeBuilder` method to latest style --- crates/fj-kernel/src/builder/edge.rs | 9 ++++++--- crates/fj-operations/src/sketch.rs | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 8f6d9b7e2..75a522217 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -11,7 +11,10 @@ use super::{CurveBuilder, SurfaceVertexBuilder}; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder: Sized { /// Update partial half-edge as a circle, from the given radius - fn update_as_circle_from_radius(self, radius: impl Into) -> Self; + fn update_as_circle_from_radius( + &mut self, + radius: impl Into, + ) -> &mut Self; /// Update partial half-edge as a line segment, from the given points fn update_as_line_segment_from_points( @@ -26,9 +29,9 @@ pub trait HalfEdgeBuilder: Sized { impl HalfEdgeBuilder for PartialHalfEdge { fn update_as_circle_from_radius( - mut self, + &mut self, radius: impl Into, - ) -> Self { + ) -> &mut Self { let mut curve = self.curve(); curve.write().update_as_circle_from_radius(radius); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index e92e3addf..7409fe863 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -59,16 +59,16 @@ impl Shape for fj::Sketch { }, ); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: curve.read().global_form.clone(), vertices: global_vertices, }), }; - Partial::from_partial( - half_edge.update_as_circle_from_radius(circle.radius()), - ) + half_edge.update_as_circle_from_radius(circle.radius()); + + Partial::from_partial(half_edge) }; let cycle = Partial::from_partial(PartialCycle::new(vec![half_edge])); From 76d0caa26bd9f02109e82677833983e2807e549e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:56:48 +0100 Subject: [PATCH 06/25] Update `HalfEdgeBuilder` method to latest style --- .../src/algorithms/intersect/curve_edge.rs | 52 +++++++------- crates/fj-kernel/src/algorithms/sweep/edge.rs | 24 +++---- crates/fj-kernel/src/algorithms/sweep/face.rs | 28 ++++---- .../fj-kernel/src/algorithms/sweep/vertex.rs | 10 +-- crates/fj-kernel/src/builder/edge.rs | 11 +-- crates/fj-kernel/src/builder/shell.rs | 66 +++++++++--------- crates/fj-kernel/src/iter.rs | 14 ++-- crates/fj-kernel/src/objects/full/edge.rs | 16 ++--- crates/fj-kernel/src/validate/edge.rs | 68 +++++++++---------- 9 files changed, 140 insertions(+), 149 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index d59f5ae66..fe9f8b4c8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -112,20 +112,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + surface, + [[1., -1.], [1., 1.]], + ); - half_edge - .update_as_line_segment_from_points( - surface, - [[1., -1.], [1., 1.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -161,20 +160,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + surface, + [[-1., -1.], [-1., 1.]], + ); - half_edge - .update_as_line_segment_from_points( - surface, - [[-1., -1.], [-1., 1.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -210,20 +208,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + surface, + [[-1., -1.], [1., -1.]], + ); - half_edge - .update_as_line_segment_from_points( - surface, - [[-1., -1.], [1., -1.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); @@ -254,20 +251,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + surface, + [[-1., 0.], [1., 0.]], + ); - half_edge - .update_as_line_segment_from_points( - surface, - [[-1., 0.], [1., 0.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let intersection = CurveEdgeIntersection::compute(&curve, &half_edge); diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 7ef4f6f63..821c8405e 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -217,21 +217,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) .build(&mut services.objects) .insert(&mut services.objects) }; @@ -254,19 +254,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + surface.clone(), + [[0., 0.], [1., 0.]], + ); half_edge - .update_as_line_segment_from_points( - surface.clone(), - [[0., 0.], [1., 0.]], - ) .build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 688a24d37..73c15a410 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -148,21 +148,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [a, b], + ); half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [a, b], - ) .build(&mut services.objects) .insert(&mut services.objects) }; @@ -216,21 +216,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [a, b], + ); half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [a, b], - ) .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index ae67900a2..4131fd02e 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -211,19 +211,19 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point(surface), + [[0., 0.], [0., 1.]], + ); half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point(surface), - [[0., 0.], [0., 1.]], - ) .build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 75a522217..ed82e953c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -18,10 +18,10 @@ pub trait HalfEdgeBuilder: Sized { /// Update partial half-edge as a line segment, from the given points fn update_as_line_segment_from_points( - self, + &mut self, surface: Partial, points: [impl Into>; 2], - ) -> Self; + ) -> &mut Self; /// Update partial half-edge as a line segment, reusing existing vertices fn update_as_line_segment(self) -> Self; @@ -65,10 +65,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { } fn update_as_line_segment_from_points( - mut self, + &mut self, surface: Partial, points: [impl Into>; 2], - ) -> Self { + ) -> &mut Self { for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) { let mut vertex = vertex.write(); @@ -80,7 +80,8 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface_form.infer_global_position(); } - self.update_as_line_segment() + *self = self.clone().update_as_line_segment(); + self } fn update_as_line_segment(mut self) -> Self { diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 2f1dc1818..afc63a66b 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -89,41 +89,39 @@ impl ShellBuilder { .read() .clone(); - Partial::from_partial( - PartialHalfEdge { - vertices: global_edge.vertices.clone().map( - |global_vertex| { - Partial::from_partial(PartialVertex { - curve: Partial::from_partial( - PartialCurve { - global_form: global_edge - .curve - .clone(), - ..Default::default() - }, - ), - surface_form: Partial::from_partial( - PartialSurfaceVertex { - global_form: global_vertex, - ..Default::default() - }, - ), - ..Default::default() - }) - }, - ), - global_form: Partial::from_partial( - PartialGlobalEdge { - curve: global_edge.curve, - vertices: global_edge.vertices, - }, - ), - } - .update_as_line_segment_from_points( - Partial::from_full_entry_point(surface.clone()), - [[Z, Z], [edge_length, Z]], + let mut half_edge = PartialHalfEdge { + vertices: global_edge.vertices.clone().map( + |global_vertex| { + Partial::from_partial(PartialVertex { + curve: Partial::from_partial( + PartialCurve { + global_form: global_edge + .curve + .clone(), + ..Default::default() + }, + ), + surface_form: Partial::from_partial( + PartialSurfaceVertex { + global_form: global_vertex, + ..Default::default() + }, + ), + ..Default::default() + }) + }, ), - ) + global_form: Partial::from_partial(PartialGlobalEdge { + curve: global_edge.curve, + vertices: global_edge.vertices, + }), + }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point(surface.clone()), + [[Z, Z], [edge_length, Z]], + ); + + Partial::from_partial(half_edge) }) .collect::>(); diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 6ec8de881..98038056c 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -512,21 +512,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) .build(&mut services.objects) .insert(&mut services.objects) }; diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index e45c5176d..90f6cb332 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -177,17 +177,17 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; - half_edge - .update_as_line_segment_from_points(surface.clone(), [a, b]) - .build(&mut services.objects) + .update_as_line_segment_from_points(surface.clone(), [a, b]); + + half_edge.build(&mut services.objects) }; let b_to_a = { let vertices = array::from_fn(|_| Partial::::new()); @@ -199,16 +199,16 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; - half_edge - .update_as_line_segment_from_points(surface, [b, a]) - .build(&mut services.objects) + half_edge.update_as_line_segment_from_points(surface, [b, a]); + + half_edge.build(&mut services.objects) }; assert_eq!(a_to_b.global_form(), b_to_a.global_form()); diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index 8008fd674..dc43c0cbf 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -228,22 +228,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); - half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let invalid = { let mut vertices = valid.vertices().clone(); @@ -278,22 +277,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); - half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let invalid = HalfEdge::new(valid.vertices().clone(), { let mut tmp = @@ -322,22 +320,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); - half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let invalid = HalfEdge::new(valid.vertices().clone(), { let mut tmp = @@ -373,22 +370,21 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + half_edge.update_as_line_segment_from_points( + Partial::from_full_entry_point( + services.objects.surfaces.xy_plane(), + ), + [[0., 0.], [1., 0.]], + ); - half_edge - .update_as_line_segment_from_points( - Partial::from_full_entry_point( - services.objects.surfaces.xy_plane(), - ), - [[0., 0.], [1., 0.]], - ) - .build(&mut services.objects) + half_edge.build(&mut services.objects) }; let invalid = HalfEdge::new( valid.vertices().clone().map(|vertex| { From 2fbfa9b34955297b8c12fc0f202278d749dd2c4a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 14:58:06 +0100 Subject: [PATCH 07/25] Refactor --- crates/fj-kernel/src/builder/cycle.rs | 20 +++--- crates/fj-kernel/src/builder/shell.rs | 88 +++++++++++++-------------- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index c43a83c91..6ed85ea55 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -151,18 +151,16 @@ impl CycleBuilder for PartialCycle { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = Partial::from_partial( - PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve, - vertices: global_vertices, - }), - } - .update_as_line_segment(), - ); + let half_edge = PartialHalfEdge { + vertices, + global_form: Partial::from_partial(PartialGlobalEdge { + curve, + vertices: global_vertices, + }), + } + .update_as_line_segment(); - self.half_edges.push(half_edge); + self.half_edges.push(Partial::from_partial(half_edge)); self } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index afc63a66b..4e965e200 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -177,18 +177,16 @@ impl ShellBuilder { .clone() }); - Partial::from_partial( - PartialHalfEdge { - vertices, - global_form: Partial::from_partial( - PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }, - ), - } - .update_as_line_segment(), - ) + let half_edge = PartialHalfEdge { + vertices, + global_form: Partial::from_partial(PartialGlobalEdge { + curve: global_curve, + vertices: global_vertices, + }), + } + .update_as_line_segment(); + + Partial::from_partial(half_edge) }) .collect::>(); @@ -271,18 +269,18 @@ impl ShellBuilder { .clone() }); - Partial::from_partial( - PartialHalfEdge { - vertices, - global_form: Partial::from_partial( - PartialGlobalEdge { - vertices: global_vertices, - curve: curve.global_form, - }, - ), - } - .update_as_line_segment(), - ) + let half_edge = PartialHalfEdge { + vertices, + global_form: Partial::from_partial( + PartialGlobalEdge { + vertices: global_vertices, + curve: curve.global_form, + }, + ), + } + .update_as_line_segment(); + + Partial::from_partial(half_edge) }, ) .collect::>() @@ -332,18 +330,16 @@ impl ShellBuilder { .clone() }); - Partial::from_partial( - PartialHalfEdge { - vertices, - global_form: Partial::from_partial( - PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }, - ), - } - .update_as_line_segment(), - ) + let half_edge = PartialHalfEdge { + vertices, + global_form: Partial::from_partial(PartialGlobalEdge { + curve: global_curve, + vertices: global_vertices, + }), + } + .update_as_line_segment(); + + Partial::from_partial(half_edge) }) .collect::>(); @@ -441,16 +437,16 @@ impl ShellBuilder { ), }); - edges.push(Partial::from_partial( - PartialHalfEdge { - vertices: vertices.map(Partial::from_partial), - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_edge.read().curve.clone(), - vertices: global_edge.read().vertices.clone(), - }), - } - .update_as_line_segment(), - )); + let half_edge = PartialHalfEdge { + vertices: vertices.map(Partial::from_partial), + global_form: Partial::from_partial(PartialGlobalEdge { + curve: global_edge.read().curve.clone(), + vertices: global_edge.read().vertices.clone(), + }), + } + .update_as_line_segment(); + + edges.push(Partial::from_partial(half_edge)); } let face = PartialFace { From 4bfdcd6d50162b45dc0be5b8439a373f4251a58f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:03:01 +0100 Subject: [PATCH 08/25] Update `HalfEdgeBuilder` method to latest style --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 14 +++++------ crates/fj-kernel/src/builder/cycle.rs | 6 ++--- crates/fj-kernel/src/builder/edge.rs | 7 +++--- crates/fj-kernel/src/builder/shell.rs | 24 +++++++++---------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 821c8405e..5f1b2c2da 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -305,16 +305,16 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let side_up = PartialHalfEdge { + let mut side_up = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + side_up.update_as_line_segment(); side_up - .update_as_line_segment() .build(&mut services.objects) .insert(&mut services.objects) }; @@ -357,16 +357,16 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let top = PartialHalfEdge { + let mut top = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + top.update_as_line_segment(); - top.update_as_line_segment() - .build(&mut services.objects) + top.build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects) }; @@ -401,16 +401,16 @@ mod tests { vertex.read().surface_form.read().global_form.clone() }); - let side_down = PartialHalfEdge { + let mut side_down = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), }; + side_down.update_as_line_segment(); side_down - .update_as_line_segment() .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 6ed85ea55..776be3bb4 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -151,14 +151,14 @@ impl CycleBuilder for PartialCycle { vertex.read().surface_form.read().global_form.clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve, vertices: global_vertices, }), - } - .update_as_line_segment(); + }; + half_edge.update_as_line_segment(); self.half_edges.push(Partial::from_partial(half_edge)); self diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index ed82e953c..dcc1ad8f8 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -24,7 +24,7 @@ pub trait HalfEdgeBuilder: Sized { ) -> &mut Self; /// Update partial half-edge as a line segment, reusing existing vertices - fn update_as_line_segment(self) -> Self; + fn update_as_line_segment(&mut self) -> &mut Self; } impl HalfEdgeBuilder for PartialHalfEdge { @@ -80,11 +80,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { surface_form.infer_global_position(); } - *self = self.clone().update_as_line_segment(); - self + self.update_as_line_segment() } - fn update_as_line_segment(mut self) -> Self { + fn update_as_line_segment(&mut self) -> &mut Self { let [from, to] = self.vertices.clone(); let [from_surface, to_surface] = [&from, &to].map(|vertex| vertex.read().surface_form.clone()); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 4e965e200..1b30d88de 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -177,14 +177,14 @@ impl ShellBuilder { .clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), - } - .update_as_line_segment(); + }; + half_edge.update_as_line_segment(); Partial::from_partial(half_edge) }) @@ -269,7 +269,7 @@ impl ShellBuilder { .clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial( PartialGlobalEdge { @@ -277,8 +277,8 @@ impl ShellBuilder { curve: curve.global_form, }, ), - } - .update_as_line_segment(); + }; + half_edge.update_as_line_segment(); Partial::from_partial(half_edge) }, @@ -330,14 +330,14 @@ impl ShellBuilder { .clone() }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices, global_form: Partial::from_partial(PartialGlobalEdge { curve: global_curve, vertices: global_vertices, }), - } - .update_as_line_segment(); + }; + half_edge.update_as_line_segment(); Partial::from_partial(half_edge) }) @@ -437,14 +437,14 @@ impl ShellBuilder { ), }); - let half_edge = PartialHalfEdge { + let mut half_edge = PartialHalfEdge { vertices: vertices.map(Partial::from_partial), global_form: Partial::from_partial(PartialGlobalEdge { curve: global_edge.read().curve.clone(), vertices: global_edge.read().vertices.clone(), }), - } - .update_as_line_segment(); + }; + half_edge.update_as_line_segment(); edges.push(Partial::from_partial(half_edge)); } From 2922b7006383555905ba3a6671ada2975afbe68e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:03:54 +0100 Subject: [PATCH 09/25] Update documentation of `HalfEdgeBuilder` --- crates/fj-kernel/src/builder/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index dcc1ad8f8..8e86d742d 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -10,20 +10,20 @@ use super::{CurveBuilder, SurfaceVertexBuilder}; /// Builder API for [`PartialHalfEdge`] pub trait HalfEdgeBuilder: Sized { - /// Update partial half-edge as a circle, from the given radius + /// Update partial half-edge to be a circle, from the given radius fn update_as_circle_from_radius( &mut self, radius: impl Into, ) -> &mut Self; - /// Update partial half-edge as a line segment, from the given points + /// Update partial half-edge to be a line segment, from the given points fn update_as_line_segment_from_points( &mut self, surface: Partial, points: [impl Into>; 2], ) -> &mut Self; - /// Update partial half-edge as a line segment, reusing existing vertices + /// Update partial half-edge to be a line segment fn update_as_line_segment(&mut self) -> &mut Self; } From 0befaefa0bbeda71a46cbc8dfd139e519d3b0121 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:04:19 +0100 Subject: [PATCH 10/25] Remove unused trait bound --- crates/fj-kernel/src/builder/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 8e86d742d..3a20f158b 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -9,7 +9,7 @@ use crate::{ use super::{CurveBuilder, SurfaceVertexBuilder}; /// Builder API for [`PartialHalfEdge`] -pub trait HalfEdgeBuilder: Sized { +pub trait HalfEdgeBuilder { /// Update partial half-edge to be a circle, from the given radius fn update_as_circle_from_radius( &mut self, From 503338d460e6f69dd25959fbd831180c09b3ee3e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:05:43 +0100 Subject: [PATCH 11/25] Refactor --- crates/fj-kernel/src/builder/edge.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 3a20f158b..5bec221de 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -43,9 +43,10 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [a_curve, b_curve] = [Scalar::ZERO, Scalar::TAU].map(|coord| Point::from([coord])); - let [vertex, _] = &mut self.vertices; - - let mut surface_vertex = vertex.write().surface_form.clone(); + let mut surface_vertex = { + let [vertex, _] = &mut self.vertices; + vertex.write().surface_form.clone() + }; surface_vertex.write().position = Some(path.point_from_path_coords(a_curve)); From d10390889a385ff01fdc7d77a1c78f8844d106f7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:07:36 +0100 Subject: [PATCH 12/25] Improve formatting --- crates/fj-kernel/src/builder/edge.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 5bec221de..41b23fd0a 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -72,7 +72,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { ) -> &mut Self { for (vertex, point) in self.vertices.each_mut_ext().zip_ext(points) { let mut vertex = vertex.write(); - vertex.curve.write().surface = surface.clone(); let mut surface_form = vertex.surface_form.write(); From 2d4ca36bec5c6941f28b69383b2198dce460aedb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:08:22 +0100 Subject: [PATCH 13/25] Update variable names --- crates/fj-kernel/src/builder/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 41b23fd0a..7517d189b 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -84,9 +84,9 @@ impl HalfEdgeBuilder for PartialHalfEdge { } fn update_as_line_segment(&mut self) -> &mut Self { - let [from, to] = self.vertices.clone(); + let [back, front] = self.vertices.clone(); let [from_surface, to_surface] = - [&from, &to].map(|vertex| vertex.read().surface_form.clone()); + [&back, &front].map(|vertex| vertex.read().surface_form.clone()); let surface = self.curve().read().surface.clone(); let points = [&from_surface, &to_surface].map(|vertex| { @@ -101,7 +101,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { curve.write().update_as_line_from_points(points); let [back, front] = { - [(from, 0.), (to, 1.)].map(|(mut vertex, position)| { + [(back, 0.), (front, 1.)].map(|(mut vertex, position)| { vertex.write().position = Some([position].into()); vertex.write().curve = self.curve(); vertex From 466d45acab8245d6daa3e9ea6e3a8d6e33ed7c1f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:09:40 +0100 Subject: [PATCH 14/25] Simplify code --- crates/fj-kernel/src/builder/edge.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 7517d189b..af2171a94 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -100,7 +100,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { curve.write().surface = surface; curve.write().update_as_line_from_points(points); - let [back, front] = { + self.vertices = { [(back, 0.), (front, 1.)].map(|(mut vertex, position)| { vertex.write().position = Some([position].into()); vertex.write().curve = self.curve(); @@ -108,8 +108,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { }) }; - self.vertices = [back, front]; - self.global_form.write().curve = curve.read().global_form.clone(); self From 20659196ec93552c7c48ebe0122c7166a88209b1 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:10:36 +0100 Subject: [PATCH 15/25] Refactor --- crates/fj-kernel/src/builder/edge.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index af2171a94..b1e596051 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -100,13 +100,14 @@ impl HalfEdgeBuilder for PartialHalfEdge { curve.write().surface = surface; curve.write().update_as_line_from_points(points); - self.vertices = { - [(back, 0.), (front, 1.)].map(|(mut vertex, position)| { - vertex.write().position = Some([position].into()); - vertex.write().curve = self.curve(); - vertex - }) - }; + self.vertices = + [back, front] + .zip_ext([0., 1.]) + .map(|(mut vertex, position)| { + vertex.write().position = Some([position].into()); + vertex.write().curve = self.curve(); + vertex + }); self.global_form.write().curve = curve.read().global_form.clone(); From 12a8ad36e2346369b76248bbb4d5cb91cb80d4f3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:12:02 +0100 Subject: [PATCH 16/25] Refactor --- crates/fj-kernel/src/builder/edge.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index b1e596051..698fdd090 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -85,12 +85,12 @@ impl HalfEdgeBuilder for PartialHalfEdge { fn update_as_line_segment(&mut self) -> &mut Self { let [back, front] = self.vertices.clone(); - let [from_surface, to_surface] = - [&back, &front].map(|vertex| vertex.read().surface_form.clone()); let surface = self.curve().read().surface.clone(); - let points = [&from_surface, &to_surface].map(|vertex| { + let points = [&back, &front].map(|vertex| { vertex + .read() + .surface_form .read() .position .expect("Can't infer line segment without surface position") From 5d5af31e5d8987705167b8c91abff27b4e05ab59 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:12:33 +0100 Subject: [PATCH 17/25] Make variable name more explicit --- crates/fj-kernel/src/builder/edge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 698fdd090..68ec33a3c 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -87,7 +87,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = self.vertices.clone(); let surface = self.curve().read().surface.clone(); - let points = [&back, &front].map(|vertex| { + let points_surface = [&back, &front].map(|vertex| { vertex .read() .surface_form @@ -98,7 +98,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let mut curve = self.curve(); curve.write().surface = surface; - curve.write().update_as_line_from_points(points); + curve.write().update_as_line_from_points(points_surface); self.vertices = [back, front] From f7e9fc599f360a13b78d3ac03b801647a3069a0b Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:13:20 +0100 Subject: [PATCH 18/25] Refactor --- crates/fj-kernel/src/builder/edge.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index 68ec33a3c..aa6c0cc8f 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -87,7 +87,7 @@ impl HalfEdgeBuilder for PartialHalfEdge { let [back, front] = self.vertices.clone(); let surface = self.curve().read().surface.clone(); - let points_surface = [&back, &front].map(|vertex| { + let points_surface = self.vertices.each_ref_ext().map(|vertex| { vertex .read() .surface_form From 88a700fd34a07384dabe0dfc1bc4a93f5bf065f0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:17:58 +0100 Subject: [PATCH 19/25] Remove redundant code --- crates/fj-kernel/src/builder/edge.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index aa6c0cc8f..f67b4c083 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -86,7 +86,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { fn update_as_line_segment(&mut self) -> &mut Self { let [back, front] = self.vertices.clone(); - let surface = self.curve().read().surface.clone(); let points_surface = self.vertices.each_ref_ext().map(|vertex| { vertex .read() @@ -97,7 +96,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { }); let mut curve = self.curve(); - curve.write().surface = surface; curve.write().update_as_line_from_points(points_surface); self.vertices = From 886061accdc44ff602cd1e6650cca43e9d6c2c58 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:19:36 +0100 Subject: [PATCH 20/25] Simplify loop --- crates/fj-kernel/src/builder/edge.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/builder/edge.rs b/crates/fj-kernel/src/builder/edge.rs index f67b4c083..9df0a0caf 100644 --- a/crates/fj-kernel/src/builder/edge.rs +++ b/crates/fj-kernel/src/builder/edge.rs @@ -84,8 +84,6 @@ impl HalfEdgeBuilder for PartialHalfEdge { } fn update_as_line_segment(&mut self) -> &mut Self { - let [back, front] = self.vertices.clone(); - let points_surface = self.vertices.each_ref_ext().map(|vertex| { vertex .read() @@ -98,14 +96,11 @@ impl HalfEdgeBuilder for PartialHalfEdge { let mut curve = self.curve(); curve.write().update_as_line_from_points(points_surface); - self.vertices = - [back, front] - .zip_ext([0., 1.]) - .map(|(mut vertex, position)| { - vertex.write().position = Some([position].into()); - vertex.write().curve = self.curve(); - vertex - }); + for (vertex, position) in self.vertices.each_mut_ext().zip_ext([0., 1.]) + { + vertex.write().position = Some([position].into()); + vertex.write().curve = curve.clone(); + } self.global_form.write().curve = curve.read().global_form.clone(); From 3f0d1ccfdf0a0fd8a0b66303a9688913e77d2115 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 15:23:43 +0100 Subject: [PATCH 21/25] Simplify some places that create `PartialHalfEdge` --- .../src/algorithms/intersect/curve_edge.rs | 77 ++---------------- crates/fj-kernel/src/algorithms/sweep/edge.rs | 36 +-------- crates/fj-kernel/src/algorithms/sweep/face.rs | 48 ++---------- .../fj-kernel/src/algorithms/sweep/vertex.rs | 25 +----- crates/fj-kernel/src/iter.rs | 25 +----- crates/fj-kernel/src/objects/full/edge.rs | 40 +--------- crates/fj-kernel/src/validate/edge.rs | 78 ++----------------- 7 files changed, 28 insertions(+), 301 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs index fe9f8b4c8..f52f1129d 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_edge.rs @@ -72,18 +72,11 @@ impl CurveEdgeIntersection { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ builder::{CurveBuilder, HalfEdgeBuilder}, - objects::Vertex, - partial::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, - }, + partial::{Partial, PartialCurve, PartialHalfEdge, PartialObject}, services::Services, }; @@ -103,22 +96,7 @@ mod tests { curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( surface, [[1., -1.], [1., 1.]], @@ -151,22 +129,7 @@ mod tests { curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( surface, [[-1., -1.], [-1., 1.]], @@ -199,22 +162,7 @@ mod tests { curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( surface, [[-1., -1.], [1., -1.]], @@ -242,22 +190,7 @@ mod tests { curve.update_as_u_axis(); let curve = curve.build(&mut services.objects); let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( surface, [[-1., 0.], [1., 0.]], diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 5f1b2c2da..7ff88f9af 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -185,8 +185,6 @@ impl Sweep for (Handle, Color) { #[cfg(test)] mod tests { - use std::array; - use fj_interop::{ext::ArrayExt, mesh::Color}; use pretty_assertions::assert_eq; @@ -208,22 +206,7 @@ mod tests { let mut services = Services::new(); let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), @@ -245,22 +228,7 @@ mod tests { ); let bottom = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( surface.clone(), [[0., 0.], [1., 0.]], diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 73c15a410..0d0bb546a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -80,22 +80,14 @@ impl Sweep for Handle { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::{ - ext::{ArrayExt, SliceExt}, - mesh::Color, - }; + use fj_interop::{ext::SliceExt, mesh::Color}; use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, builder::{FaceBuilder, HalfEdgeBuilder}, insert::Insert, - objects::{Sketch, Vertex}, - partial::{ - Partial, PartialFace, PartialGlobalEdge, PartialHalfEdge, - PartialObject, - }, + objects::Sketch, + partial::{Partial, PartialFace, PartialHalfEdge, PartialObject}, services::Services, }; @@ -139,22 +131,7 @@ mod tests { let triangle = TRIANGLE.as_slice(); let side_faces = triangle.array_windows_ext().map(|&[a, b]| { let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), @@ -207,22 +184,7 @@ mod tests { let triangle = TRIANGLE.as_slice(); let side_faces = triangle.array_windows_ext().map(|&[a, b]| { let half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), diff --git a/crates/fj-kernel/src/algorithms/sweep/vertex.rs b/crates/fj-kernel/src/algorithms/sweep/vertex.rs index 4131fd02e..249383eb0 100644 --- a/crates/fj-kernel/src/algorithms/sweep/vertex.rs +++ b/crates/fj-kernel/src/algorithms/sweep/vertex.rs @@ -157,19 +157,15 @@ impl Sweep for Handle { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::ext::ArrayExt; use pretty_assertions::assert_eq; use crate::{ algorithms::sweep::Sweep, builder::{CurveBuilder, HalfEdgeBuilder}, insert::Insert, - objects::Vertex, partial::{ - Partial, PartialCurve, PartialGlobalEdge, PartialHalfEdge, - PartialObject, PartialSurfaceVertex, PartialVertex, + Partial, PartialCurve, PartialHalfEdge, PartialObject, + PartialSurfaceVertex, PartialVertex, }, services::Services, }; @@ -202,22 +198,7 @@ mod tests { .sweep([0., 0., 1.], &mut services.objects); let expected_half_edge = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point(surface), [[0., 0.], [0., 1.]], diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 98038056c..066f49c5b 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -359,10 +359,6 @@ impl Iterator for Iter { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::ext::ArrayExt; - use crate::{ builder::{CurveBuilder, CycleBuilder, FaceBuilder, HalfEdgeBuilder}, insert::Insert, @@ -371,8 +367,8 @@ mod tests { SurfaceVertex, Vertex, }, partial::{ - Partial, PartialCurve, PartialCycle, PartialFace, - PartialGlobalEdge, PartialHalfEdge, PartialObject, + Partial, PartialCurve, PartialCycle, PartialFace, PartialHalfEdge, + PartialObject, }, services::Services, }; @@ -503,22 +499,7 @@ mod tests { let mut services = Services::new(); let object = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), diff --git a/crates/fj-kernel/src/objects/full/edge.rs b/crates/fj-kernel/src/objects/full/edge.rs index 90f6cb332..c79b0a539 100644 --- a/crates/fj-kernel/src/objects/full/edge.rs +++ b/crates/fj-kernel/src/objects/full/edge.rs @@ -144,15 +144,11 @@ impl VerticesInNormalizedOrder { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::ext::ArrayExt; use pretty_assertions::assert_eq; use crate::{ builder::HalfEdgeBuilder, - objects::Vertex, - partial::{Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject}, + partial::{Partial, PartialHalfEdge, PartialObject}, services::Services, }; @@ -168,44 +164,14 @@ mod tests { let b = [1., 0.]; let a_to_b = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge .update_as_line_segment_from_points(surface.clone(), [a, b]); half_edge.build(&mut services.objects) }; let b_to_a = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points(surface, [b, a]); half_edge.build(&mut services.objects) diff --git a/crates/fj-kernel/src/validate/edge.rs b/crates/fj-kernel/src/validate/edge.rs index dc43c0cbf..7e79d4ef0 100644 --- a/crates/fj-kernel/src/validate/edge.rs +++ b/crates/fj-kernel/src/validate/edge.rs @@ -198,17 +198,13 @@ impl HalfEdgeValidationError { #[cfg(test)] mod tests { - use std::array; - - use fj_interop::ext::ArrayExt; - use crate::{ builder::HalfEdgeBuilder, insert::Insert, - objects::{GlobalCurve, HalfEdge, Vertex}, + objects::{GlobalCurve, HalfEdge}, partial::{ - Partial, PartialGlobalEdge, PartialHalfEdge, PartialObject, - PartialSurfaceVertex, PartialVertex, + Partial, PartialHalfEdge, PartialObject, PartialSurfaceVertex, + PartialVertex, }, services::Services, validate::Validate, @@ -219,22 +215,7 @@ mod tests { let mut services = Services::new(); let valid = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), @@ -268,22 +249,7 @@ mod tests { let mut services = Services::new(); let valid = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), @@ -311,22 +277,7 @@ mod tests { let mut services = Services::new(); let valid = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), @@ -361,22 +312,7 @@ mod tests { let mut services = Services::new(); let valid = { - let vertices = array::from_fn(|_| Partial::::new()); - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); - - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; + let mut half_edge = PartialHalfEdge::default(); half_edge.update_as_line_segment_from_points( Partial::from_full_entry_point( services.objects.surfaces.xy_plane(), From fabf11bf90ace0c5a8aa56b18fe74801cedc26b9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 16:08:10 +0100 Subject: [PATCH 22/25] Modify test not to rely on intermediate `build`s --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 101 ++++++++++-------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 7ff88f9af..dad839b01 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -192,11 +192,11 @@ mod tests { algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::{Cycle, Vertex}, + objects::Vertex, partial::{ - Partial, PartialCurve, PartialFace, PartialGlobalEdge, - PartialHalfEdge, PartialObject, PartialSurfaceVertex, - PartialVertex, + Partial, PartialCurve, PartialCycle, PartialFace, + PartialGlobalEdge, PartialHalfEdge, PartialObject, + PartialSurfaceVertex, PartialVertex, }, services::Services, }; @@ -235,21 +235,23 @@ mod tests { ); half_edge - .build(&mut services.objects) - .insert(&mut services.objects) }; let side_up = { let vertices = [ PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - bottom.front().surface_form().surface().clone(), - ), + surface: bottom.vertices[1] + .read() + .surface_form + .read() + .surface + .clone(), ..Default::default() }), - surface_form: Partial::from_full_entry_point( - bottom.front().surface_form().clone(), - ), + surface_form: bottom.vertices[1] + .read() + .surface_form + .clone(), ..Default::default() }, PartialVertex { @@ -283,20 +285,17 @@ mod tests { side_up.update_as_line_segment(); side_up - .build(&mut services.objects) - .insert(&mut services.objects) }; let top = { let vertices = [ PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - side_up - .front() - .surface_form() - .surface() - .clone(), - ), + surface: side_up.vertices[1] + .read() + .surface_form + .read() + .surface + .clone(), ..Default::default() }), surface_form: Partial::from_partial( @@ -309,9 +308,10 @@ mod tests { ..Default::default() }, PartialVertex { - surface_form: Partial::from_full_entry_point( - side_up.front().surface_form().clone(), - ), + surface_form: side_up.vertices[1] + .read() + .surface_form + .clone(), ..Default::default() }, ] @@ -334,28 +334,37 @@ mod tests { }; top.update_as_line_segment(); - top.build(&mut services.objects) - .insert(&mut services.objects) - .reverse(&mut services.objects) + Partial::from_full_entry_point( + top.build(&mut services.objects) + .insert(&mut services.objects) + .reverse(&mut services.objects), + ) + .read() + .clone() }; let side_down = { let vertices = [ PartialVertex { curve: Partial::from_partial(PartialCurve { - surface: Partial::from_full_entry_point( - bottom.back().surface_form().surface().clone(), - ), + surface: bottom.vertices[0] + .read() + .surface_form + .read() + .surface + .clone(), ..Default::default() }), - surface_form: Partial::from_full_entry_point( - bottom.back().surface_form().clone(), - ), + surface_form: bottom.vertices[0] + .read() + .surface_form + .clone(), ..Default::default() }, PartialVertex { - surface_form: Partial::from_full_entry_point( - top.front().surface_form().clone(), - ), + surface_form: top.vertices[1] + .read() + .surface_form + .clone(), ..Default::default() }, ] @@ -378,17 +387,23 @@ mod tests { }; side_down.update_as_line_segment(); - side_down - .build(&mut services.objects) - .insert(&mut services.objects) - .reverse(&mut services.objects) + Partial::from_full_entry_point( + side_down + .build(&mut services.objects) + .insert(&mut services.objects) + .reverse(&mut services.objects), + ) + .read() + .clone() }; - let cycle = Cycle::new([bottom, side_up, top, side_down]) - .insert(&mut services.objects); + let mut cycle = PartialCycle::default(); + cycle.half_edges.extend( + [bottom, side_up, top, side_down].map(Partial::from_partial), + ); let face = PartialFace { - exterior: Partial::from_full_entry_point(cycle), + exterior: Partial::from_partial(cycle), ..Default::default() }; face.build(&mut services.objects) From ed6b2f2db8f21eb1d9d292aaacff6b52c674af81 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 16:17:58 +0100 Subject: [PATCH 23/25] Simplify half-edge construction in test --- crates/fj-kernel/src/algorithms/sweep/edge.rs | 182 +++++------------- 1 file changed, 48 insertions(+), 134 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index dad839b01..df9e2c08a 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -185,18 +185,15 @@ impl Sweep for (Handle, Color) { #[cfg(test)] mod tests { - use fj_interop::{ext::ArrayExt, mesh::Color}; + use fj_interop::mesh::Color; use pretty_assertions::assert_eq; use crate::{ algorithms::{reverse::Reverse, sweep::Sweep}, builder::HalfEdgeBuilder, insert::Insert, - objects::Vertex, partial::{ - Partial, PartialCurve, PartialCycle, PartialFace, - PartialGlobalEdge, PartialHalfEdge, PartialObject, - PartialSurfaceVertex, PartialVertex, + Partial, PartialCycle, PartialFace, PartialHalfEdge, PartialObject, }, services::Services, }; @@ -237,101 +234,45 @@ mod tests { half_edge }; let side_up = { - let vertices = [ - PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: bottom.vertices[1] - .read() - .surface_form - .read() - .surface - .clone(), - ..Default::default() - }), - surface_form: bottom.vertices[1] - .read() - .surface_form - .clone(), - ..Default::default() - }, - PartialVertex { - surface_form: Partial::from_partial( - PartialSurfaceVertex { - position: Some([1., 1.].into()), - surface: surface.clone(), - ..Default::default() - }, - ), - ..Default::default() - }, - ] - .map(Partial::::from_partial); - - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); + let mut side_up = PartialHalfEdge::default(); + side_up.curve().write().surface = surface.clone(); + + { + let [back, front] = &mut side_up.vertices; + + back.write().surface_form = + bottom.vertices[1].read().surface_form.clone(); + side_up.global_form.write().vertices[0] = + back.read().surface_form.read().global_form.clone(); + + let mut front = front.write(); + let mut front = front.surface_form.write(); + front.position = Some([1., 1.].into()); + front.surface = surface.clone(); + } - let mut side_up = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; side_up.update_as_line_segment(); side_up }; let top = { - let vertices = [ - PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: side_up.vertices[1] - .read() - .surface_form - .read() - .surface - .clone(), - ..Default::default() - }), - surface_form: Partial::from_partial( - PartialSurfaceVertex { - position: Some([0., 1.].into()), - surface, - ..Default::default() - }, - ), - ..Default::default() - }, - PartialVertex { - surface_form: side_up.vertices[1] - .read() - .surface_form - .clone(), - ..Default::default() - }, - ] - .map(Partial::::from_partial); - - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); + let mut top = PartialHalfEdge::default(); + top.curve().write().surface = surface.clone(); + + { + let [back, front] = &mut top.vertices; + + let mut back = back.write(); + let mut back = back.surface_form.write(); + back.position = Some([0., 1.].into()); + back.surface = surface.clone(); + + front.write().surface_form = + side_up.vertices[1].read().surface_form.clone(); + top.global_form.write().vertices[1] = + front.read().surface_form.read().global_form.clone(); + } - let mut top = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; top.update_as_line_segment(); Partial::from_full_entry_point( @@ -343,48 +284,21 @@ mod tests { .clone() }; let side_down = { - let vertices = [ - PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: bottom.vertices[0] - .read() - .surface_form - .read() - .surface - .clone(), - ..Default::default() - }), - surface_form: bottom.vertices[0] - .read() - .surface_form - .clone(), - ..Default::default() - }, - PartialVertex { - surface_form: top.vertices[1] - .read() - .surface_form - .clone(), - ..Default::default() - }, - ] - .map(Partial::::from_partial); - - let global_curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); + let mut side_down = PartialHalfEdge::default(); + side_down.curve().write().surface = surface; + + let [back, front] = &mut side_down.vertices; + + back.write().surface_form = + bottom.vertices[0].read().surface_form.clone(); + side_down.global_form.write().vertices[0] = + back.read().surface_form.read().global_form.clone(); + + front.write().surface_form = + top.vertices[1].read().surface_form.clone(); + side_down.global_form.write().vertices[1] = + front.read().surface_form.read().global_form.clone(); - let mut side_down = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: global_curve, - vertices: global_vertices, - }), - }; side_down.update_as_line_segment(); Partial::from_full_entry_point( From 55bef2abfea3ff9386d447f60d2cab2d1420c224 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 16:55:02 +0100 Subject: [PATCH 24/25] Simplify half-edge construction in `CycleBuilder` --- crates/fj-kernel/src/builder/cycle.rs | 66 ++++++++++----------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 776be3bb4..8b69d3d53 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -2,7 +2,7 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Curve, Surface, SurfaceVertex, Vertex}, + objects::{Surface, SurfaceVertex, Vertex}, partial::{ Partial, PartialCurve, PartialCycle, PartialGlobalEdge, PartialHalfEdge, PartialSurfaceVertex, PartialVertex, @@ -10,7 +10,7 @@ use crate::{ storage::Handle, }; -use super::{CurveBuilder, HalfEdgeBuilder}; +use super::HalfEdgeBuilder; /// Builder API for [`PartialCycle`] pub trait CycleBuilder { @@ -54,47 +54,29 @@ impl CycleBuilder for PartialCycle { if let Some(vertex_prev) = previous { let surface = vertex_prev.read().surface.clone(); - let [position_prev, position_next] = - [&vertex_prev, &vertex_next].map(|vertex| { - vertex - .read() - .position - .expect("Need surface position to extend cycle") - }); - previous = Some(vertex_next.clone()); - - let mut curve: Partial = - Partial::from_partial(PartialCurve { - surface: surface.clone(), - ..Default::default() - }); - curve - .write() - .update_as_line_from_points([position_prev, position_next]); - - let vertices = [(0., vertex_prev), (1., vertex_next)].map( - |(position, surface_form)| { - Partial::from_partial(PartialVertex { - position: Some([position].into()), - curve: curve.clone(), - surface_form, - }) - }, - ); - - let global_vertices = - vertices.each_ref_ext().map(|vertex: &Partial| { - vertex.read().surface_form.read().global_form.clone() - }); - - half_edges.push(Partial::from_partial(PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve: curve.read().global_form.clone(), - vertices: global_vertices, - }), - })); + let surface_vertices = [vertex_prev, vertex_next]; + + let mut half_edge = PartialHalfEdge::default(); + half_edge.curve().write().surface = surface; + + { + let global_vertices = + &mut half_edge.global_form.write().vertices; + + for ((vertex, surface_form), global_form) in half_edge + .vertices + .each_mut_ext() + .zip_ext(surface_vertices) + .zip_ext(global_vertices.each_mut_ext()) + { + *global_form = surface_form.read().global_form.clone(); + vertex.write().surface_form = surface_form; + } + } + + half_edge.update_as_line_segment(); + half_edges.push(Partial::from_partial(half_edge)); continue; } From 25d22b3d73eda03045692ae8e66d2d7156ff0fa3 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Dec 2022 16:55:02 +0100 Subject: [PATCH 25/25] Simplify half-edge construction in `CycleBuilder` --- crates/fj-kernel/src/builder/cycle.rs | 57 ++++++++++++--------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 8b69d3d53..46e946dcd 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -2,11 +2,8 @@ use fj_interop::ext::ArrayExt; use fj_math::Point; use crate::{ - objects::{Surface, SurfaceVertex, Vertex}, - partial::{ - Partial, PartialCurve, PartialCycle, PartialGlobalEdge, - PartialHalfEdge, PartialSurfaceVertex, PartialVertex, - }, + objects::{Surface, SurfaceVertex}, + partial::{Partial, PartialCycle, PartialHalfEdge, PartialSurfaceVertex}, storage::Handle, }; @@ -107,39 +104,37 @@ impl CycleBuilder for PartialCycle { let last = self.half_edges.last(); let vertices = [first, last].map(|option| { - option.map(|half_edge| half_edge.read().vertices.clone()) + option.map(|half_edge| { + half_edge + .read() + .vertices + .each_ref_ext() + .map(|vertex| vertex.read().surface_form.clone()) + }) }); let [Some([first, _]), Some([_, last])] = vertices else { return self; }; - let surface = self.surface().expect("Need surface to close cycle"); - let vertices = [last, first].map(|vertex| { - Partial::::from_partial(PartialVertex { - curve: Partial::from_partial(PartialCurve { - surface: surface.clone(), - ..Default::default() - }), - surface_form: vertex.read().surface_form.clone(), - ..Default::default() - }) - }); - let curve = { - let [vertex, _] = &vertices; - vertex.read().curve.read().global_form.clone() - }; - let global_vertices = vertices.each_ref_ext().map(|vertex| { - vertex.read().surface_form.read().global_form.clone() - }); + let mut half_edge = PartialHalfEdge::default(); + half_edge.curve().write().surface = + self.surface().expect("Need surface to close cycle"); + + { + let global_vertices = &mut half_edge.global_form.write().vertices; + + for ((vertex, surface_form), global_form) in half_edge + .vertices + .each_mut_ext() + .zip_ext([last, first]) + .zip_ext(global_vertices.each_mut_ext()) + { + *global_form = surface_form.read().global_form.clone(); + vertex.write().surface_form = surface_form; + } + } - let mut half_edge = PartialHalfEdge { - vertices, - global_form: Partial::from_partial(PartialGlobalEdge { - curve, - vertices: global_vertices, - }), - }; half_edge.update_as_line_segment(); self.half_edges.push(Partial::from_partial(half_edge));