From 63290e9665c8470d891dee5487eb703f78648950 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 12:44:21 +0100 Subject: [PATCH 1/2] Add `SweptRegion` --- crates/fj-core/src/operations/sweep/mod.rs | 2 +- crates/fj-core/src/operations/sweep/region.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/sweep/mod.rs b/crates/fj-core/src/operations/sweep/mod.rs index 729307455..9ed29c1ff 100644 --- a/crates/fj-core/src/operations/sweep/mod.rs +++ b/crates/fj-core/src/operations/sweep/mod.rs @@ -17,7 +17,7 @@ pub use self::{ face::SweepFace, half_edge::SweepHalfEdge, path::SweepSurfacePath, - region::SweepRegion, + region::{SweepRegion, SweptRegion}, shell_face::SweepFaceOfShell, sketch::SweepSketch, vertex::SweepVertex, diff --git a/crates/fj-core/src/operations/sweep/region.rs b/crates/fj-core/src/operations/sweep/region.rs index f61a548ff..f7b9ae9b7 100644 --- a/crates/fj-core/src/operations/sweep/region.rs +++ b/crates/fj-core/src/operations/sweep/region.rs @@ -111,3 +111,21 @@ fn sweep_cycle( swept_cycle.top_cycle.insert(services) } + +/// The result of sweeping a [`Region`] +/// +/// See [`SweepRegion`]. +pub struct SweptRegion { + /// The side faces created by the sweep + pub side_faces: Vec, + + /// The top face created by the sweep + pub top_face: Face, +} + +impl SweptRegion { + /// Return an iterator over all of the faces + pub fn all_faces(self) -> impl Iterator { + self.side_faces.into_iter().chain([self.top_face]) + } +} From a83b277fdde64f5793b8ea4223f97a6e22e151e4 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 12 Dec 2023 12:44:42 +0100 Subject: [PATCH 2/2] Return `SweptRegion` from region sweeping op --- crates/fj-core/src/operations/holes.rs | 2 +- crates/fj-core/src/operations/sweep/face.rs | 2 +- crates/fj-core/src/operations/sweep/region.rs | 10 ++++++---- crates/fj-core/src/operations/sweep/shell_face.rs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/fj-core/src/operations/holes.rs b/crates/fj-core/src/operations/holes.rs index 20d90a5ab..b9f9ada6e 100644 --- a/crates/fj-core/src/operations/holes.rs +++ b/crates/fj-core/src/operations/holes.rs @@ -50,7 +50,7 @@ impl AddHole for Shell { &mut SweepCache::default(), services, ) - .into_iter() + .all_faces() .map(|face| face.insert(services)) .collect::>(); diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index 5e4ce5c2c..212b40cbc 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -54,7 +54,7 @@ impl SweepFace for Handle { let side_faces = bottom_face .region() .sweep_region(bottom_face.surface(), path, cache, services) - .into_iter() + .all_faces() .map(|side_face| side_face.insert(services)); faces.extend(side_faces); diff --git a/crates/fj-core/src/operations/sweep/region.rs b/crates/fj-core/src/operations/sweep/region.rs index f7b9ae9b7..426357a50 100644 --- a/crates/fj-core/src/operations/sweep/region.rs +++ b/crates/fj-core/src/operations/sweep/region.rs @@ -34,7 +34,7 @@ pub trait SweepRegion { path: impl Into>, cache: &mut SweepCache, services: &mut Services, - ) -> Vec; + ) -> SweptRegion; } impl SweepRegion for Region { @@ -44,7 +44,7 @@ impl SweepRegion for Region { path: impl Into>, cache: &mut SweepCache, services: &mut Services, - ) -> Vec { + ) -> SweptRegion { let path = path.into(); let mut faces = Vec::new(); @@ -84,9 +84,11 @@ impl SweepRegion for Region { Face::new(top_surface, top_region) }; - faces.push(top_face); - faces + SweptRegion { + top_face, + side_faces: faces, + } } } diff --git a/crates/fj-core/src/operations/sweep/shell_face.rs b/crates/fj-core/src/operations/sweep/shell_face.rs index 5632c295e..f26b6de1c 100644 --- a/crates/fj-core/src/operations/sweep/shell_face.rs +++ b/crates/fj-core/src/operations/sweep/shell_face.rs @@ -57,7 +57,7 @@ impl SweepFaceOfShell for Shell { let region = Region::new(exterior, [], face.region().color()); let faces = region .sweep_region(face.surface(), path, &mut cache, services) - .into_iter() + .all_faces() .map(|face| face.insert(services)); self.remove_face(&face).add_faces(faces)