From 0d0bfdbbc91b6d72d2a0f714edcee36d21985c29 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 Jan 2023 12:57:46 +0100 Subject: [PATCH 1/7] Refactor --- crates/fj-kernel/src/builder/sketch.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 890804b2a..9579abe9f 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -27,6 +27,7 @@ impl SketchBuilder for PartialSketch { face.exterior.write().surface = surface.into(); face.exterior.write().update_as_polygon_from_points(points); - self.faces.extend([Partial::from_partial(face)]); + let face = Partial::from_partial(face); + self.faces.extend([face]); } } From 8950ef2bbbf35421563195218352e297fbe565ba Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 Jan 2023 12:58:23 +0100 Subject: [PATCH 2/7] Return added face from `SketchBuilder` method --- crates/fj-kernel/src/builder/sketch.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 9579abe9f..8b3ef040c 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -1,7 +1,7 @@ use fj_math::Point; use crate::{ - objects::Surface, + objects::{Face, Surface}, partial::{Partial, PartialFace, PartialSketch}, }; @@ -14,7 +14,7 @@ pub trait SketchBuilder { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ); + ) -> Partial; } impl SketchBuilder for PartialSketch { @@ -22,12 +22,14 @@ impl SketchBuilder for PartialSketch { &mut self, surface: impl Into>, points: impl IntoIterator>>, - ) { + ) -> Partial { let mut face = PartialFace::default(); face.exterior.write().surface = surface.into(); face.exterior.write().update_as_polygon_from_points(points); let face = Partial::from_partial(face); - self.faces.extend([face]); + self.faces.extend([face.clone()]); + + face } } From 46859d2551f6af6109512aeca1b7e7bd48b8d3f5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 10 Jan 2023 13:11:32 +0100 Subject: [PATCH 3/7] Refactor --- crates/fj-kernel/src/algorithms/sweep/face.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 7f54e4ff4..a9a6e85fb 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -107,8 +107,11 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let mut sketch = PartialSketch::default(); - sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + let sketch = { + let mut sketch = PartialSketch::default(); + sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + sketch + }; let solid = sketch .build(&mut services.objects) .insert(&mut services.objects) @@ -161,8 +164,11 @@ mod tests { let mut services = Services::new(); let surface = services.objects.surfaces.xy_plane(); - let mut sketch = PartialSketch::default(); - sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + let sketch = { + let mut sketch = PartialSketch::default(); + sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + sketch + }; let solid = sketch .build(&mut services.objects) .insert(&mut services.objects) From c07f341033b36e878c3164d10b3e7955316c7954 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 Jan 2023 12:05:18 +0100 Subject: [PATCH 4/7] Simplify `SketchBuilder` method --- crates/fj-kernel/src/algorithms/sweep/face.rs | 16 ++++++++++++++-- crates/fj-kernel/src/builder/sketch.rs | 11 ++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index a9a6e85fb..f27045bd5 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -109,7 +109,13 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let sketch = { let mut sketch = PartialSketch::default(); - sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + + let mut face = sketch.add_face(surface.clone()); + face.write() + .exterior + .write() + .update_as_polygon_from_points(TRIANGLE); + sketch }; let solid = sketch @@ -166,7 +172,13 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let sketch = { let mut sketch = PartialSketch::default(); - sketch.add_polygon_from_points(surface.clone(), TRIANGLE); + + let mut face = sketch.add_face(surface.clone()); + face.write() + .exterior + .write() + .update_as_polygon_from_points(TRIANGLE); + sketch }; let solid = sketch diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 8b3ef040c..628f40db1 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -1,31 +1,24 @@ -use fj_math::Point; - use crate::{ objects::{Face, Surface}, partial::{Partial, PartialFace, PartialSketch}, }; -use super::CycleBuilder; - /// Builder API for [`PartialSketch`] pub trait SketchBuilder { /// Add a polygon to the sketch, created from the provided points - fn add_polygon_from_points( + fn add_face( &mut self, surface: impl Into>, - points: impl IntoIterator>>, ) -> Partial; } impl SketchBuilder for PartialSketch { - fn add_polygon_from_points( + fn add_face( &mut self, surface: impl Into>, - points: impl IntoIterator>>, ) -> Partial { let mut face = PartialFace::default(); face.exterior.write().surface = surface.into(); - face.exterior.write().update_as_polygon_from_points(points); let face = Partial::from_partial(face); self.faces.extend([face.clone()]); From 2ab516999b7ddec65e0ff31f394c8772a748a7a8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 Jan 2023 12:09:16 +0100 Subject: [PATCH 5/7] Further simplify `SketchBuilder` method --- crates/fj-kernel/src/algorithms/sweep/face.rs | 8 ++++++-- crates/fj-kernel/src/builder/sketch.rs | 15 ++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index f27045bd5..32f209174 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -110,7 +110,9 @@ mod tests { let sketch = { let mut sketch = PartialSketch::default(); - let mut face = sketch.add_face(surface.clone()); + let mut face = sketch.add_face(); + face.write().exterior.write().surface = + Partial::from(surface.clone()); face.write() .exterior .write() @@ -173,7 +175,9 @@ mod tests { let sketch = { let mut sketch = PartialSketch::default(); - let mut face = sketch.add_face(surface.clone()); + let mut face = sketch.add_face(); + face.write().exterior.write().surface = + Partial::from(surface.clone()); face.write() .exterior .write() diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 628f40db1..6772e7db3 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -1,24 +1,17 @@ use crate::{ - objects::{Face, Surface}, + objects::Face, partial::{Partial, PartialFace, PartialSketch}, }; /// Builder API for [`PartialSketch`] pub trait SketchBuilder { /// Add a polygon to the sketch, created from the provided points - fn add_face( - &mut self, - surface: impl Into>, - ) -> Partial; + fn add_face(&mut self) -> Partial; } impl SketchBuilder for PartialSketch { - fn add_face( - &mut self, - surface: impl Into>, - ) -> Partial { - let mut face = PartialFace::default(); - face.exterior.write().surface = surface.into(); + fn add_face(&mut self) -> Partial { + let face = PartialFace::default(); let face = Partial::from_partial(face); self.faces.extend([face.clone()]); From e7407a40e9111784b2327d97ca88a147e88b753d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 Jan 2023 12:13:53 +0100 Subject: [PATCH 6/7] Update doc comment --- crates/fj-kernel/src/builder/sketch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 6772e7db3..e5687835a 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -5,7 +5,7 @@ use crate::{ /// Builder API for [`PartialSketch`] pub trait SketchBuilder { - /// Add a polygon to the sketch, created from the provided points + /// Add a face to the sketch fn add_face(&mut self) -> Partial; } From 18d280bc76dfa266123fb64be29f2e6900e82359 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 11 Jan 2023 12:14:56 +0100 Subject: [PATCH 7/7] Refactor --- crates/fj-kernel/src/builder/sketch.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index e5687835a..c80feb4ec 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -1,6 +1,6 @@ use crate::{ objects::Face, - partial::{Partial, PartialFace, PartialSketch}, + partial::{Partial, PartialSketch}, }; /// Builder API for [`PartialSketch`] @@ -11,11 +11,8 @@ pub trait SketchBuilder { impl SketchBuilder for PartialSketch { fn add_face(&mut self) -> Partial { - let face = PartialFace::default(); - - let face = Partial::from_partial(face); + let face = Partial::default(); self.faces.extend([face.clone()]); - face } }