Skip to content

Commit

Permalink
Merge pull request #2114 from hannobraun/sweep
Browse files Browse the repository at this point in the history
Make face sweeping simpler and more flexible
  • Loading branch information
hannobraun authored Nov 28, 2023
2 parents 3cc3760 + 1691928 commit d83fa6f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
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

0 comments on commit d83fa6f

Please sign in to comment.