From 5922c8ea83a6e025403e5376f5edf93a7cc5288c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 17:33:51 +0100 Subject: [PATCH 1/3] Implement `SweepFace` for `Handle` This is a reversal of an earlier decision, and prepares for an upcoming simplification. --- crates/fj-core/src/operations/sweep/face.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index 1ba7c5a86..ed45f2f9d 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -6,6 +6,7 @@ use crate::{ objects::{Face, Shell}, operations::{insert::Insert, reverse::Reverse}, services::Services, + storage::Handle, }; use super::{SweepCache, SweepRegion}; @@ -25,7 +26,7 @@ pub trait SweepFace { ) -> Shell; } -impl SweepFace for Face { +impl SweepFace for Handle { fn sweep_face( &self, path: impl Into>, From f56986bbc0af47b8e545d80c6487cf657bff231d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 28 Nov 2023 17:25:03 +0100 Subject: [PATCH 2/3] Make sketch sweeping code more robust Make sure to create a face that will always end up an exterior face, regardless of surface coordinate system and direction of the sweep path. This is preparation for making the face sweeping code a bit dumber, but more flexible. --- crates/fj-core/src/operations/sweep/sketch.rs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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 = From 1691928317175c3fde59f7ba4c2fc2bdc1f343fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 24 Nov 2023 17:43:32 +0100 Subject: [PATCH 3/3] Make face sweeping code simpler and more flexible By always using the original face as the bottom, it should now be relatively straight-forward to create shells whose faces are facing inside. This is useful for creating cavities within a solid, for example. --- crates/fj-core/src/operations/sweep/face.rs | 30 +++------------------ 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/crates/fj-core/src/operations/sweep/face.rs b/crates/fj-core/src/operations/sweep/face.rs index ed45f2f9d..f75004188 100644 --- a/crates/fj-core/src/operations/sweep/face.rs +++ b/crates/fj-core/src/operations/sweep/face.rs @@ -1,10 +1,9 @@ -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, }; @@ -50,7 +49,7 @@ impl SweepFace for Handle { 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( @@ -78,26 +77,3 @@ impl SweepFace for Handle { 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) - } -}