diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index 1ba7c5a86..f75004188 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -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}; @@ -25,7 +25,7 @@ pub trait SweepFace { ) -> Shell; } -impl SweepFace for Face { +impl SweepFace for Handle { fn sweep_face( &self, path: impl Into>, @@ -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( @@ -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) - } -} diff --git a/crates/fj-core/src/operations/sweep/sketch.rs b/crates/fj-core/src/operations/sweep/sketch.rs index 34fb7651b..1b3ffebef 100644 --- a/crates/fj-core/src/operations/sweep/sketch.rs +++ b/crates/fj-core/src/operations/sweep/sketch.rs @@ -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, }; @@ -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 =