From 5e526a74ae8aede2d02de5def257c58b67e6ec2e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 21 Sep 2022 11:39:03 +0200 Subject: [PATCH] Add additional method to `FaceBuilder` --- .../src/algorithms/intersect/curve_face.rs | 2 +- .../src/algorithms/triangulate/mod.rs | 2 +- crates/fj-kernel/src/builder/face.rs | 18 +++++++++++++++++- crates/fj-kernel/src/objects/face.rs | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs index 2223257e9..b33643310 100644 --- a/crates/fj-kernel/src/algorithms/intersect/curve_face.rs +++ b/crates/fj-kernel/src/algorithms/intersect/curve_face.rs @@ -188,8 +188,8 @@ mod tests { let face = Face::builder(&stores, surface) .with_exterior_polygon_from_points(exterior) + .with_interior_polygon_from_points(interior) .build() - .with_hole(interior) .into_face(); let expected = diff --git a/crates/fj-kernel/src/algorithms/triangulate/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs index 26445c39b..8c8ae8e57 100644 --- a/crates/fj-kernel/src/algorithms/triangulate/mod.rs +++ b/crates/fj-kernel/src/algorithms/triangulate/mod.rs @@ -137,8 +137,8 @@ mod tests { let surface = Surface::xy_plane(); let face = Face::builder(&stores, surface) .with_exterior_polygon_from_points([a, b, c, d]) + .with_interior_polygon_from_points([e, f, g, h]) .build() - .with_hole([e, f, g, h]) .into_face(); let triangles = triangulate(face)?; diff --git a/crates/fj-kernel/src/builder/face.rs b/crates/fj-kernel/src/builder/face.rs index f0fcb389f..4fc65c8d9 100644 --- a/crates/fj-kernel/src/builder/face.rs +++ b/crates/fj-kernel/src/builder/face.rs @@ -22,6 +22,9 @@ pub struct FaceBuilder<'a> { /// Must be provided by the caller, directly or using one of the `with_` /// methods, before [`FaceBuilder::build`] is called. pub exterior: Option, + + /// The interior cycles that form holes in the [`Face`] + pub interiors: Vec, } impl<'a> FaceBuilder<'a> { @@ -37,12 +40,25 @@ impl<'a> FaceBuilder<'a> { self } + /// Build the [`Face`] with an interior polygon from the provided points + pub fn with_interior_polygon_from_points( + mut self, + points: impl IntoIterator>>, + ) -> Self { + self.interiors.push( + Cycle::builder(self.stores, self.surface) + .build_polygon_from_points(points), + ); + self + } + /// Construct a polygon from a list of points pub fn build(self) -> FacePolygon<'a> { let exterior = self .exterior .expect("Can't build `Face` without exterior cycle"); - let face = Face::new(self.surface, exterior); + let face = + Face::new(self.surface, exterior).with_interiors(self.interiors); FacePolygon { stores: self.stores, diff --git a/crates/fj-kernel/src/objects/face.rs b/crates/fj-kernel/src/objects/face.rs index 540257d0b..948603d94 100644 --- a/crates/fj-kernel/src/objects/face.rs +++ b/crates/fj-kernel/src/objects/face.rs @@ -71,6 +71,7 @@ impl Face { stores, surface, exterior: None, + interiors: Vec::new(), } }