From dceeadc855458feaebc87f81227e2481929050e7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 3 Mar 2022 14:13:06 +0100 Subject: [PATCH] Fix sweeping of un-symmetrical sketches This fixes #230, while making #173 worse (now all bottom faces of extruded shapes are black). I think this is an acceptable trade-off, as it enables some progress with the sweep code, without requiring more infrastructure work right away. --- src/kernel/algorithms/sweep.rs | 58 +++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/src/kernel/algorithms/sweep.rs b/src/kernel/algorithms/sweep.rs index bcd0478c7..06b786499 100644 --- a/src/kernel/algorithms/sweep.rs +++ b/src/kernel/algorithms/sweep.rs @@ -1,8 +1,3 @@ -use std::f64::consts::PI; - -use nalgebra::vector; -use parry3d_f64::math::Isometry; - use crate::{ kernel::topology::{ faces::{Face, Faces}, @@ -21,7 +16,6 @@ pub fn sweep_shape( ) -> Shape { let mut shape = Shape::new(); - let rotation = Isometry::rotation(vector![PI, 0., 0.]).into(); let translation = Transform::translation(path); let mut bottom_faces = Vec::new(); @@ -29,12 +23,7 @@ pub fn sweep_shape( let mut side_faces = Vec::new(); for face in &original.faces.0 { - // This only works for faces that are symmetric to the x-axis. - // - // See issue: - // https://github.com/hannobraun/Fornjot/issues/230 - bottom_faces.push(transform_face(face, &rotation, &mut shape)); - + bottom_faces.push(face.clone()); top_faces.push(transform_face(face, &translation, &mut shape)); } @@ -75,3 +64,48 @@ pub fn sweep_shape( shape } + +#[cfg(test)] +mod tests { + use crate::{ + kernel::{ + geometry::Surface, + topology::{ + edges::{Edge, Edges}, + faces::Face, + Shape, + }, + }, + math::{Point, Scalar, Vector}, + }; + + use super::sweep_shape; + + #[test] + fn bottom_face() { + let mut original = Shape::new(); + + let a = original.vertices().create(Point::from([0., 0., 0.])); + let b = original.vertices().create(Point::from([1., 0., 0.])); + let c = original.vertices().create(Point::from([0., 1., 0.])); + + let ab = Edge::line_segment([a, b]); + let bc = Edge::line_segment([b, c]); + let ca = Edge::line_segment([c, a]); + + let face = Face::Face { + surface: Surface::x_y_plane(), + edges: Edges::single_cycle([ab, bc, ca]), + }; + + original.faces.0.push(face.clone()); + + let swept = sweep_shape( + &original, + Vector::from([0., 0., 1.]), + Scalar::from_f64(0.), + ); + + assert!(swept.faces.0.contains(&face)); + } +}