Skip to content

Commit

Permalink
Merge pull request #2121 from hannobraun/sweep
Browse files Browse the repository at this point in the history
Add `SweepFaceOfShell`
  • Loading branch information
hannobraun authored Nov 29, 2023
2 parents 1cb5f4a + ad0e25b commit d66d20e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/fj-core/src/operations/sweep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod face;
mod half_edge;
mod path;
mod region;
mod shell_face;
mod sketch;
mod vertex;

Expand All @@ -17,6 +18,7 @@ pub use self::{
half_edge::SweepHalfEdge,
path::SweepSurfacePath,
region::SweepRegion,
shell_face::SweepFaceOfShell,
sketch::SweepSketch,
vertex::SweepVertex,
};
Expand Down
65 changes: 65 additions & 0 deletions crates/fj-core/src/operations/sweep/shell_face.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use fj_math::Vector;

use crate::{
objects::{Face, Region, Shell},
operations::{
insert::Insert,
reverse::Reverse,
sweep::{SweepCache, SweepRegion},
update::UpdateShell,
},
services::Services,
storage::Handle,
};

/// # Sweep a [`Face`] that is part of a [`Shell`]
///
/// See [module documentation] for more information.
///
/// [module documentation]: super
pub trait SweepFaceOfShell {
/// # Sweep the [`Face`] of the [`Shell`]
///
/// Extends the shell, adding the new faces to it.
///
/// # Panics
///
/// Panics, if the face has interior cycles. This is not a fundamental
/// limitation, but none the less not yet supported.
fn sweep_face_of_shell(
&self,
face: Handle<Face>,
path: impl Into<Vector<3>>,
services: &mut Services,
) -> Self;
}

impl SweepFaceOfShell for Shell {
fn sweep_face_of_shell(
&self,
face: Handle<Face>,
path: impl Into<Vector<3>>,
services: &mut Services,
) -> Self {
let path = path.into();

if !face.region().interiors().is_empty() {
todo!(
"Sweeping shell faces with interior cycles is not yet \
supported."
)
}

let mut cache = SweepCache::default();

let exterior =
face.region().exterior().reverse(services).insert(services);
let region = Region::new(exterior, [], face.region().color());
let faces = region
.sweep_region(face.surface(), path, &mut cache, services)
.into_iter()
.map(|face| face.insert(services));

self.remove_face(&face).add_faces(faces)
}
}
8 changes: 6 additions & 2 deletions models/split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fj::{
build::{BuildRegion, BuildSketch},
insert::Insert,
split::SplitFace,
sweep::SweepSketch,
sweep::{SweepFaceOfShell, SweepSketch},
update::{UpdateSketch, UpdateSolid},
},
services::Services,
Expand Down Expand Up @@ -46,7 +46,11 @@ pub fn model(
(cycle.half_edges().nth(2).unwrap(), [split_pos]),
];

shell.split_face(face, line, services).0.insert(services)
let (shell, [face, _]) = shell.split_face(face, line, services);

shell
.sweep_face_of_shell(face, [0., 0., -size / 2.], services)
.insert(services)
})
.insert(services)
}

0 comments on commit d66d20e

Please sign in to comment.