From 96e4d539318b1d11be471ba07a4a2ae28e052448 Mon Sep 17 00:00:00 2001 From: gabsi26 Date: Tue, 24 May 2022 16:23:13 +0200 Subject: [PATCH 1/2] Invert surface for negative sweep path (only top and bottom) Checks if the path points in negative z-direction and flips surface normal accordingly this is sufficient as long as sketches are always drawn in the xy-plane if this ever changes this has to be revisited Signed-off-by: gabsi26 --- crates/fj-kernel/src/algorithms/sweep.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index 6ef9b3cea8..525ecbc855 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -20,12 +20,18 @@ pub fn sweep_shape( let translation = Transform::translation(path); let (mut bottom, source_to_bottom) = source.clone_shape(); - bottom - .update() - .update_all(|surface: &mut Surface| *surface = surface.reverse()) - .validate()?; - let (mut top, source_to_top) = source.clone_shape(); + + if path.dot(&Vector::from([0., 0., 1.])) >= fj_math::Scalar::from_f64(0.) { + bottom + .update() + .update_all(|surface: &mut Surface| *surface = surface.reverse()) + .validate()?; + } else { + top.update() + .update_all(|surface: &mut Surface| *surface = surface.reverse()) + .validate()?; + } transform_shape(&mut top, &translation); let mut target = Shape::new(); From b9384abc647d3ea47baae6af255c7c2df1ac6a94 Mon Sep 17 00:00:00 2001 From: gabsi26 Date: Tue, 24 May 2022 17:26:40 +0200 Subject: [PATCH 2/2] Sides of sweep are now also flipped if needed Signed-off-by: gabsi26 --- crates/fj-kernel/src/algorithms/sweep.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index 525ecbc855..2b20aded91 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -124,11 +124,22 @@ pub fn sweep_shape( let top_edge = source_to_top.edges().get(&edge_source).unwrap().clone(); - let surface = + let surface = if path.dot(&Vector::from([0., 0., 1.])) + >= fj_math::Scalar::from_f64(0.) + { target.insert(Surface::SweptCurve(SweptCurve { curve: bottom_edge.get().curve(), path, - }))?; + }))? + } else { + target.insert( + Surface::SweptCurve(SweptCurve { + curve: bottom_edge.get().curve(), + path, + }) + .reverse(), //////////////////////////////////// + )? + }; let cycle = target.merge(Cycle::new(vec![ bottom_edge,