Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sweeping of un-symmetrical sketches #284

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 46 additions & 12 deletions src/kernel/algorithms/sweep.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
use std::f64::consts::PI;

use nalgebra::vector;
use parry3d_f64::math::Isometry;

use crate::{
kernel::topology::{
faces::{Face, Faces},
Expand All @@ -21,20 +16,14 @@ 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();
let mut top_faces = Vec::new();
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));
}

Expand Down Expand Up @@ -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));
}
}