Skip to content

Commit

Permalink
Add additional method to FaceBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Sep 21, 2022
1 parent 7f287bf commit 5e526a7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/intersect/curve_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-kernel/src/algorithms/triangulate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
18 changes: 17 additions & 1 deletion crates/fj-kernel/src/builder/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cycle>,

/// The interior cycles that form holes in the [`Face`]
pub interiors: Vec<Cycle>,
}

impl<'a> FaceBuilder<'a> {
Expand All @@ -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<Item = impl Into<Point<2>>>,
) -> 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,
Expand Down
1 change: 1 addition & 0 deletions crates/fj-kernel/src/objects/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl Face {
stores,
surface,
exterior: None,
interiors: Vec::new(),
}
}

Expand Down

0 comments on commit 5e526a7

Please sign in to comment.