From af031b18c81d7d5feb23c4cac17e505c5d839ac5 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Wed, 21 Jan 2026 16:51:37 +0400 Subject: [PATCH 1/2] =?UTF-8?q?add=20corner=E2=80=91case=20tests=20for=20v?= =?UTF-8?q?ector=20simplify?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOverlay/src/vector/simplify.rs | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/iOverlay/src/vector/simplify.rs b/iOverlay/src/vector/simplify.rs index 2de577b..25e751f 100644 --- a/iOverlay/src/vector/simplify.rs +++ b/iOverlay/src/vector/simplify.rs @@ -258,4 +258,76 @@ mod tests { debug_assert!(result); debug_assert!(contour.len() == 4); } + + #[test] + fn test_duplicate_points() { + #[rustfmt::skip] + let mut contour = vec![ + VectorEdge::new(1, int_pnt!(-1, 3), int_pnt!(-1, 1)), + VectorEdge::new(2, int_pnt!(-1, 3), int_pnt!(-1, 1)), + VectorEdge::new(3, int_pnt!(-1, 1), int_pnt!(-3, 1)), + VectorEdge::new(4, int_pnt!(-3, 1), int_pnt!(-3, -2)), + VectorEdge::new(5, int_pnt!(-3, -2), int_pnt!(3, -2)), + VectorEdge::new(6, int_pnt!(3, -2), int_pnt!(3, 1)), + VectorEdge::new(7, int_pnt!(3, -2), int_pnt!(1, 1)), + VectorEdge::new(8, int_pnt!(1, 1), int_pnt!(1, 3)), + VectorEdge::new(9, int_pnt!(1, 3), int_pnt!(-1, 3)), + VectorEdge::new(10, int_pnt!(-1, 3), int_pnt!(-1, -1)), + ]; + + let result = contour.simplify_contour(); + + debug_assert!(result); + debug_assert!(contour.len() == 8); + } + + #[test] + fn test_tiny_segments() { + #[rustfmt::skip] + let mut contour = vec![ + VectorEdge::new(1, int_pnt!(0, 1), int_pnt!(-1, 0)), + VectorEdge::new(2, int_pnt!(-1, 0), int_pnt!(0, -1)), + VectorEdge::new(3, int_pnt!(-1, 0), int_pnt!(0, -1)), + VectorEdge::new(4, int_pnt!(0, -1), int_pnt!(1, 0)), + VectorEdge::new(5, int_pnt!(1, 0), int_pnt!(0, 1)), + VectorEdge::new(6, int_pnt!(1, 0), int_pnt!(0, 1)), + ]; + + let result = contour.simplify_contour(); + + debug_assert!(result); + debug_assert!(contour.len() == 4); + } + + #[test] + fn test_collinear_runs() { + #[rustfmt::skip] + let mut contour = vec![ + VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)), + VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)), + VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)), + VectorEdge::new(4, int_pnt!(3, 0), int_pnt!(0, -3)), + VectorEdge::new(5, int_pnt!(0, -3), int_pnt!(-3, 0)), + ]; + + let result = contour.simplify_contour(); + + debug_assert!(result); + debug_assert!(contour.len() == 3); + } + + #[test] + fn test_zero_area_path() { + #[rustfmt::skip] + let mut contour = vec![ + VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)), + VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)), + VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)), + ]; + + let result = contour.simplify_contour(); + + debug_assert!(result); + debug_assert!(contour.is_empty()); + } } From 7a68a1f8896684f6ce62360f4ee65de38bedbee6 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Wed, 21 Jan 2026 19:25:02 +0400 Subject: [PATCH 2/2] fix tests so that each contour is a regular closed contour --- iOverlay/src/vector/simplify.rs | 43 ++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/iOverlay/src/vector/simplify.rs b/iOverlay/src/vector/simplify.rs index 25e751f..4576b14 100644 --- a/iOverlay/src/vector/simplify.rs +++ b/iOverlay/src/vector/simplify.rs @@ -264,15 +264,15 @@ mod tests { #[rustfmt::skip] let mut contour = vec![ VectorEdge::new(1, int_pnt!(-1, 3), int_pnt!(-1, 1)), - VectorEdge::new(2, int_pnt!(-1, 3), int_pnt!(-1, 1)), + VectorEdge::new(2, int_pnt!(-1, 1), int_pnt!(-1, 1)), VectorEdge::new(3, int_pnt!(-1, 1), int_pnt!(-3, 1)), VectorEdge::new(4, int_pnt!(-3, 1), int_pnt!(-3, -2)), VectorEdge::new(5, int_pnt!(-3, -2), int_pnt!(3, -2)), VectorEdge::new(6, int_pnt!(3, -2), int_pnt!(3, 1)), - VectorEdge::new(7, int_pnt!(3, -2), int_pnt!(1, 1)), - VectorEdge::new(8, int_pnt!(1, 1), int_pnt!(1, 3)), - VectorEdge::new(9, int_pnt!(1, 3), int_pnt!(-1, 3)), - VectorEdge::new(10, int_pnt!(-1, 3), int_pnt!(-1, -1)), + VectorEdge::new(7, int_pnt!(3, 1), int_pnt!(3, 1)), + VectorEdge::new(8, int_pnt!(3, 1), int_pnt!(1, 1)), + VectorEdge::new(9, int_pnt!(1, 1), int_pnt!(1, 3)), + VectorEdge::new(10, int_pnt!(1, 3), int_pnt!(-1, 3)), ]; let result = contour.simplify_contour(); @@ -285,12 +285,12 @@ mod tests { fn test_tiny_segments() { #[rustfmt::skip] let mut contour = vec![ - VectorEdge::new(1, int_pnt!(0, 1), int_pnt!(-1, 0)), - VectorEdge::new(2, int_pnt!(-1, 0), int_pnt!(0, -1)), - VectorEdge::new(3, int_pnt!(-1, 0), int_pnt!(0, -1)), - VectorEdge::new(4, int_pnt!(0, -1), int_pnt!(1, 0)), - VectorEdge::new(5, int_pnt!(1, 0), int_pnt!(0, 1)), - VectorEdge::new(6, int_pnt!(1, 0), int_pnt!(0, 1)), + VectorEdge::new(1, int_pnt!(0, 2), int_pnt!(-1, 1)), + VectorEdge::new(2, int_pnt!(-1, 1), int_pnt!(-2, 0)), + VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(0, -1)), + VectorEdge::new(4, int_pnt!(0, -1), int_pnt!(2, 0)), + VectorEdge::new(5, int_pnt!(2, 0), int_pnt!(1, 1)), + VectorEdge::new(6, int_pnt!(1, 1), int_pnt!(0, 2)), ]; let result = contour.simplify_contour(); @@ -303,26 +303,29 @@ mod tests { fn test_collinear_runs() { #[rustfmt::skip] let mut contour = vec![ - VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)), - VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)), - VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)), - VectorEdge::new(4, int_pnt!(3, 0), int_pnt!(0, -3)), - VectorEdge::new(5, int_pnt!(0, -3), int_pnt!(-3, 0)), + VectorEdge::new(1, int_pnt!(-2, -2), int_pnt!(0, -2)), + VectorEdge::new(2, int_pnt!(0, -2), int_pnt!(2, -2)), + VectorEdge::new(3, int_pnt!(2, -2), int_pnt!(2, 0)), + VectorEdge::new(4, int_pnt!(2, 0), int_pnt!(2, 2)), + VectorEdge::new(5, int_pnt!(2, 2), int_pnt!(0, 2)), + VectorEdge::new(6, int_pnt!(0, 2), int_pnt!(-2, 2)), + VectorEdge::new(7, int_pnt!(-2, 2), int_pnt!(-2, 0)), + VectorEdge::new(8, int_pnt!(-2, 0), int_pnt!(-2, -2)), ]; let result = contour.simplify_contour(); debug_assert!(result); - debug_assert!(contour.len() == 3); + debug_assert!(contour.len() == 4); } #[test] fn test_zero_area_path() { #[rustfmt::skip] let mut contour = vec![ - VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(3, 0)), - VectorEdge::new(2, int_pnt!(-3, 0), int_pnt!(-1, 0)), - VectorEdge::new(3, int_pnt!(-2, 0), int_pnt!(2, 0)), + VectorEdge::new(1, int_pnt!(-3, 0), int_pnt!(0, 0)), + VectorEdge::new(2, int_pnt!(0, 0), int_pnt!(3, 0)), + VectorEdge::new(3, int_pnt!(3, 0), int_pnt!(-3, 0)), ]; let result = contour.simplify_contour();