From a18b372f589bc05cf079c09f8d72c0f5ae2ff8eb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 12:47:14 +0100 Subject: [PATCH 1/7] Update method name I believe the new one is a bit clearer. --- .../fj-kernel/src/algorithms/intersect/curve_face.rs | 2 +- crates/fj-kernel/src/algorithms/triangulate/mod.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 4 ++-- crates/fj-kernel/src/validate/face.rs | 10 ++-------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 67227a757..ab60f1a88 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -188,7 +188,7 @@ mod tests { let face = { let mut face = PartialFace::default(); face.with_exterior_polygon_from_points(surface.clone(), exterior); - face.with_interior_polygon_from_points(surface, interior); + face.add_interior_polygon(surface, interior); face.build(&mut services.objects) }; diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 6b6e8528d..38a5a3c5a 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -135,7 +135,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); face.with_exterior_polygon_from_points(surface.clone(), [a, b, c, d]); - face.with_interior_polygon_from_points(surface.clone(), [e, f, g, h]); + face.add_interior_polygon(surface.clone(), [e, f, g, h]); let face = face .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 116d829f2..3538a6835 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -17,7 +17,7 @@ pub trait FaceBuilder { ); /// Update the [`PartialFace`] with an interior polygon - fn with_interior_polygon_from_points( + fn add_interior_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, @@ -34,7 +34,7 @@ impl FaceBuilder for PartialFace { self.exterior = Partial::from_partial(cycle); } - fn with_interior_polygon_from_points( + fn add_interior_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 8582a156f..19ef84d01 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -125,10 +125,7 @@ mod tests { surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], ); - face.with_interior_polygon_from_points( - surface, - [[1., 1.], [1., 2.], [2., 1.]], - ); + face.add_interior_polygon(surface, [[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) }; @@ -161,10 +158,7 @@ mod tests { surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], ); - face.with_interior_polygon_from_points( - surface, - [[1., 1.], [1., 2.], [2., 1.]], - ); + face.add_interior_polygon(surface, [[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) }; let invalid = { From 69ed3e06d1ef83997b4c652651dafebe615b2e2e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 12:48:19 +0100 Subject: [PATCH 2/7] Update method name The new name is shorter, as well as more explicit about the fact that it updates the existing exterior. --- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/intersect/face_face.rs | 4 ++-- .../src/algorithms/intersect/face_point.rs | 16 ++++++++-------- .../src/algorithms/intersect/ray_face.rs | 14 +++++++------- crates/fj-kernel/src/algorithms/sweep/face.rs | 8 ++++---- .../fj-kernel/src/algorithms/triangulate/mod.rs | 9 +++------ crates/fj-kernel/src/builder/face.rs | 4 ++-- crates/fj-kernel/src/builder/shell.rs | 2 +- crates/fj-kernel/src/builder/sketch.rs | 2 +- crates/fj-kernel/src/iter.rs | 4 ++-- crates/fj-kernel/src/validate/face.rs | 4 ++-- crates/fj-operations/src/sketch.rs | 2 +- 12 files changed, 34 insertions(+), 37 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index ab60f1a88..5bdc07ff8 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -187,7 +187,7 @@ mod tests { let face = { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface.clone(), exterior); + face.update_exterior_as_polygon(surface.clone(), exterior); face.add_interior_polygon(surface, interior); face.build(&mut services.objects) diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index 4e1367b81..2a619779b 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -94,7 +94,7 @@ mod tests { ] .map(|surface| { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface, points); + face.update_exterior_as_polygon(surface, points); face.build(&mut services.objects) }); @@ -122,7 +122,7 @@ mod tests { ]; let [a, b] = surfaces.clone().map(|surface| { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface, points); + face.update_exterior_as_polygon(surface, points); face.build(&mut services.objects) }); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 630dd81bc..1ab7f6879 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -149,7 +149,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [1., 1.], [0., 2.]], ); @@ -168,7 +168,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [2., 1.], [0., 2.]], ); @@ -190,7 +190,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[4., 2.], [0., 4.], [0., 0.]], ); @@ -212,7 +212,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [2., 1.], [3., 0.], [3., 4.]], ); @@ -234,7 +234,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [2., 1.], [3., 1.], [0., 2.]], ); @@ -256,7 +256,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [2., 1.], [3., 1.], [4., 0.], [4., 5.]], ); @@ -278,7 +278,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [2., 0.], [0., 1.]], ); @@ -309,7 +309,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [1., 0.], [0., 1.]], ); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 76907a400..7d1e22a8d 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -167,7 +167,7 @@ mod tests { let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -187,7 +187,7 @@ mod tests { let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -210,7 +210,7 @@ mod tests { let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -230,7 +230,7 @@ mod tests { let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -261,7 +261,7 @@ mod tests { let surface = services.objects.surfaces.yz_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -290,7 +290,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); @@ -312,7 +312,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-1., -1.], [1., -1.], [1., 1.], [-1., 1.]], ); diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 340b882fc..815f05b97 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -113,13 +113,13 @@ mod tests { .sweep(UP, &mut services.objects); let mut bottom = PartialFace::default(); - bottom.with_exterior_polygon_from_points(surface.clone(), TRIANGLE); + bottom.update_exterior_as_polygon(surface.clone(), TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); - top.with_exterior_polygon_from_points( + top.update_exterior_as_polygon( surface.translate(UP, &mut services.objects), TRIANGLE, ); @@ -164,7 +164,7 @@ mod tests { .sweep(DOWN, &mut services.objects); let mut bottom = PartialFace::default(); - bottom.with_exterior_polygon_from_points( + bottom.update_exterior_as_polygon( surface.clone().translate(DOWN, &mut services.objects), TRIANGLE, ); @@ -173,7 +173,7 @@ mod tests { .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); - top.with_exterior_polygon_from_points(surface, TRIANGLE); + top.update_exterior_as_polygon(surface, TRIANGLE); let top = top .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 38a5a3c5a..6779e26c7 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -98,7 +98,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface, [a, b, c, d]); + face.update_exterior_as_polygon(surface, [a, b, c, d]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -134,7 +134,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface.clone(), [a, b, c, d]); + face.update_exterior_as_polygon(surface.clone(), [a, b, c, d]); face.add_interior_polygon(surface.clone(), [e, f, g, h]); let face = face .build(&mut services.objects) @@ -193,10 +193,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( - surface.clone(), - [a, b, c, d, e], - ); + face.update_exterior_as_polygon(surface.clone(), [a, b, c, d, e]); let face = face .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 3538a6835..0a702d743 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -10,7 +10,7 @@ use super::CycleBuilder; /// Builder API for [`PartialFace`] pub trait FaceBuilder { /// Update the [`PartialFace`] with an exterior polygon - fn with_exterior_polygon_from_points( + fn update_exterior_as_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, @@ -25,7 +25,7 @@ pub trait FaceBuilder { } impl FaceBuilder for PartialFace { - fn with_exterior_polygon_from_points( + fn update_exterior_as_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index b3bc62629..75bc79f49 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -42,7 +42,7 @@ impl ShellBuilder for PartialShell { objects.surfaces.xy_plane().translate([Z, Z, -h], objects); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[-h, -h], [h, -h], [h, h], [-h, h]], ); diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 1deaee09a..c100f0d6f 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -24,7 +24,7 @@ impl SketchBuilder for PartialSketch { points: impl IntoIterator>>, ) { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface, points); + face.update_exterior_as_polygon(surface, points); self.faces.extend([Partial::from_partial(face)]); } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 0edb14bf2..ea21c9499 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -436,7 +436,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut object = PartialFace::default(); - object.with_exterior_polygon_from_points( + object.update_exterior_as_polygon( surface, [[0., 0.], [1., 0.], [0., 1.]], ); @@ -555,7 +555,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface, [[0., 0.], [1., 0.], [0., 1.]], ); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 19ef84d01..94ff4ffb5 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -121,7 +121,7 @@ mod tests { let valid = { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], ); @@ -154,7 +154,7 @@ mod tests { let valid = { let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points( + face.update_exterior_as_polygon( surface.clone(), [[0., 0.], [3., 0.], [0., 3.]], ); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 742d58dd1..c34e44682 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -61,7 +61,7 @@ impl Shape for fj::Sketch { .map(Point::from); let mut face = PartialFace::default(); - face.with_exterior_polygon_from_points(surface, points); + face.update_exterior_as_polygon(surface, points); face.color = Some(Color(self.color())); face From 0bedf10436df0d3ee6944737f6ff530c0497cf6a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 13:01:02 +0100 Subject: [PATCH 3/7] Make `CycleBuilder` method update existing cycle --- crates/fj-kernel/src/builder/cycle.rs | 15 +++++++-------- crates/fj-kernel/src/builder/face.rs | 8 ++++++-- crates/fj-kernel/src/iter.rs | 6 ++---- crates/fj-kernel/src/validate/cycle.rs | 3 ++- crates/fj-kernel/src/validate/face.rs | 3 ++- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 2e2a36864..39ee25184 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -10,10 +10,12 @@ use super::HalfEdgeBuilder; /// Builder API for [`PartialCycle`] pub trait CycleBuilder { /// Create a cycle as a polygonal chain from the provided points + #[allow(clippy::wrong_self_convention)] fn from_poly_chain( + &mut self, surface: impl Into>, points: impl IntoIterator>>, - ) -> Self; + ); /// Add a new half-edge to the cycle /// @@ -29,15 +31,14 @@ pub trait CycleBuilder { impl CycleBuilder for PartialCycle { fn from_poly_chain( + &mut self, surface: impl Into>, points: impl IntoIterator>>, - ) -> Self { + ) { let surface = surface.into(); - let mut cycle = PartialCycle::default(); - for point in points.into_iter().map(Into::into) { - let mut half_edge = cycle.add_half_edge(); + let mut half_edge = self.add_half_edge(); let mut half_edge = half_edge.write(); half_edge.curve().write().surface = surface.clone(); @@ -49,11 +50,9 @@ impl CycleBuilder for PartialCycle { back_surface.surface = surface.clone(); } - for half_edge in &mut cycle.half_edges { + for half_edge in &mut self.half_edges { half_edge.write().update_as_line_segment(); } - - cycle } fn add_half_edge(&mut self) -> Partial { diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 0a702d743..58deb61c9 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -30,7 +30,9 @@ impl FaceBuilder for PartialFace { surface: impl Into>, points: impl IntoIterator>>, ) { - let cycle = PartialCycle::from_poly_chain(surface, points); + let mut cycle = PartialCycle::default(); + cycle.from_poly_chain(surface, points); + self.exterior = Partial::from_partial(cycle); } @@ -39,7 +41,9 @@ impl FaceBuilder for PartialFace { surface: impl Into>, points: impl IntoIterator>>, ) { - let cycle = PartialCycle::from_poly_chain(surface, points); + let mut cycle = PartialCycle::default(); + cycle.from_poly_chain(surface, points); + self.interiors = vec![Partial::from_partial(cycle)]; } } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index ea21c9499..5f7918489 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -408,10 +408,8 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let object = { - let cycle = PartialCycle::from_poly_chain( - surface, - [[0., 0.], [1., 0.], [0., 1.]], - ); + let mut cycle = PartialCycle::default(); + cycle.from_poly_chain(surface, [[0., 0.], [1., 0.], [0., 1.]]); cycle .build(&mut services.objects) .insert(&mut services.objects) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index a2d682db9..e6740a9e5 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -78,7 +78,8 @@ mod tests { let mut services = Services::new(); let valid = { - let cycle = PartialCycle::from_poly_chain( + let mut cycle = PartialCycle::default(); + cycle.from_poly_chain( services.objects.surfaces.xy_plane(), [[0., 0.], [1., 0.], [0., 1.]], ); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 94ff4ffb5..600000894 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -130,7 +130,8 @@ mod tests { face.build(&mut services.objects) }; let invalid = { - let cycle = PartialCycle::from_poly_chain( + let mut cycle = PartialCycle::default(); + cycle.from_poly_chain( services.objects.surfaces.xz_plane(), [[1., 1.], [1., 2.], [2., 1.]], ); From 90e200823c502be036c197e4c15c95f240cb3853 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 13:02:13 +0100 Subject: [PATCH 4/7] Update method name --- crates/fj-kernel/src/builder/cycle.rs | 5 ++--- crates/fj-kernel/src/builder/face.rs | 4 ++-- crates/fj-kernel/src/iter.rs | 2 +- crates/fj-kernel/src/validate/cycle.rs | 2 +- crates/fj-kernel/src/validate/face.rs | 2 +- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 39ee25184..3ac2a6cc3 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -10,8 +10,7 @@ use super::HalfEdgeBuilder; /// Builder API for [`PartialCycle`] pub trait CycleBuilder { /// Create a cycle as a polygonal chain from the provided points - #[allow(clippy::wrong_self_convention)] - fn from_poly_chain( + fn update_as_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, @@ -30,7 +29,7 @@ pub trait CycleBuilder { } impl CycleBuilder for PartialCycle { - fn from_poly_chain( + fn update_as_polygon( &mut self, surface: impl Into>, points: impl IntoIterator>>, diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 58deb61c9..8e4cd8967 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -31,7 +31,7 @@ impl FaceBuilder for PartialFace { points: impl IntoIterator>>, ) { let mut cycle = PartialCycle::default(); - cycle.from_poly_chain(surface, points); + cycle.update_as_polygon(surface, points); self.exterior = Partial::from_partial(cycle); } @@ -42,7 +42,7 @@ impl FaceBuilder for PartialFace { points: impl IntoIterator>>, ) { let mut cycle = PartialCycle::default(); - cycle.from_poly_chain(surface, points); + cycle.update_as_polygon(surface, points); self.interiors = vec![Partial::from_partial(cycle)]; } diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 5f7918489..85bbc4bce 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -409,7 +409,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let object = { let mut cycle = PartialCycle::default(); - cycle.from_poly_chain(surface, [[0., 0.], [1., 0.], [0., 1.]]); + cycle.update_as_polygon(surface, [[0., 0.], [1., 0.], [0., 1.]]); cycle .build(&mut services.objects) .insert(&mut services.objects) diff --git a/crates/fj-kernel/src/validate/cycle.rs b/crates/fj-kernel/src/validate/cycle.rs index e6740a9e5..8582097fa 100644 --- a/crates/fj-kernel/src/validate/cycle.rs +++ b/crates/fj-kernel/src/validate/cycle.rs @@ -79,7 +79,7 @@ mod tests { let valid = { let mut cycle = PartialCycle::default(); - cycle.from_poly_chain( + cycle.update_as_polygon( services.objects.surfaces.xy_plane(), [[0., 0.], [1., 0.], [0., 1.]], ); diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 600000894..a6f04e49a 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -131,7 +131,7 @@ mod tests { }; let invalid = { let mut cycle = PartialCycle::default(); - cycle.from_poly_chain( + cycle.update_as_polygon( services.objects.surfaces.xz_plane(), [[1., 1.], [1., 2.], [2., 1.]], ); From b20a75e9f4684171a3a1cdcb13066898ce37e87a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 13:06:30 +0100 Subject: [PATCH 5/7] Return created objects from `CycleBuilder` method --- crates/fj-kernel/src/builder/cycle.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 3ac2a6cc3..5e7a44e54 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -14,7 +14,7 @@ pub trait CycleBuilder { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ); + ) -> Vec>; /// Add a new half-edge to the cycle /// @@ -33,25 +33,34 @@ impl CycleBuilder for PartialCycle { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ) { + ) -> Vec> { let surface = surface.into(); + let mut half_edges = Vec::new(); + for point in points.into_iter().map(Into::into) { let mut half_edge = self.add_half_edge(); - let mut half_edge = half_edge.write(); - half_edge.curve().write().surface = surface.clone(); + { + let mut half_edge = half_edge.write(); + + half_edge.curve().write().surface = surface.clone(); - let mut back = half_edge.back_mut().write(); - let mut back_surface = back.surface_form.write(); + let mut back = half_edge.back_mut().write(); + let mut back_surface = back.surface_form.write(); - back_surface.position = Some(point); - back_surface.surface = surface.clone(); + back_surface.position = Some(point); + back_surface.surface = surface.clone(); + } + + half_edges.push(half_edge); } for half_edge in &mut self.half_edges { half_edge.write().update_as_line_segment(); } + + half_edges } fn add_half_edge(&mut self) -> Partial { From 558324cc37ec66724826120e76c109fa9cbb7280 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 13:08:37 +0100 Subject: [PATCH 6/7] Fix `FaceBuilder::add_interior_polygon` It didn't actually add one, but replaced all existing ones. --- crates/fj-kernel/src/builder/face.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 8e4cd8967..0fabd85b1 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -44,6 +44,6 @@ impl FaceBuilder for PartialFace { let mut cycle = PartialCycle::default(); cycle.update_as_polygon(surface, points); - self.interiors = vec![Partial::from_partial(cycle)]; + self.interiors.push(Partial::from_partial(cycle)); } } From aa8b7e83dc12d783c025121eabd29f6e91601320 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 15 Dec 2022 13:09:48 +0100 Subject: [PATCH 7/7] Return created objects from `FaceBuilder` method --- crates/fj-kernel/src/builder/face.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 0fabd85b1..4c48ca503 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - objects::Surface, + objects::{HalfEdge, Surface}, partial::{Partial, PartialCycle, PartialFace}, }; @@ -14,7 +14,7 @@ pub trait FaceBuilder { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ); + ) -> Vec>; /// Update the [`PartialFace`] with an interior polygon fn add_interior_polygon( @@ -29,11 +29,13 @@ impl FaceBuilder for PartialFace { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ) { + ) -> Vec> { let mut cycle = PartialCycle::default(); - cycle.update_as_polygon(surface, points); + let half_edges = cycle.update_as_polygon(surface, points); self.exterior = Partial::from_partial(cycle); + + half_edges } fn add_interior_polygon(