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

Make face sweeping simpler and more flexible #2114

Merged
merged 3 commits into from
Nov 28, 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
33 changes: 5 additions & 28 deletions crates/fj-core/src/operations/sweep/face.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use fj_math::{Scalar, Vector};
use fj_math::Vector;

use crate::{
algorithms::transform::TransformObject,
geometry::GlobalPath,
objects::{Face, Shell},
operations::{insert::Insert, reverse::Reverse},
operations::insert::Insert,
services::Services,
storage::Handle,
};

use super::{SweepCache, SweepRegion};
Expand All @@ -25,7 +25,7 @@ pub trait SweepFace {
) -> Shell;
}

impl SweepFace for Face {
impl SweepFace for Handle<Face> {
fn sweep_face(
&self,
path: impl Into<Vector<3>>,
Expand All @@ -49,7 +49,7 @@ impl SweepFace for Face {

let mut faces = Vec::new();

let bottom_face = bottom_face(self, path, services).insert(services);
let bottom_face = self.clone();
faces.push(bottom_face.clone());

let swept_region = bottom_face.region().sweep_region(
Expand Down Expand Up @@ -77,26 +77,3 @@ impl SweepFace for Face {
Shell::new(faces)
}
}

fn bottom_face(face: &Face, path: Vector<3>, services: &mut Services) -> Face {
let is_negative_sweep = {
let u = match face.surface().geometry().u {
GlobalPath::Circle(_) => todo!(
"Sweeping from faces defined in rounded surfaces is not \
supported"
),
GlobalPath::Line(line) => line.direction(),
};
let v = face.surface().geometry().v;

let normal = u.cross(&v);

normal.dot(&path) < Scalar::ZERO
};

if is_negative_sweep {
face.clone()
} else {
face.reverse(services)
}
}
32 changes: 30 additions & 2 deletions crates/fj-core/src/operations/sweep/sketch.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use fj_math::Vector;
use fj_math::{Scalar, Vector};

use crate::{
geometry::GlobalPath,
objects::{Face, Sketch, Solid, Surface},
operations::insert::Insert,
operations::{insert::Insert, reverse::Reverse},
services::Services,
storage::Handle,
};
Expand Down Expand Up @@ -36,6 +37,33 @@ impl SweepSketch for Sketch {

let mut shells = Vec::new();
for region in self.regions() {
let region = {
// The following code assumes that the sketch is winded counter-
// clockwise. Let's check that real quick.
assert!(region.exterior().winding().is_ccw());

let is_negative_sweep = {
let u = match surface.geometry().u {
GlobalPath::Circle(_) => todo!(
"Sweeping sketch from a rounded surfaces is not \
supported"
),
GlobalPath::Line(line) => line.direction(),
};
let v = surface.geometry().v;

let normal = u.cross(&v);

normal.dot(&path) < Scalar::ZERO
};

if is_negative_sweep {
region.clone()
} else {
region.reverse(services).insert(services)
}
};

let face =
Face::new(surface.clone(), region.clone()).insert(services);
let shell =
Expand Down