From a76a8f993b0617b0acbd4dc6dc646dee04ee5568 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:24:16 +0200 Subject: [PATCH 01/10] Simplify constructor name I'm about to make changes that will make the old, more specific name no longer suitable. --- crates/fj-kernel/src/algorithms/reverse/face.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 4 ++-- crates/fj-kernel/src/algorithms/transform/face.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 2 +- crates/fj-kernel/src/builder/shell.rs | 4 ++-- crates/fj-kernel/src/objects/face.rs | 2 +- crates/fj-operations/src/difference_2d.rs | 2 +- crates/fj-operations/src/sketch.rs | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index 4fccfe726..f2df8f785 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -8,7 +8,7 @@ impl Reverse for Face { let interiors = self.interiors().map(|cycle| cycle.clone().reverse(objects)); - Face::from_exterior(exterior) + Face::new(exterior) .with_interiors(interiors) .with_color(self.color()) } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index bd3605cc3..51dfa7457 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -169,7 +169,7 @@ impl Sweep for (Handle, Color) { Cycle::new(surface, edges, objects) }; - Face::from_exterior(cycle).with_color(color) + Face::new(cycle).with_color(color) } } @@ -245,7 +245,7 @@ mod tests { &objects, ); - Face::from_exterior(cycle) + Face::new(cycle) }; assert_eq!(face, expected_face); diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index 59b58f0df..4a106300c 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -26,7 +26,7 @@ impl TransformObject for Face { let color = self.color(); - Face::from_exterior(exterior) + Face::new(exterior) .with_interiors(interiors) .with_color(color) } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index b63fd9cbe..790cdca9a 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -62,6 +62,6 @@ impl<'a> FaceBuilder<'a> { let exterior = self .exterior .expect("Can't build `Face` without exterior cycle"); - Face::from_exterior(exterior).with_interiors(self.interiors) + Face::new(exterior).with_interiors(self.interiors) } } diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 15ba7c1b4..ce54b6f16 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -171,7 +171,7 @@ impl<'a> ShellBuilder<'a> { .with_half_edges([bottom, side_up, top, side_down]) .build(self.objects); - Face::from_exterior(cycle) + Face::new(cycle) }); (sides, tops) @@ -234,7 +234,7 @@ impl<'a> ShellBuilder<'a> { ); } - Face::from_exterior(Cycle::new(surface, edges, self.objects)) + Face::new(Cycle::new(surface, edges, self.objects)) }; let mut faces = Vec::new(); diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index ac1bf3250..e10409174 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -54,7 +54,7 @@ impl Face { /// /// Creates the face with no interiors and the default color. This can be /// overridden using the `with_` methods. - pub fn from_exterior(exterior: Handle) -> Self { + pub fn new(exterior: Handle) -> Self { Self { surface: exterior.surface().clone(), exterior, diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index dfe0c4d19..6edf95bc0 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -78,7 +78,7 @@ impl Shape for fj::Difference2d { ); faces.push( - Face::from_exterior(exterior) + Face::new(exterior) .with_interiors(interiors) .with_color(Color(self.color())), ); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 7fc914720..2356f8ea6 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -32,7 +32,7 @@ impl Shape for fj::Sketch { .build(objects); let cycle = Cycle::new(surface, [half_edge], objects); - Face::from_exterior(cycle).with_color(Color(self.color())) + Face::new(cycle).with_color(Color(self.color())) } fj::Chain::PolyChain(poly_chain) => { let points = From c1f0bb471360eaae7e990f1c1b5df72a620c8cc7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:29:07 +0200 Subject: [PATCH 02/10] Make `Surface` in `FaceBuilder` optional --- crates/fj-kernel/src/builder/face.rs | 6 +++--- crates/fj-kernel/src/objects/face.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 790cdca9a..492c30a93 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -14,7 +14,7 @@ pub struct FaceBuilder<'a> { pub objects: &'a Objects, /// The surface that the [`Face`] is defined in - pub surface: Handle, + pub surface: Option>, /// The exterior cycle that bounds the [`Face`] on the outside /// @@ -34,7 +34,7 @@ impl<'a> FaceBuilder<'a> { ) -> Self { self.exterior = Some( Cycle::partial() - .with_surface(Some(self.surface.clone())) + .with_surface(self.surface.clone()) .with_poly_chain_from_points(points) .close_with_line_segment() .build(self.objects), @@ -49,7 +49,7 @@ impl<'a> FaceBuilder<'a> { ) -> Self { self.interiors.push( Cycle::partial() - .with_surface(Some(self.surface.clone())) + .with_surface(self.surface.clone()) .with_poly_chain_from_points(points) .close_with_line_segment() .build(self.objects), diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index e10409174..138bd7318 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -44,7 +44,7 @@ impl Face { pub fn builder(objects: &Objects, surface: Handle) -> FaceBuilder { FaceBuilder { objects, - surface, + surface: Some(surface), exterior: None, interiors: Vec::new(), } From 882d9f30b1b8eeec78fbd20f1a9961cf6bcadc6f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:34:51 +0200 Subject: [PATCH 03/10] Add `FaceBuilder::with_surface` --- crates/fj-kernel/src/builder/face.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 492c30a93..f831fced0 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -27,6 +27,12 @@ pub struct FaceBuilder<'a> { } impl<'a> FaceBuilder<'a> { + /// Build the [`Face`] with the provided surface + pub fn with_surface(mut self, surface: Handle) -> Self { + self.surface = Some(surface); + self + } + /// Build the [`Face`] with an exterior polygon from the provided points pub fn with_exterior_polygon_from_points( mut self, From bb9980f39f6d4ee0fa5494a38e1959d2ad968ba5 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:35:28 +0200 Subject: [PATCH 04/10] Simplify `Face::builder` --- .../src/algorithms/intersect/curve_face.rs | 3 ++- .../src/algorithms/intersect/face_face.rs | 6 +++-- .../src/algorithms/intersect/face_point.rs | 24 ++++++++++++------- .../src/algorithms/intersect/ray_face.rs | 21 ++++++++++------ crates/fj-kernel/src/algorithms/sweep/face.rs | 19 ++++++++------- .../src/algorithms/triangulate/mod.rs | 9 ++++--- crates/fj-kernel/src/builder/shell.rs | 3 ++- crates/fj-kernel/src/builder/sketch.rs | 3 ++- crates/fj-kernel/src/iter.rs | 6 +++-- crates/fj-kernel/src/objects/face.rs | 4 ++-- crates/fj-operations/src/sketch.rs | 3 ++- 11 files changed, 65 insertions(+), 36 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index dd9913d7a..e41a5a5bd 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -182,7 +182,8 @@ mod tests { [ 1., -1.], ]; - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points(exterior) .with_interior_polygon_from_points(interior) .build(); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_face.rs b/crates/fj-kernel/src/algorithms/intersect/face_face.rs index c2d3ad063..6c13e2538 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -79,7 +79,8 @@ mod tests { ]; let [a, b] = [objects.surfaces.xy_plane(), objects.surfaces.xz_plane()] .map(|surface| { - Face::builder(&objects, surface) + Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points(points) .build() }); @@ -103,7 +104,8 @@ mod tests { let surfaces = [objects.surfaces.xy_plane(), objects.surfaces.xz_plane()]; let [a, b] = surfaces.clone().map(|surface| { - Face::builder(&objects, surface) + Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points(points) .build() }); diff --git a/crates/fj-kernel/src/algorithms/intersect/face_point.rs b/crates/fj-kernel/src/algorithms/intersect/face_point.rs index 7e129a567..252ab7fa4 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -145,7 +145,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [1., 1.], [0., 2.]]) .build(); let point = Point::from([2., 1.]); @@ -159,7 +160,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [2., 1.], [0., 2.]]) .build(); let point = Point::from([1., 1.]); @@ -176,7 +178,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[4., 2.], [0., 4.], [0., 0.]]) .build(); let point = Point::from([1., 2.]); @@ -193,7 +196,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [0., 0.], [2., 1.], @@ -215,7 +219,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [0., 0.], [2., 1.], @@ -237,7 +242,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [0., 0.], [2., 1.], @@ -260,7 +266,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [2., 0.], [0., 1.]]) .build(); let point = Point::from([1., 0.]); @@ -286,7 +293,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]) .build(); let point = Point::from([1., 0.]); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index 66030713c..d630f949e 100644 --- a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs @@ -163,7 +163,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.yz_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -183,7 +184,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.yz_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -206,7 +208,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.yz_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -226,7 +229,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.yz_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -257,7 +261,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.yz_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -286,7 +291,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-1., -1.], [1., -1.], @@ -308,7 +314,8 @@ mod tests { let ray = HorizontalRayToTheRight::from([0., 0., 0.]); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-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 01cf7f627..36bf806fa 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -102,11 +102,13 @@ mod tests { .build_polygon_from_points(TRIANGLE) .sweep(UP, &objects); - let bottom = Face::builder(&objects, surface.clone()) + let bottom = Face::builder(&objects) + .with_surface(surface.clone()) .with_exterior_polygon_from_points(TRIANGLE) .build() .reverse(&objects); - let top = Face::builder(&objects, surface.translate(UP, &objects)) + let top = Face::builder(&objects) + .with_surface(surface.translate(UP, &objects)) .with_exterior_polygon_from_points(TRIANGLE) .build(); @@ -134,12 +136,13 @@ mod tests { .build_polygon_from_points(TRIANGLE) .sweep(DOWN, &objects); - let bottom = - Face::builder(&objects, surface.clone().translate(DOWN, &objects)) - .with_exterior_polygon_from_points(TRIANGLE) - .build() - .reverse(&objects); - let top = Face::builder(&objects, surface) + let bottom = Face::builder(&objects) + .with_surface(surface.clone().translate(DOWN, &objects)) + .with_exterior_polygon_from_points(TRIANGLE) + .build() + .reverse(&objects); + let top = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points(TRIANGLE) .build(); diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 697818a30..7dc826434 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -99,7 +99,8 @@ mod tests { let d = [0., 1.]; let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([a, b, c, d]) .build(); @@ -133,7 +134,8 @@ mod tests { let h = [3., 1.]; let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface.clone()) + let face = Face::builder(&objects) + .with_surface(surface.clone()) .with_exterior_polygon_from_points([a, b, c, d]) .with_interior_polygon_from_points([e, f, g, h]) .build(); @@ -193,7 +195,8 @@ mod tests { let e = [0., 0.8]; let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface.clone()) + let face = Face::builder(&objects) + .with_surface(surface.clone()) .with_exterior_polygon_from_points([a, b, c, d, e]) .build(); diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index ce54b6f16..8db3e5726 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -39,7 +39,8 @@ impl<'a> ShellBuilder<'a> { .xy_plane() .translate([Z, Z, -h], self.objects); - Face::builder(self.objects, surface) + Face::builder(self.objects) + .with_surface(surface) .with_exterior_polygon_from_points([ [-h, -h], [h, -h], diff --git a/crates/fj-kernel/src/builder/sketch.rs b/crates/fj-kernel/src/builder/sketch.rs index 7ca130e94..03feb3777 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -22,7 +22,8 @@ impl<'a> SketchBuilder<'a> { self, points: impl IntoIterator>>, ) -> Sketch { - let face = Face::builder(self.objects, self.surface) + let face = Face::builder(self.objects) + .with_surface(self.surface) .with_exterior_polygon_from_points(points) .build(); Sketch::new().with_faces([face]) diff --git a/crates/fj-kernel/src/iter.rs b/crates/fj-kernel/src/iter.rs index 7d1d4314a..081f9458b 100644 --- a/crates/fj-kernel/src/iter.rs +++ b/crates/fj-kernel/src/iter.rs @@ -421,7 +421,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let object = Face::builder(&objects, surface) + let object = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]) .build(); @@ -522,7 +523,8 @@ mod tests { let objects = Objects::new(); let surface = objects.surfaces.xy_plane(); - let face = Face::builder(&objects, surface) + let face = Face::builder(&objects) + .with_surface(surface) .with_exterior_polygon_from_points([[0., 0.], [1., 0.], [0., 1.]]) .build(); let object = Sketch::new().with_faces([face]); diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index 138bd7318..ea2b0763d 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -41,10 +41,10 @@ pub struct Face { impl Face { /// Build a `Face` using [`FaceBuilder`] - pub fn builder(objects: &Objects, surface: Handle) -> FaceBuilder { + pub fn builder(objects: &Objects) -> FaceBuilder { FaceBuilder { objects, - surface: Some(surface), + surface: None, exterior: None, interiors: Vec::new(), } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 2356f8ea6..dc7dcad2d 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -38,7 +38,8 @@ impl Shape for fj::Sketch { let points = poly_chain.to_points().into_iter().map(Point::from); - Face::builder(objects, surface) + Face::builder(objects) + .with_surface(surface) .with_exterior_polygon_from_points(points) .build() .with_color(Color(self.color())) From 85321ce0f22283d96fc7e5a0e0119756a393b511 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:38:58 +0200 Subject: [PATCH 05/10] Add `FaceBuilder::with_exterior` --- crates/fj-kernel/src/algorithms/reverse/face.rs | 4 +++- crates/fj-kernel/src/algorithms/sweep/edge.rs | 7 +++++-- crates/fj-kernel/src/algorithms/transform/face.rs | 4 +++- crates/fj-kernel/src/builder/face.rs | 6 ++++++ crates/fj-kernel/src/builder/shell.rs | 6 ++++-- crates/fj-operations/src/difference_2d.rs | 4 +++- crates/fj-operations/src/sketch.rs | 5 ++++- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index f2df8f785..a04cdd812 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -8,7 +8,9 @@ impl Reverse for Face { let interiors = self.interiors().map(|cycle| cycle.clone().reverse(objects)); - Face::new(exterior) + Face::builder(objects) + .with_exterior(exterior) + .build() .with_interiors(interiors) .with_color(self.color()) } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 51dfa7457..9851a2019 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -169,7 +169,10 @@ impl Sweep for (Handle, Color) { Cycle::new(surface, edges, objects) }; - Face::new(cycle).with_color(color) + Face::builder(objects) + .with_exterior(cycle) + .build() + .with_color(color) } } @@ -245,7 +248,7 @@ mod tests { &objects, ); - Face::new(cycle) + Face::builder(&objects).with_exterior(cycle).build() }; assert_eq!(face, expected_face); diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index 4a106300c..540446b1b 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -26,7 +26,9 @@ impl TransformObject for Face { let color = self.color(); - Face::new(exterior) + Face::builder(objects) + .with_exterior(exterior) + .build() .with_interiors(interiors) .with_color(color) } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index f831fced0..dd2e2a8eb 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -33,6 +33,12 @@ impl<'a> FaceBuilder<'a> { self } + /// Build the [`Face`] with the provided exterior + pub fn with_exterior(mut self, exterior: Handle) -> Self { + self.exterior = Some(exterior); + self + } + /// Build the [`Face`] with an exterior polygon from the provided points pub fn with_exterior_polygon_from_points( mut self, diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index 8db3e5726..b56dce2a6 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -172,7 +172,7 @@ impl<'a> ShellBuilder<'a> { .with_half_edges([bottom, side_up, top, side_down]) .build(self.objects); - Face::new(cycle) + Face::builder(self.objects).with_exterior(cycle).build() }); (sides, tops) @@ -235,7 +235,9 @@ impl<'a> ShellBuilder<'a> { ); } - Face::new(Cycle::new(surface, edges, self.objects)) + Face::builder(self.objects) + .with_exterior(Cycle::new(surface, edges, self.objects)) + .build() }; let mut faces = Vec::new(); diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index 6edf95bc0..ed795cf60 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -78,7 +78,9 @@ impl Shape for fj::Difference2d { ); faces.push( - Face::new(exterior) + Face::builder(objects) + .with_exterior(exterior) + .build() .with_interiors(interiors) .with_color(Color(self.color())), ); diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index dc7dcad2d..2a2da6513 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -32,7 +32,10 @@ impl Shape for fj::Sketch { .build(objects); let cycle = Cycle::new(surface, [half_edge], objects); - Face::new(cycle).with_color(Color(self.color())) + Face::builder(objects) + .with_exterior(cycle) + .build() + .with_color(Color(self.color())) } fj::Chain::PolyChain(poly_chain) => { let points = From 13960920240710b972f546bd97b85595b5e46e4e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:45:12 +0200 Subject: [PATCH 06/10] Add `FaceBuilder::with_interiors` --- crates/fj-kernel/src/algorithms/reverse/face.rs | 2 +- crates/fj-kernel/src/algorithms/transform/face.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 9 +++++++++ crates/fj-operations/src/difference_2d.rs | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index a04cdd812..c7961657e 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -10,8 +10,8 @@ impl Reverse for Face { Face::builder(objects) .with_exterior(exterior) - .build() .with_interiors(interiors) + .build() .with_color(self.color()) } } diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index 540446b1b..d97ff0a8a 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -28,8 +28,8 @@ impl TransformObject for Face { Face::builder(objects) .with_exterior(exterior) - .build() .with_interiors(interiors) + .build() .with_color(color) } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index dd2e2a8eb..dfde3d137 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -54,6 +54,15 @@ impl<'a> FaceBuilder<'a> { self } + /// Build the [`Face`] with the provided interior polygons + pub fn with_interiors( + mut self, + interiors: impl IntoIterator>, + ) -> Self { + self.interiors.extend(interiors); + self + } + /// Build the [`Face`] with an interior polygon from the provided points pub fn with_interior_polygon_from_points( mut self, diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index ed795cf60..f30f6f3a6 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -80,8 +80,8 @@ impl Shape for fj::Difference2d { faces.push( Face::builder(objects) .with_exterior(exterior) - .build() .with_interiors(interiors) + .build() .with_color(Color(self.color())), ); } From 630dc53b7085be24bbff14a93d4e5ba473ffe0fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:47:20 +0200 Subject: [PATCH 07/10] Refactor --- crates/fj-kernel/src/objects/face.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index ea2b0763d..058fffa6c 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -55,11 +55,15 @@ impl Face { /// Creates the face with no interiors and the default color. This can be /// overridden using the `with_` methods. pub fn new(exterior: Handle) -> Self { + let surface = exterior.surface().clone(); + let interiors = Vec::new(); + let color = Color::default(); + Self { - surface: exterior.surface().clone(), + surface, exterior, - interiors: Vec::new(), - color: Color::default(), + interiors, + color, } } From b0f3266f9cfe78568473903a973c25ae59f413d0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:49:32 +0200 Subject: [PATCH 08/10] Merge `Face::with_interiors` into constructor --- crates/fj-kernel/src/builder/face.rs | 2 +- crates/fj-kernel/src/objects/face.rs | 46 +++++++++++----------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index dfde3d137..2f5423c4a 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -83,6 +83,6 @@ impl<'a> FaceBuilder<'a> { let exterior = self .exterior .expect("Can't build `Face` without exterior cycle"); - Face::new(exterior).with_interiors(self.interiors) + Face::new(exterior, self.interiors) } } diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index 058fffa6c..45f17728c 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -52,51 +52,41 @@ impl Face { /// Construct a new instance of `Face` /// - /// Creates the face with no interiors and the default color. This can be - /// overridden using the `with_` methods. - pub fn new(exterior: Handle) -> Self { - let surface = exterior.surface().clone(); - let interiors = Vec::new(); - let color = Color::default(); - - Self { - surface, - exterior, - interiors, - color, - } - } - - /// Add interior cycles to the face - /// - /// Consumes the face and returns the updated instance. - /// /// # Panics /// - /// Panics, if the added cycles are not defined in the face's surface. + /// Panics, if the provided cycles are not defined in the same surface. /// /// Panics, if the winding of the interior cycles is not opposite that of /// the exterior cycle. - pub fn with_interiors( - mut self, - interiors: impl IntoIterator>, + pub fn new( + exterior: Handle, + the_interiors: impl IntoIterator>, ) -> Self { - for interior in interiors.into_iter() { + let surface = exterior.surface().clone(); + let mut interiors = Vec::new(); + let color = Color::default(); + + for interior in the_interiors.into_iter() { assert_eq!( - self.surface().id(), + surface.id(), interior.surface().id(), "Cycles that bound a face must be in face's surface" ); assert_ne!( - self.exterior().winding(), + exterior.winding(), interior.winding(), "Interior cycles must have opposite winding of exterior cycle" ); - self.interiors.push(interior); + interiors.push(interior); } - self + Self { + surface, + exterior, + interiors, + color, + } } /// Update the color of the face From f3e661d2c4a5e7c24f155c702463cae56a96a15a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:52:58 +0200 Subject: [PATCH 09/10] Add `FaceBuilder::with_color` --- crates/fj-kernel/src/algorithms/reverse/face.rs | 2 +- crates/fj-kernel/src/algorithms/sweep/edge.rs | 2 +- crates/fj-kernel/src/algorithms/transform/face.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 14 +++++++++++++- crates/fj-kernel/src/objects/face.rs | 1 + crates/fj-operations/src/difference_2d.rs | 4 ++-- crates/fj-operations/src/sketch.rs | 4 ++-- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/reverse/face.rs b/crates/fj-kernel/src/algorithms/reverse/face.rs index c7961657e..1ed9f2154 100644 --- a/crates/fj-kernel/src/algorithms/reverse/face.rs +++ b/crates/fj-kernel/src/algorithms/reverse/face.rs @@ -11,7 +11,7 @@ impl Reverse for Face { Face::builder(objects) .with_exterior(exterior) .with_interiors(interiors) - .build() .with_color(self.color()) + .build() } } diff --git a/crates/fj-kernel/src/algorithms/sweep/edge.rs b/crates/fj-kernel/src/algorithms/sweep/edge.rs index 9851a2019..e6fa94430 100644 --- a/crates/fj-kernel/src/algorithms/sweep/edge.rs +++ b/crates/fj-kernel/src/algorithms/sweep/edge.rs @@ -171,8 +171,8 @@ impl Sweep for (Handle, Color) { Face::builder(objects) .with_exterior(cycle) - .build() .with_color(color) + .build() } } diff --git a/crates/fj-kernel/src/algorithms/transform/face.rs b/crates/fj-kernel/src/algorithms/transform/face.rs index d97ff0a8a..a1050e5be 100644 --- a/crates/fj-kernel/src/algorithms/transform/face.rs +++ b/crates/fj-kernel/src/algorithms/transform/face.rs @@ -29,8 +29,8 @@ impl TransformObject for Face { Face::builder(objects) .with_exterior(exterior) .with_interiors(interiors) - .build() .with_color(color) + .build() } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 2f5423c4a..d3fe6bb78 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -1,3 +1,4 @@ +use fj_interop::mesh::Color; use fj_math::Point; use crate::{ @@ -24,6 +25,9 @@ pub struct FaceBuilder<'a> { /// The interior cycles that form holes in the [`Face`] pub interiors: Vec>, + + /// The color of the [`Face`] + pub color: Option, } impl<'a> FaceBuilder<'a> { @@ -78,11 +82,19 @@ impl<'a> FaceBuilder<'a> { self } + /// Build the [`Face`] with the provided color + pub fn with_color(mut self, color: Color) -> Self { + self.color = Some(color); + self + } + /// Construct a polygon from a list of points pub fn build(self) -> Face { let exterior = self .exterior .expect("Can't build `Face` without exterior cycle"); - Face::new(exterior, self.interiors) + let color = self.color.unwrap_or_default(); + + Face::new(exterior, self.interiors).with_color(color) } } diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index 45f17728c..4bbfb9c1d 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -47,6 +47,7 @@ impl Face { surface: None, exterior: None, interiors: Vec::new(), + color: None, } } diff --git a/crates/fj-operations/src/difference_2d.rs b/crates/fj-operations/src/difference_2d.rs index f30f6f3a6..fa9916d3f 100644 --- a/crates/fj-operations/src/difference_2d.rs +++ b/crates/fj-operations/src/difference_2d.rs @@ -81,8 +81,8 @@ impl Shape for fj::Difference2d { Face::builder(objects) .with_exterior(exterior) .with_interiors(interiors) - .build() - .with_color(Color(self.color())), + .with_color(Color(self.color())) + .build(), ); } diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 2a2da6513..4c16baef7 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -34,8 +34,8 @@ impl Shape for fj::Sketch { Face::builder(objects) .with_exterior(cycle) - .build() .with_color(Color(self.color())) + .build() } fj::Chain::PolyChain(poly_chain) => { let points = @@ -44,8 +44,8 @@ impl Shape for fj::Sketch { Face::builder(objects) .with_surface(surface) .with_exterior_polygon_from_points(points) - .build() .with_color(Color(self.color())) + .build() } }; From a6f50e80d96b67c60466131b212cebbf124a145e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Sat, 22 Oct 2022 09:54:06 +0200 Subject: [PATCH 10/10] Merge `Face::with_color` into constructor --- crates/fj-kernel/src/builder/face.rs | 2 +- crates/fj-kernel/src/objects/face.rs | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index d3fe6bb78..3715ed32e 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -95,6 +95,6 @@ impl<'a> FaceBuilder<'a> { .expect("Can't build `Face` without exterior cycle"); let color = self.color.unwrap_or_default(); - Face::new(exterior, self.interiors).with_color(color) + Face::new(exterior, self.interiors, color) } } diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index 4bbfb9c1d..da3fae686 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -62,10 +62,10 @@ impl Face { pub fn new( exterior: Handle, the_interiors: impl IntoIterator>, + color: Color, ) -> Self { let surface = exterior.surface().clone(); let mut interiors = Vec::new(); - let color = Color::default(); for interior in the_interiors.into_iter() { assert_eq!( @@ -90,14 +90,6 @@ impl Face { } } - /// Update the color of the face - /// - /// Consumes the face and returns the updated instance. - pub fn with_color(mut self, color: Color) -> Self { - self.color = color; - self - } - /// Access this face's surface pub fn surface(&self) -> &Handle { &self.surface