From 886f2d995388221c5a160cb43b6d257d4d288d32 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 4 Jan 2023 14:51:02 +0100 Subject: [PATCH 1/8] Add new `FaceBuilder` method --- crates/fj-kernel/src/builder/face.rs | 39 +++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index bc1c49ee9..907b7378a 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -5,7 +5,7 @@ use crate::{ partial::{Partial, PartialCycle, PartialFace}, }; -use super::CycleBuilder; +use super::{CycleBuilder, SurfaceBuilder}; /// Builder API for [`PartialFace`] pub trait FaceBuilder { @@ -15,6 +15,21 @@ pub trait FaceBuilder { points: impl IntoIterator>>, ) -> Vec>; + /// Update the [`PartialFace`] with an exterior triangle, from 3D points + /// + /// Uses the three points to infer a plane that is used as the surface. + /// + /// # Implementation Note + /// + /// This method is probably just temporary, and will be generalized into a + /// "update as polygon from global points" method sooner or later. For now, + /// I didn't want to deal with the question of how to infer the surface, and + /// how to handle points that don't fit that surface. + fn update_exterior_as_triangle_from_global_points( + &mut self, + points: [impl Into>; 3], + ) -> [Partial; 3]; + /// Update the [`PartialFace`] with an interior polygon fn add_interior_polygon( &mut self, @@ -30,6 +45,28 @@ impl FaceBuilder for PartialFace { self.exterior.write().update_as_polygon_from_points(points) } + fn update_exterior_as_triangle_from_global_points( + &mut self, + points_global: [impl Into>; 3], + ) -> [Partial; 3] { + let points_surface = self + .exterior + .write() + .surface + .write() + .update_as_plane_from_points(points_global); + let mut edges = self.update_exterior_as_polygon(points_surface); + + // None of the following should panic, as we just created a polygon from + // three points, so we should have exactly three edges. + let c = edges.pop().unwrap(); + let b = edges.pop().unwrap(); + let a = edges.pop().unwrap(); + assert!(edges.pop().is_none()); + + [a, b, c] + } + fn add_interior_polygon( &mut self, points: impl IntoIterator>>, From c170b8eb37795334f2162cba6068dd95c2f22db9 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 12:03:58 +0100 Subject: [PATCH 2/8] Update order of methods Add half-edges to the cycle seems more essential, so it makes sense that it should come before the higher-level methods. --- crates/fj-kernel/src/builder/cycle.rs | 60 +++++++++++++-------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index da31da187..151f4c5b4 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -9,17 +9,6 @@ use super::HalfEdgeBuilder; /// Builder API for [`PartialCycle`] pub trait CycleBuilder { - /// Create a cycle as a polygonal chain from the provided points - fn update_as_polygon_from_points( - &mut self, - points: impl IntoIterator>>, - ) -> Vec>; - - /// Update cycle to be a polygon - /// - /// Will update each half-edge in the cycle to be a line segment. - fn update_as_polygon(&mut self); - /// Add a new half-edge to the cycle /// /// Creates a half-edge and adds it to the cycle. The new half-edge is @@ -43,31 +32,20 @@ pub trait CycleBuilder { &mut self, point: impl Into>, ) -> Partial; -} -impl CycleBuilder for PartialCycle { + /// Create a cycle as a polygonal chain from the provided points fn update_as_polygon_from_points( &mut self, points: impl IntoIterator>>, - ) -> Vec> { - let mut half_edges = Vec::new(); - - for point in points { - let half_edge = self.add_half_edge_from_point_to_start(point); - half_edges.push(half_edge); - } - - self.update_as_polygon(); - - half_edges - } + ) -> Vec>; - fn update_as_polygon(&mut self) { - for half_edge in &mut self.half_edges { - half_edge.write().update_as_line_segment(); - } - } + /// Update cycle to be a polygon + /// + /// Will update each half-edge in the cycle to be a line segment. + fn update_as_polygon(&mut self); +} +impl CycleBuilder for PartialCycle { fn add_half_edge(&mut self) -> Partial { let mut new_half_edge = Partial::::new(); @@ -129,4 +107,26 @@ impl CycleBuilder for PartialCycle { half_edge } + + fn update_as_polygon_from_points( + &mut self, + points: impl IntoIterator>>, + ) -> Vec> { + let mut half_edges = Vec::new(); + + for point in points { + let half_edge = self.add_half_edge_from_point_to_start(point); + half_edges.push(half_edge); + } + + self.update_as_polygon(); + + half_edges + } + + fn update_as_polygon(&mut self) { + for half_edge in &mut self.half_edges { + half_edge.write().update_as_line_segment(); + } + } } From a01b9a337d432461cfdda5fa30865b78c2fb53d7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 12:06:59 +0100 Subject: [PATCH 3/8] Update doc comments --- crates/fj-kernel/src/builder/cycle.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 151f4c5b4..525be9dd7 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -33,13 +33,13 @@ pub trait CycleBuilder { point: impl Into>, ) -> Partial; - /// Create a cycle as a polygonal chain from the provided points + /// Update cycle as a polygon from the provided points fn update_as_polygon_from_points( &mut self, points: impl IntoIterator>>, ) -> Vec>; - /// Update cycle to be a polygon + /// Update cycle as a polygon /// /// Will update each half-edge in the cycle to be a line segment. fn update_as_polygon(&mut self); From 110c543921c7573b4ea23a81bc9d26288b4a3da7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 12:09:47 +0100 Subject: [PATCH 4/8] Add new `CycleBuilder` method --- crates/fj-kernel/src/builder/cycle.rs | 36 +++++++++++++++++++++++++++ crates/fj-kernel/src/builder/face.rs | 19 +++----------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/crates/fj-kernel/src/builder/cycle.rs b/crates/fj-kernel/src/builder/cycle.rs index 525be9dd7..68749a828 100644 --- a/crates/fj-kernel/src/builder/cycle.rs +++ b/crates/fj-kernel/src/builder/cycle.rs @@ -1,6 +1,7 @@ use fj_math::Point; use crate::{ + builder::SurfaceBuilder, objects::HalfEdge, partial::{Partial, PartialCycle}, }; @@ -43,6 +44,21 @@ pub trait CycleBuilder { /// /// Will update each half-edge in the cycle to be a line segment. fn update_as_polygon(&mut self); + + /// Update cycle as a triangle, from global (3D) points + /// + /// Uses the three points to infer a plane that is used as the surface. + /// + /// # Implementation Note + /// + /// This method is probably just temporary, and will be generalized into a + /// "update as polygon from global points" method sooner or later. For now, + /// I didn't want to deal with the question of how to infer the surface, and + /// how to handle points that don't fit that surface. + fn update_as_triangle_from_global_points( + &mut self, + points: [impl Into>; 3], + ) -> [Partial; 3]; } impl CycleBuilder for PartialCycle { @@ -129,4 +145,24 @@ impl CycleBuilder for PartialCycle { half_edge.write().update_as_line_segment(); } } + + fn update_as_triangle_from_global_points( + &mut self, + points_global: [impl Into>; 3], + ) -> [Partial; 3] { + let points_surface = self + .surface + .write() + .update_as_plane_from_points(points_global); + let mut edges = self.update_as_polygon_from_points(points_surface); + + // None of the following should panic, as we just created a polygon from + // three points, so we should have exactly three edges. + let c = edges.pop().unwrap(); + let b = edges.pop().unwrap(); + let a = edges.pop().unwrap(); + assert!(edges.pop().is_none()); + + [a, b, c] + } } diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index 907b7378a..3c035c4aa 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -5,7 +5,7 @@ use crate::{ partial::{Partial, PartialCycle, PartialFace}, }; -use super::{CycleBuilder, SurfaceBuilder}; +use super::CycleBuilder; /// Builder API for [`PartialFace`] pub trait FaceBuilder { @@ -49,22 +49,9 @@ impl FaceBuilder for PartialFace { &mut self, points_global: [impl Into>; 3], ) -> [Partial; 3] { - let points_surface = self - .exterior + self.exterior .write() - .surface - .write() - .update_as_plane_from_points(points_global); - let mut edges = self.update_exterior_as_polygon(points_surface); - - // None of the following should panic, as we just created a polygon from - // three points, so we should have exactly three edges. - let c = edges.pop().unwrap(); - let b = edges.pop().unwrap(); - let a = edges.pop().unwrap(); - assert!(edges.pop().is_none()); - - [a, b, c] + .update_as_triangle_from_global_points(points_global) } fn add_interior_polygon( From 372050cb80207e3afad6f8902186f993b1654769 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 16:31:09 +0100 Subject: [PATCH 5/8] Make method name more specific --- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/intersect/face_face.rs | 4 +-- .../src/algorithms/intersect/face_point.rs | 36 ++++++++++++++----- .../src/algorithms/intersect/ray_face.rs | 14 ++++---- crates/fj-kernel/src/algorithms/sweep/face.rs | 8 ++--- .../src/algorithms/triangulate/mod.rs | 6 ++-- 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/validate/face.rs | 12 +++++-- crates/fj-operations/src/sketch.rs | 2 +- 11 files changed, 60 insertions(+), 32 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 06d049cc2..310e2756b 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.exterior.write().surface = surface; - face.update_exterior_as_polygon(exterior); + face.update_exterior_as_polygon_from_points(exterior); face.add_interior_polygon(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 adf9a5496..a8ba4668a 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_face.rs @@ -95,7 +95,7 @@ mod tests { .map(|surface| { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon(points); + face.update_exterior_as_polygon_from_points(points); face.build(&mut services.objects) }); @@ -124,7 +124,7 @@ mod tests { let [a, b] = surfaces.clone().map(|surface| { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon(points); + face.update_exterior_as_polygon_from_points(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 7e2c74c9f..c7192eb2e 100644 --- a/crates/fj-kernel/src/algorithms/intersect/face_point.rs +++ b/crates/fj-kernel/src/algorithms/intersect/face_point.rs @@ -149,7 +149,11 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([[0., 0.], [1., 1.], [0., 2.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [1., 1.], + [0., 2.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -166,7 +170,11 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([[0., 0.], [2., 1.], [0., 2.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [2., 1.], + [0., 2.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -186,7 +194,11 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([[4., 2.], [0., 4.], [0., 0.]]); + face.update_exterior_as_polygon_from_points([ + [4., 2.], + [0., 4.], + [0., 0.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -206,7 +218,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 0.], @@ -231,7 +243,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 1.], @@ -256,7 +268,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [0., 0.], [2., 1.], [3., 1.], @@ -282,7 +294,11 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([[0., 0.], [2., 0.], [0., 1.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [2., 0.], + [0., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -312,7 +328,11 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([[0., 0.], [1., 0.], [0., 1.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [1., 0.], + [0., 1.], + ]); let face = face .build(&mut services.objects) .insert(&mut services.objects); diff --git a/crates/fj-kernel/src/algorithms/intersect/ray_face.rs b/crates/fj-kernel/src/algorithms/intersect/ray_face.rs index cb9572487..3391e7a18 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 mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -190,7 +190,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -216,7 +216,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -239,7 +239,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -274,7 +274,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.yz_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -308,7 +308,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-1., -1.], [1., -1.], [1., 1.], @@ -333,7 +333,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-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 799803854..65d0f298f 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -116,7 +116,7 @@ mod tests { let mut bottom = PartialFace::default(); bottom.exterior.write().surface = Partial::from(surface.clone()); - bottom.update_exterior_as_polygon(TRIANGLE); + bottom.update_exterior_as_polygon_from_points(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) @@ -124,7 +124,7 @@ mod tests { let mut top = PartialFace::default(); top.exterior.write().surface = Partial::from(surface.translate(UP, &mut services.objects)); - top.update_exterior_as_polygon(TRIANGLE); + top.update_exterior_as_polygon_from_points(TRIANGLE); let top = top .build(&mut services.objects) .insert(&mut services.objects); @@ -169,14 +169,14 @@ mod tests { bottom.exterior.write().surface = Partial::from( surface.clone().translate(DOWN, &mut services.objects), ); - bottom.update_exterior_as_polygon(TRIANGLE); + bottom.update_exterior_as_polygon_from_points(TRIANGLE); let bottom = bottom .build(&mut services.objects) .insert(&mut services.objects) .reverse(&mut services.objects); let mut top = PartialFace::default(); top.exterior.write().surface = Partial::from(surface); - top.update_exterior_as_polygon(TRIANGLE); + top.update_exterior_as_polygon_from_points(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 695c7aad0..1aef2605f 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -99,7 +99,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(services.objects.surfaces.xy_plane()); - face.update_exterior_as_polygon([a, b, c, d]); + face.update_exterior_as_polygon_from_points([a, b, c, d]); let face = face .build(&mut services.objects) .insert(&mut services.objects); @@ -136,7 +136,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface.clone()); - face.update_exterior_as_polygon([a, b, c, d]); + face.update_exterior_as_polygon_from_points([a, b, c, d]); face.add_interior_polygon([e, f, g, h]); let face = face .build(&mut services.objects) @@ -196,7 +196,7 @@ mod tests { let surface = services.objects.surfaces.xy_plane(); let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface.clone()); - face.update_exterior_as_polygon([a, b, c, d, e]); + face.update_exterior_as_polygon_from_points([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 3c035c4aa..f869eeafc 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 update_exterior_as_polygon( + fn update_exterior_as_polygon_from_points( &mut self, points: impl IntoIterator>>, ) -> Vec>; @@ -38,7 +38,7 @@ pub trait FaceBuilder { } impl FaceBuilder for PartialFace { - fn update_exterior_as_polygon( + fn update_exterior_as_polygon_from_points( &mut self, points: impl IntoIterator>>, ) -> Vec> { diff --git a/crates/fj-kernel/src/builder/shell.rs b/crates/fj-kernel/src/builder/shell.rs index c673449b4..073d12fa1 100644 --- a/crates/fj-kernel/src/builder/shell.rs +++ b/crates/fj-kernel/src/builder/shell.rs @@ -55,7 +55,7 @@ impl ShellBuilder for PartialShell { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon([ + face.update_exterior_as_polygon_from_points([ [-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 1436ad2cd..57ca036fb 100644 --- a/crates/fj-kernel/src/builder/sketch.rs +++ b/crates/fj-kernel/src/builder/sketch.rs @@ -25,7 +25,7 @@ impl SketchBuilder for PartialSketch { ) { let mut face = PartialFace::default(); face.exterior.write().surface = surface.into(); - face.update_exterior_as_polygon(points); + face.update_exterior_as_polygon_from_points(points); self.faces.extend([Partial::from_partial(face)]); } diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index 893683beb..fe6312ade 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -122,7 +122,11 @@ mod tests { let valid = { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon([[0., 0.], [3., 0.], [0., 3.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [3., 0.], + [0., 3.], + ]); face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) @@ -154,7 +158,11 @@ mod tests { let valid = { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon([[0., 0.], [3., 0.], [0., 3.]]); + face.update_exterior_as_polygon_from_points([ + [0., 0.], + [3., 0.], + [0., 3.], + ]); face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); face.build(&mut services.objects) }; diff --git a/crates/fj-operations/src/sketch.rs b/crates/fj-operations/src/sketch.rs index 61318cce6..4cd863d8e 100644 --- a/crates/fj-operations/src/sketch.rs +++ b/crates/fj-operations/src/sketch.rs @@ -64,7 +64,7 @@ impl Shape for fj::Sketch { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface); - face.update_exterior_as_polygon(points); + face.update_exterior_as_polygon_from_points(points); face.color = Some(Color(self.color())); face From 0baa9215c7f1dec7512f43d1b0d792b82e996d49 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 16:33:18 +0100 Subject: [PATCH 6/8] Update doc comments --- crates/fj-kernel/src/builder/face.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index f869eeafc..1142b87e3 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -9,13 +9,13 @@ use super::CycleBuilder; /// Builder API for [`PartialFace`] pub trait FaceBuilder { - /// Update the [`PartialFace`] with an exterior polygon + /// Update the face exterior as a polygon from the provided points fn update_exterior_as_polygon_from_points( &mut self, points: impl IntoIterator>>, ) -> Vec>; - /// Update the [`PartialFace`] with an exterior triangle, from 3D points + /// Update the face exterior as a triangle, from 3D points /// /// Uses the three points to infer a plane that is used as the surface. /// @@ -30,7 +30,7 @@ pub trait FaceBuilder { points: [impl Into>; 3], ) -> [Partial; 3]; - /// Update the [`PartialFace`] with an interior polygon + /// Add an interior polygon, from the provided points fn add_interior_polygon( &mut self, points: impl IntoIterator>>, From 8addc440326aea2f0367383031b7fe842b348347 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 16:35:03 +0100 Subject: [PATCH 7/8] Make method name more specific --- .../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 | 12 ++++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 310e2756b..76d839a07 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -189,7 +189,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = surface; face.update_exterior_as_polygon_from_points(exterior); - face.add_interior_polygon(interior); + face.add_interior_polygon_from_points(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 1aef2605f..c252bb7fc 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -137,7 +137,7 @@ mod tests { let mut face = PartialFace::default(); face.exterior.write().surface = Partial::from(surface.clone()); face.update_exterior_as_polygon_from_points([a, b, c, d]); - face.add_interior_polygon([e, f, g, h]); + face.add_interior_polygon_from_points([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 1142b87e3..a5a31bbea 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -31,7 +31,7 @@ pub trait FaceBuilder { ) -> [Partial; 3]; /// Add an interior polygon, from the provided points - fn add_interior_polygon( + fn add_interior_polygon_from_points( &mut self, points: impl IntoIterator>>, ); @@ -54,7 +54,7 @@ impl FaceBuilder for PartialFace { .update_as_triangle_from_global_points(points_global) } - fn add_interior_polygon( + fn add_interior_polygon_from_points( &mut self, points: impl IntoIterator>>, ) { diff --git a/crates/fj-kernel/src/validate/face.rs b/crates/fj-kernel/src/validate/face.rs index fe6312ade..0effcee19 100644 --- a/crates/fj-kernel/src/validate/face.rs +++ b/crates/fj-kernel/src/validate/face.rs @@ -127,7 +127,11 @@ mod tests { [3., 0.], [0., 3.], ]); - face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); + face.add_interior_polygon_from_points([ + [1., 1.], + [1., 2.], + [2., 1.], + ]); face.build(&mut services.objects) }; @@ -163,7 +167,11 @@ mod tests { [3., 0.], [0., 3.], ]); - face.add_interior_polygon([[1., 1.], [1., 2.], [2., 1.]]); + face.add_interior_polygon_from_points([ + [1., 1.], + [1., 2.], + [2., 1.], + ]); face.build(&mut services.objects) }; let invalid = { From 2e35790f7f5abd040ff985203cba04c719529b0a Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 5 Jan 2023 16:36:26 +0100 Subject: [PATCH 8/8] Add `FaceBuilder::update_exterior_as_polygon` --- crates/fj-kernel/src/builder/face.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index a5a31bbea..fb5e74f61 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -15,6 +15,9 @@ pub trait FaceBuilder { points: impl IntoIterator>>, ) -> Vec>; + /// Update the face exterior as a polygon + fn update_exterior_as_polygon(&mut self); + /// Update the face exterior as a triangle, from 3D points /// /// Uses the three points to infer a plane that is used as the surface. @@ -45,6 +48,10 @@ impl FaceBuilder for PartialFace { self.exterior.write().update_as_polygon_from_points(points) } + fn update_exterior_as_polygon(&mut self) { + self.exterior.write().update_as_polygon() + } + fn update_exterior_as_triangle_from_global_points( &mut self, points_global: [impl Into>; 3],