Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SweptRegion #2137

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/holes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl AddHole for Shell {
&mut SweepCache::default(),
services,
)
.into_iter()
.all_faces()
.map(|face| face.insert(services))
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl SweepFace for Handle<Face> {
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);

Expand Down
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 24 additions & 4 deletions crates/fj-core/src/operations/sweep/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub trait SweepRegion {
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
services: &mut Services,
) -> Vec<Face>;
) -> SweptRegion;
}

impl SweepRegion for Region {
Expand All @@ -44,7 +44,7 @@ impl SweepRegion for Region {
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
services: &mut Services,
) -> Vec<Face> {
) -> SweptRegion {
let path = path.into();

let mut faces = Vec::new();
Expand Down Expand Up @@ -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,
}
}
}

Expand All @@ -111,3 +113,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<Face>,

/// 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<Item = Face> {
self.side_faces.into_iter().chain([self.top_face])
}
}
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/shell_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down