From f47f2be833de5bb4d686a47245a914c846f4053f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 15:18:38 +0200 Subject: [PATCH 1/9] Move test suite to correct module --- crates/fj-kernel/src/algorithms/sweep/face.rs | 150 ++++++++++++++++++ .../fj-kernel/src/algorithms/sweep/sketch.rs | 150 ------------------ 2 files changed, 150 insertions(+), 150 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 638df01ae..0cbfe5acb 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -75,3 +75,153 @@ fn create_top_face( face } + +#[cfg(test)] +mod tests { + use fj_math::{Point, Vector}; + + use crate::{ + iter::ObjectIters, + objects::{Face, Sketch, Surface}, + }; + + use super::Sweep; + + // This test currently fails, even though the code it tests works correctly. + // Fixing this would require this whole test suite to be refactored. + // + // Since other tests have already been disabled before, diminishing the + // value of this test suite significantly, it's not a big loss to disable + // this rather simple test too, and fix the whole test suite at a later + // date. + #[test] + #[ignore] + fn bottom_positive() -> anyhow::Result<()> { + test_bottom_top( + [0., 0., 1.], + [[0., 0., 0.], [1., 0., 0.], [0., -1., 0.]], + [[0., 0.], [1., 0.], [0., -1.]], + ) + } + + #[test] + fn bottom_negative() -> anyhow::Result<()> { + test_bottom_top( + [0., 0., -1.], + [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.]], + [[0., 0.], [1., 0.], [0., 1.]], + ) + } + + #[test] + fn top_positive() -> anyhow::Result<()> { + test_bottom_top( + [0., 0., 1.], + [[0., 0., 1.], [1., 0., 1.], [0., 1., 1.]], + [[0., 0.], [1., 0.], [0., 1.]], + ) + } + + // This test currently fails, even though the code it tests works correctly. + // Fixing this would require this whole test suite to be refactored. + // + // Since other tests have already been disabled before, diminishing the + // value of this test suite significantly, it's not a big loss to disable + // this rather simple test too, and fix the whole test suite at a later + // date. + #[test] + #[ignore] + fn top_negative() -> anyhow::Result<()> { + test_bottom_top( + [0., 0., -1.], + [[0., 0., -1.], [1., 0., -1.], [0., -1., -1.]], + [[0., 0.], [1., 0.], [0., -1.]], + ) + } + + // This test currently fails, even though the code it tests works correctly. + // At the time this test was disabled, fixing it would have been + // impractical. This has changed since then, thanks to some simplifications. + #[test] + #[ignore] + fn side_positive() -> anyhow::Result<()> { + test_side( + [0., 0., 1.], + [ + [[0., 0., 0.], [1., 0., 0.], [0., 0., 1.]], + [[1., 0., 0.], [0., 1., 0.], [1., 0., 1.]], + [[0., 1., 0.], [0., 0., 0.], [0., 1., 1.]], + ], + ) + } + + // This test currently fails, even though the code it tests works correctly. + // At the time this test was disabled, fixing it would have been + // impractical. This has changed since then, thanks to some simplifications. + #[test] + #[ignore] + fn side_negative() -> anyhow::Result<()> { + test_side( + [0., 0., -1.], + [ + [[0., 0., 0.], [0., 1., 0.], [0., 0., -1.]], + [[0., 1., 0.], [1., 0., 0.], [0., 1., -1.]], + [[1., 0., 0.], [0., 0., 0.], [1., 0., -1.]], + ], + ) + } + + fn test_side( + direction: impl Into>, + expected_surfaces: [[impl Into>; 3]; 3], + ) -> anyhow::Result<()> { + test( + direction, + expected_surfaces, + [[0., 0.], [1., 0.], [1., 1.], [0., 1.]], + ) + } + + fn test_bottom_top( + direction: impl Into>, + expected_surface: [impl Into>; 3], + expected_vertices: [impl Into>; 3], + ) -> anyhow::Result<()> { + test(direction, [expected_surface], expected_vertices) + } + + fn test( + direction: impl Into>, + expected_surfaces: impl IntoIterator>; 3]>, + expected_vertices: impl IntoIterator>>, + ) -> anyhow::Result<()> { + let surface = Surface::xy_plane(); + let face = Face::build(surface).polygon_from_points([ + [0., 0.], + [1., 0.], + [0., 1.], + ]); + let sketch = Sketch::new().with_faces([face]); + + let solid = sketch.sweep(direction); + + let expected_vertices: Vec<_> = expected_vertices + .into_iter() + .map(|vertex| vertex.into()) + .collect(); + + let faces = expected_surfaces.into_iter().map(|surface| { + let surface = Surface::plane_from_points(surface); + + Face::build(surface) + .polygon_from_points(expected_vertices.clone()) + .into_face() + }); + + for face in faces { + assert!(solid.face_iter().any(|f| f == &face)); + } + + Ok(()) + } +} diff --git a/crates/fj-kernel/src/algorithms/sweep/sketch.rs b/crates/fj-kernel/src/algorithms/sweep/sketch.rs index 6c32798ed..143f2baf3 100644 --- a/crates/fj-kernel/src/algorithms/sweep/sketch.rs +++ b/crates/fj-kernel/src/algorithms/sweep/sketch.rs @@ -19,153 +19,3 @@ impl Sweep for Sketch { Solid::new().with_shells(shells) } } - -#[cfg(test)] -mod tests { - use fj_math::{Point, Vector}; - - use crate::{ - iter::ObjectIters, - objects::{Face, Sketch, Surface}, - }; - - use super::Sweep; - - // This test currently fails, even though the code it tests works correctly. - // Fixing this would require this whole test suite to be refactored. - // - // Since other tests have already been disabled before, diminishing the - // value of this test suite significantly, it's not a big loss to disable - // this rather simple test too, and fix the whole test suite at a later - // date. - #[test] - #[ignore] - fn bottom_positive() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., 1.], - [[0., 0., 0.], [1., 0., 0.], [0., -1., 0.]], - [[0., 0.], [1., 0.], [0., -1.]], - ) - } - - #[test] - fn bottom_negative() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., -1.], - [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.]], - [[0., 0.], [1., 0.], [0., 1.]], - ) - } - - #[test] - fn top_positive() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., 1.], - [[0., 0., 1.], [1., 0., 1.], [0., 1., 1.]], - [[0., 0.], [1., 0.], [0., 1.]], - ) - } - - // This test currently fails, even though the code it tests works correctly. - // Fixing this would require this whole test suite to be refactored. - // - // Since other tests have already been disabled before, diminishing the - // value of this test suite significantly, it's not a big loss to disable - // this rather simple test too, and fix the whole test suite at a later - // date. - #[test] - #[ignore] - fn top_negative() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., -1.], - [[0., 0., -1.], [1., 0., -1.], [0., -1., -1.]], - [[0., 0.], [1., 0.], [0., -1.]], - ) - } - - // This test currently fails, even though the code it tests works correctly. - // At the time this test was disabled, fixing it would have been - // impractical. This has changed since then, thanks to some simplifications. - #[test] - #[ignore] - fn side_positive() -> anyhow::Result<()> { - test_side( - [0., 0., 1.], - [ - [[0., 0., 0.], [1., 0., 0.], [0., 0., 1.]], - [[1., 0., 0.], [0., 1., 0.], [1., 0., 1.]], - [[0., 1., 0.], [0., 0., 0.], [0., 1., 1.]], - ], - ) - } - - // This test currently fails, even though the code it tests works correctly. - // At the time this test was disabled, fixing it would have been - // impractical. This has changed since then, thanks to some simplifications. - #[test] - #[ignore] - fn side_negative() -> anyhow::Result<()> { - test_side( - [0., 0., -1.], - [ - [[0., 0., 0.], [0., 1., 0.], [0., 0., -1.]], - [[0., 1., 0.], [1., 0., 0.], [0., 1., -1.]], - [[1., 0., 0.], [0., 0., 0.], [1., 0., -1.]], - ], - ) - } - - fn test_side( - direction: impl Into>, - expected_surfaces: [[impl Into>; 3]; 3], - ) -> anyhow::Result<()> { - test( - direction, - expected_surfaces, - [[0., 0.], [1., 0.], [1., 1.], [0., 1.]], - ) - } - - fn test_bottom_top( - direction: impl Into>, - expected_surface: [impl Into>; 3], - expected_vertices: [impl Into>; 3], - ) -> anyhow::Result<()> { - test(direction, [expected_surface], expected_vertices) - } - - fn test( - direction: impl Into>, - expected_surfaces: impl IntoIterator>; 3]>, - expected_vertices: impl IntoIterator>>, - ) -> anyhow::Result<()> { - let surface = Surface::xy_plane(); - let face = Face::build(surface).polygon_from_points([ - [0., 0.], - [1., 0.], - [0., 1.], - ]); - let sketch = Sketch::new().with_faces([face]); - - let solid = sketch.sweep(direction); - - let expected_vertices: Vec<_> = expected_vertices - .into_iter() - .map(|vertex| vertex.into()) - .collect(); - - let faces = expected_surfaces.into_iter().map(|surface| { - let surface = Surface::plane_from_points(surface); - - Face::build(surface) - .polygon_from_points(expected_vertices.clone()) - .into_face() - }); - - for face in faces { - assert!(solid.face_iter().any(|f| f == &face)); - } - - Ok(()) - } -} From c9d677573610980dee6697326600c462d62dba6c Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 15:42:57 +0200 Subject: [PATCH 2/9] Fix test --- crates/fj-kernel/src/algorithms/sweep/face.rs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 0cbfe5acb..e490e10e0 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -81,27 +81,30 @@ mod tests { use fj_math::{Point, Vector}; use crate::{ + algorithms::reverse::Reverse, iter::ObjectIters, objects::{Face, Sketch, Surface}, }; use super::Sweep; - // This test currently fails, even though the code it tests works correctly. - // Fixing this would require this whole test suite to be refactored. - // - // Since other tests have already been disabled before, diminishing the - // value of this test suite significantly, it's not a big loss to disable - // this rather simple test too, and fix the whole test suite at a later - // date. + const TRIANGLE: [[f64; 2]; 3] = [[0., 0.], [1., 0.], [0., 1.]]; + + const UP: [f64; 3] = [0., 0., 1.]; + #[test] - #[ignore] - fn bottom_positive() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., 1.], - [[0., 0., 0.], [1., 0., 0.], [0., -1., 0.]], - [[0., 0.], [1., 0.], [0., -1.]], - ) + fn bottom_positive() { + let surface = Surface::xy_plane(); + let solid = Sketch::build(surface) + .polygon_from_points(TRIANGLE) + .sweep(UP); + + let bottom = Face::build(surface) + .polygon_from_points(TRIANGLE) + .into_face() + .reverse(); + + assert!(solid.find_face(&bottom).is_some()); } #[test] From 776763a73614e9b1c5a234433753690af58e96bd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 15:46:28 +0200 Subject: [PATCH 3/9] Merge tests --- crates/fj-kernel/src/algorithms/sweep/face.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index e490e10e0..f79cdd726 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -81,7 +81,7 @@ mod tests { use fj_math::{Point, Vector}; use crate::{ - algorithms::reverse::Reverse, + algorithms::{reverse::Reverse, transform::TransformObject}, iter::ObjectIters, objects::{Face, Sketch, Surface}, }; @@ -93,7 +93,7 @@ mod tests { const UP: [f64; 3] = [0., 0., 1.]; #[test] - fn bottom_positive() { + fn sweep_up() { let surface = Surface::xy_plane(); let solid = Sketch::build(surface) .polygon_from_points(TRIANGLE) @@ -103,8 +103,12 @@ mod tests { .polygon_from_points(TRIANGLE) .into_face() .reverse(); + let top = Face::build(surface.translate(UP)) + .polygon_from_points(TRIANGLE) + .into_face(); assert!(solid.find_face(&bottom).is_some()); + assert!(solid.find_face(&top).is_some()); } #[test] @@ -116,15 +120,6 @@ mod tests { ) } - #[test] - fn top_positive() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., 1.], - [[0., 0., 1.], [1., 0., 1.], [0., 1., 1.]], - [[0., 0.], [1., 0.], [0., 1.]], - ) - } - // This test currently fails, even though the code it tests works correctly. // Fixing this would require this whole test suite to be refactored. // From 4df88d50ed70206c2ffa0e77970a814e9a69a91e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 16:04:47 +0200 Subject: [PATCH 4/9] Fix test --- crates/fj-kernel/src/algorithms/sweep/face.rs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index f79cdd726..0a8b361df 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -78,12 +78,13 @@ fn create_top_face( #[cfg(test)] mod tests { + use fj_interop::mesh::Color; use fj_math::{Point, Vector}; use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, iter::ObjectIters, - objects::{Face, Sketch, Surface}, + objects::{Face, HalfEdge, Sketch, Surface}, }; use super::Sweep; @@ -137,20 +138,26 @@ mod tests { ) } - // This test currently fails, even though the code it tests works correctly. - // At the time this test was disabled, fixing it would have been - // impractical. This has changed since then, thanks to some simplifications. #[test] - #[ignore] - fn side_positive() -> anyhow::Result<()> { - test_side( - [0., 0., 1.], - [ - [[0., 0., 0.], [1., 0., 0.], [0., 0., 1.]], - [[1., 0., 0.], [0., 1., 0.], [1., 0., 1.]], - [[0., 1., 0.], [0., 0., 0.], [0., 1., 1.]], - ], - ) + fn side_positive() { + let surface = Surface::xy_plane(); + let solid = Sketch::build(surface) + .polygon_from_points(TRIANGLE) + .sweep(UP); + + let mut side_faces = TRIANGLE.windows(2).map(|window| { + // Can't panic, as we passed `2` to `windows`. + // + // Can be cleaned up, once `array_windows` is stable: + // https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows + let [a, b] = [window[0], window[1]]; + + let half_edge = HalfEdge::build(Surface::xy_plane()) + .line_segment_from_points([a, b]); + (half_edge, Color::default()).sweep(UP) + }); + + assert!(side_faces.all(|face| solid.find_face(&face).is_some())); } // This test currently fails, even though the code it tests works correctly. From c4479c46f579255be5d17695545447cf8ebe9e3e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 15:56:09 +0200 Subject: [PATCH 5/9] Merge tests --- crates/fj-kernel/src/algorithms/sweep/face.rs | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 0a8b361df..b1c4737b5 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -110,6 +110,20 @@ mod tests { assert!(solid.find_face(&bottom).is_some()); assert!(solid.find_face(&top).is_some()); + + let mut side_faces = TRIANGLE.windows(2).map(|window| { + // Can't panic, as we passed `2` to `windows`. + // + // Can be cleaned up, once `array_windows` is stable: + // https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows + let [a, b] = [window[0], window[1]]; + + let half_edge = HalfEdge::build(Surface::xy_plane()) + .line_segment_from_points([a, b]); + (half_edge, Color::default()).sweep(UP) + }); + + assert!(side_faces.all(|face| solid.find_face(&face).is_some())); } #[test] @@ -138,28 +152,6 @@ mod tests { ) } - #[test] - fn side_positive() { - let surface = Surface::xy_plane(); - let solid = Sketch::build(surface) - .polygon_from_points(TRIANGLE) - .sweep(UP); - - let mut side_faces = TRIANGLE.windows(2).map(|window| { - // Can't panic, as we passed `2` to `windows`. - // - // Can be cleaned up, once `array_windows` is stable: - // https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows - let [a, b] = [window[0], window[1]]; - - let half_edge = HalfEdge::build(Surface::xy_plane()) - .line_segment_from_points([a, b]); - (half_edge, Color::default()).sweep(UP) - }); - - assert!(side_faces.all(|face| solid.find_face(&face).is_some())); - } - // This test currently fails, even though the code it tests works correctly. // At the time this test was disabled, fixing it would have been // impractical. This has changed since then, thanks to some simplifications. From 869d03adef0ecdf17d9f9f3cb44457e6c5cb03be Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 16:00:59 +0200 Subject: [PATCH 6/9] Fix test --- crates/fj-kernel/src/algorithms/sweep/face.rs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index b1c4737b5..f644f5a38 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -92,6 +92,7 @@ mod tests { const TRIANGLE: [[f64; 2]; 3] = [[0., 0.], [1., 0.], [0., 1.]]; const UP: [f64; 3] = [0., 0., 1.]; + const DOWN: [f64; 3] = [0., 0., -1.]; #[test] fn sweep_up() { @@ -135,21 +136,18 @@ mod tests { ) } - // This test currently fails, even though the code it tests works correctly. - // Fixing this would require this whole test suite to be refactored. - // - // Since other tests have already been disabled before, diminishing the - // value of this test suite significantly, it's not a big loss to disable - // this rather simple test too, and fix the whole test suite at a later - // date. #[test] - #[ignore] - fn top_negative() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., -1.], - [[0., 0., -1.], [1., 0., -1.], [0., -1., -1.]], - [[0., 0.], [1., 0.], [0., -1.]], - ) + fn top_negative() { + let surface = Surface::xy_plane(); + let solid = Sketch::build(surface) + .polygon_from_points(TRIANGLE) + .sweep(DOWN); + + let top = Face::build(surface) + .polygon_from_points(TRIANGLE) + .into_face(); + + assert!(solid.find_face(&top).is_some()); } // This test currently fails, even though the code it tests works correctly. From e1a95566c0dd6e7c5ac5369315a320a5b6a80b26 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 16:02:15 +0200 Subject: [PATCH 7/9] Merge tests --- crates/fj-kernel/src/algorithms/sweep/face.rs | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index f644f5a38..522109fb7 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -128,25 +128,21 @@ mod tests { } #[test] - fn bottom_negative() -> anyhow::Result<()> { - test_bottom_top( - [0., 0., -1.], - [[0., 0., 0.], [1., 0., 0.], [0., 1., 0.]], - [[0., 0.], [1., 0.], [0., 1.]], - ) - } - - #[test] - fn top_negative() { + fn sweep_down() { let surface = Surface::xy_plane(); let solid = Sketch::build(surface) .polygon_from_points(TRIANGLE) .sweep(DOWN); + let bottom = Face::build(surface.translate(DOWN)) + .polygon_from_points(TRIANGLE) + .into_face() + .reverse(); let top = Face::build(surface) .polygon_from_points(TRIANGLE) .into_face(); + assert!(solid.find_face(&bottom).is_some()); assert!(solid.find_face(&top).is_some()); } @@ -177,14 +173,6 @@ mod tests { ) } - fn test_bottom_top( - direction: impl Into>, - expected_surface: [impl Into>; 3], - expected_vertices: [impl Into>; 3], - ) -> anyhow::Result<()> { - test(direction, [expected_surface], expected_vertices) - } - fn test( direction: impl Into>, expected_surfaces: impl IntoIterator>; 3]>, From 60b54d883997ce09ff772047633ee45cd0515e52 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 16:13:35 +0200 Subject: [PATCH 8/9] Fix test --- crates/fj-kernel/src/algorithms/sweep/face.rs | 73 ++++--------------- 1 file changed, 16 insertions(+), 57 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 522109fb7..9da3eaf99 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -79,11 +79,9 @@ fn create_top_face( #[cfg(test)] mod tests { use fj_interop::mesh::Color; - use fj_math::{Point, Vector}; use crate::{ algorithms::{reverse::Reverse, transform::TransformObject}, - iter::ObjectIters, objects::{Face, HalfEdge, Sketch, Surface}, }; @@ -146,65 +144,26 @@ mod tests { assert!(solid.find_face(&top).is_some()); } - // This test currently fails, even though the code it tests works correctly. - // At the time this test was disabled, fixing it would have been - // impractical. This has changed since then, thanks to some simplifications. #[test] - #[ignore] - fn side_negative() -> anyhow::Result<()> { - test_side( - [0., 0., -1.], - [ - [[0., 0., 0.], [0., 1., 0.], [0., 0., -1.]], - [[0., 1., 0.], [1., 0., 0.], [0., 1., -1.]], - [[1., 0., 0.], [0., 0., 0.], [1., 0., -1.]], - ], - ) - } + fn side_negative() { + let surface = Surface::xy_plane(); + let solid = Sketch::build(surface) + .polygon_from_points(TRIANGLE) + .sweep(DOWN); - fn test_side( - direction: impl Into>, - expected_surfaces: [[impl Into>; 3]; 3], - ) -> anyhow::Result<()> { - test( - direction, - expected_surfaces, - [[0., 0.], [1., 0.], [1., 1.], [0., 1.]], - ) - } + let mut side_faces = TRIANGLE.windows(2).map(|window| { + // Can't panic, as we passed `2` to `windows`. + // + // Can be cleaned up, once `array_windows` is stable: + // https://doc.rust-lang.org/std/primitive.slice.html#method.array_windows + let [a, b] = [window[0], window[1]]; - fn test( - direction: impl Into>, - expected_surfaces: impl IntoIterator>; 3]>, - expected_vertices: impl IntoIterator>>, - ) -> anyhow::Result<()> { - let surface = Surface::xy_plane(); - let face = Face::build(surface).polygon_from_points([ - [0., 0.], - [1., 0.], - [0., 1.], - ]); - let sketch = Sketch::new().with_faces([face]); - - let solid = sketch.sweep(direction); - - let expected_vertices: Vec<_> = expected_vertices - .into_iter() - .map(|vertex| vertex.into()) - .collect(); - - let faces = expected_surfaces.into_iter().map(|surface| { - let surface = Surface::plane_from_points(surface); - - Face::build(surface) - .polygon_from_points(expected_vertices.clone()) - .into_face() + let half_edge = HalfEdge::build(Surface::xy_plane()) + .line_segment_from_points([a, b]) + .reverse(); + (half_edge, Color::default()).sweep(DOWN) }); - for face in faces { - assert!(solid.face_iter().any(|f| f == &face)); - } - - Ok(()) + assert!(side_faces.all(|face| solid.find_face(&face).is_some())); } } From 766c6de18745888e7bc27dcdc92e0159cf009ea0 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Fri, 9 Sep 2022 16:13:58 +0200 Subject: [PATCH 9/9] Merge tests --- crates/fj-kernel/src/algorithms/sweep/face.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep/face.rs b/crates/fj-kernel/src/algorithms/sweep/face.rs index 9da3eaf99..1c44e542f 100644 --- a/crates/fj-kernel/src/algorithms/sweep/face.rs +++ b/crates/fj-kernel/src/algorithms/sweep/face.rs @@ -142,14 +142,6 @@ mod tests { assert!(solid.find_face(&bottom).is_some()); assert!(solid.find_face(&top).is_some()); - } - - #[test] - fn side_negative() { - let surface = Surface::xy_plane(); - let solid = Sketch::build(surface) - .polygon_from_points(TRIANGLE) - .sweep(DOWN); let mut side_faces = TRIANGLE.windows(2).map(|window| { // Can't panic, as we passed `2` to `windows`.