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 SweepFaceOfShell #2121

Merged
merged 3 commits into from
Nov 29, 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: 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)
}