From a0153dd4b1356970a5c2dd2e85c2728434e4b6c1 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Sun, 25 Jan 2026 14:18:42 +0400 Subject: [PATCH 1/3] add tests for string slice edge cases --- iOverlay/src/string/slice.rs | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/iOverlay/src/string/slice.rs b/iOverlay/src/string/slice.rs index 1ee1c2c..7ac2b9e 100644 --- a/iOverlay/src/string/slice.rs +++ b/iOverlay/src/string/slice.rs @@ -137,4 +137,113 @@ impl IntSlice for [IntPoint] { .map(|graph| graph.extract_shapes(StringRule::Slice)) .unwrap_or_default() } +} + +#[cfg(test)] +mod tests { + use alloc::vec; + use i_float::int::point::IntPoint; + use crate::core::fill_rule::FillRule; + use crate::string::slice::IntSlice; + + #[test] + fn test_empty_input() { + #[rustfmt::skip] + let shapes = [].slice_by_line( + [IntPoint::new(0, 0), IntPoint::new(0, 0)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 0); + } + + #[test] + fn test_0() { + #[rustfmt::skip] + let shapes = vec![ + IntPoint::new(-2, -2), + IntPoint::new(2, -2), + IntPoint::new(2, 2), + IntPoint::new(-2, 2), + ] + .slice_by_line( + [IntPoint::new(-5, 5), IntPoint::new(5, -5)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 2); + assert_eq!(shapes[0][0].len(), 3); + assert_eq!(shapes[1][0].len(), 3); + } + + #[test] + fn test_1() { + #[rustfmt::skip] + let shapes = vec![ + IntPoint::new(-2, -2), + IntPoint::new(2, -2), + IntPoint::new(2, 2), + IntPoint::new(-2, 2), + ] + .slice_by_line( + [IntPoint::new(-5, 5), IntPoint::new(5, 5)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 1); + } + + #[test] + fn test_2() { + #[rustfmt::skip] + let shapes = vec![ + IntPoint::new(0, 0), + IntPoint::new(2, 0), + IntPoint::new(2, 3), + IntPoint::new(1, 1), + IntPoint::new(0, 3), + ] + .slice_by_line( + [IntPoint::new(-5, 2), IntPoint::new(5, 2)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 3); + assert_eq!(shapes[0][0].len(), 5); + assert_eq!(shapes[1][0].len(), 3); + assert_eq!(shapes[2][0].len(), 3); + } + + #[test] + fn test_3() { + #[rustfmt::skip] + let shapes = vec![ + IntPoint::new(-2, -2), + IntPoint::new(2, -2), + IntPoint::new(2, 2), + IntPoint::new(-2, 2), + ] + .slice_by_line( + [IntPoint::new(-2, 5), IntPoint::new(2, -5)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 1); + } + + #[test] + fn test_4() { + #[rustfmt::skip] + let shapes = vec![ + IntPoint::new(-2, 0), + IntPoint::new(2, 0), + IntPoint::new(0, 2), + ] + .slice_by_line( + [IntPoint::new(-5, 2), IntPoint::new(5, 2)], + FillRule::NonZero, + ); + + assert_eq!(shapes.len(), 1); + } } \ No newline at end of file From 151382274584e1ba4ebefb0b7302c38305fec909 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Sun, 25 Jan 2026 14:28:21 +0400 Subject: [PATCH 2/3] move the tests to the place where they should be --- iOverlay/src/string/extract.rs | 169 ------------------------------- iOverlay/src/string/slice.rs | 178 ++++++++++++++++++++++++++++++++- 2 files changed, 173 insertions(+), 174 deletions(-) diff --git a/iOverlay/src/string/extract.rs b/iOverlay/src/string/extract.rs index 889264f..594a698 100644 --- a/iOverlay/src/string/extract.rs +++ b/iOverlay/src/string/extract.rs @@ -225,7 +225,6 @@ mod tests { use crate::core::fill_rule::FillRule; use crate::string::overlay::StringOverlay; use crate::string::rule::StringRule; - use crate::string::slice::IntSlice; use alloc::vec; use i_float::int::point::IntPoint; @@ -238,56 +237,6 @@ mod tests { IntPoint::new(10, 10), ]]; - let result = paths.slice_by_line( - [IntPoint::new(-20, 0), IntPoint::new(20, 0)], - FillRule::NonZero, - ); - - assert_eq!(result.len(), 2); - assert_eq!(result[0].len(), 1); - assert_eq!(result[0][0].len(), 4); - assert_eq!(result[1].len(), 1); - assert_eq!(result[1][0].len(), 4); - } - - #[test] - fn test_1() { - let paths = vec![ - vec![ - IntPoint::new(-10, 10), - IntPoint::new(-10, -10), - IntPoint::new(10, -10), - IntPoint::new(10, 10), - ], - vec![ - IntPoint::new(-5, -5), - IntPoint::new(-5, 5), - IntPoint::new(5, 5), - IntPoint::new(5, -5), - ], - ]; - - let result = paths.slice_by_line( - [IntPoint::new(-20, 0), IntPoint::new(20, 0)], - FillRule::NonZero, - ); - - assert_eq!(result.len(), 2); - assert_eq!(result[0].len(), 1); - assert_eq!(result[0][0].len(), 8); - assert_eq!(result[1].len(), 1); - assert_eq!(result[1][0].len(), 8); - } - - #[test] - fn test_2() { - let paths = vec![vec![ - IntPoint::new(-10, 10), - IntPoint::new(-10, -10), - IntPoint::new(10, -10), - IntPoint::new(10, 10), - ]]; - let window = vec![ IntPoint::new(-5, -5), IntPoint::new(-5, 5), @@ -303,122 +252,4 @@ mod tests { assert_eq!(r.len(), 2); } - - #[test] - fn test_3() { - let paths = vec![ - vec![ - IntPoint::new(0, 0), - IntPoint::new(35, 0), - IntPoint::new(35, 20), - IntPoint::new(0, 20), - ], - vec![ - IntPoint::new(5, 5), - IntPoint::new(5, 15), - IntPoint::new(15, 15), - IntPoint::new(15, 5), - ], - vec![ - IntPoint::new(20, 5), - IntPoint::new(20, 15), - IntPoint::new(30, 15), - IntPoint::new(30, 5), - ], - ]; - - let result = paths.slice_by_line( - [IntPoint::new(15, 10), IntPoint::new(20, 10)], - FillRule::NonZero, - ); - - assert_eq!(result.len(), 1); - assert_eq!(result[0].len(), 3); - } - - #[test] - fn test_4() { - let paths = vec![ - vec![ - IntPoint::new(0, 0), - IntPoint::new(35, 0), - IntPoint::new(35, 20), - IntPoint::new(0, 20), - ], - vec![ - IntPoint::new(5, 5), - IntPoint::new(5, 15), - IntPoint::new(15, 15), - IntPoint::new(15, 5), - ], - vec![ - IntPoint::new(20, 5), - IntPoint::new(20, 15), - IntPoint::new(30, 15), - IntPoint::new(30, 5), - ], - ]; - - let result = paths.slice_by_lines( - &vec![ - [IntPoint::new(15, 5), IntPoint::new(20, 5)], - [IntPoint::new(15, 15), IntPoint::new(20, 15)], - ], - FillRule::NonZero, - ); - - assert_eq!(result.len(), 2); - assert_eq!(result[0].len(), 2); - assert_eq!(result[1].len(), 1); - } - - #[test] - fn test_5() { - let paths = vec![ - vec![ - IntPoint::new(0, 0), - IntPoint::new(35, 0), - IntPoint::new(35, 35), - IntPoint::new(0, 35), - ], - vec![ - IntPoint::new(5, 5), - IntPoint::new(5, 15), - IntPoint::new(15, 15), - IntPoint::new(15, 5), - ], - vec![ - IntPoint::new(20, 5), - IntPoint::new(20, 15), - IntPoint::new(30, 15), - IntPoint::new(30, 5), - ], - vec![ - IntPoint::new(5, 20), - IntPoint::new(5, 30), - IntPoint::new(15, 30), - IntPoint::new(15, 20), - ], - vec![ - IntPoint::new(20, 20), - IntPoint::new(20, 30), - IntPoint::new(30, 30), - IntPoint::new(30, 20), - ], - ]; - - let result = paths.slice_by_lines( - &vec![ - [IntPoint::new(10, 15), IntPoint::new(10, 20)], - [IntPoint::new(25, 15), IntPoint::new(25, 20)], - [IntPoint::new(15, 10), IntPoint::new(20, 10)], - [IntPoint::new(15, 25), IntPoint::new(20, 25)], - ], - FillRule::NonZero, - ); - - assert_eq!(result.len(), 2); - assert_eq!(result[0].len(), 2); - assert_eq!(result[1].len(), 1); - } } diff --git a/iOverlay/src/string/slice.rs b/iOverlay/src/string/slice.rs index 7ac2b9e..140660d 100644 --- a/iOverlay/src/string/slice.rs +++ b/iOverlay/src/string/slice.rs @@ -159,6 +159,174 @@ mod tests { #[test] fn test_0() { + let paths = vec![vec![ + IntPoint::new(-10, 10), + IntPoint::new(-10, -10), + IntPoint::new(10, -10), + IntPoint::new(10, 10), + ]]; + + let result = paths.slice_by_line( + [IntPoint::new(-20, 0), IntPoint::new(20, 0)], + FillRule::NonZero, + ); + + assert_eq!(result.len(), 2); + assert_eq!(result[0].len(), 1); + assert_eq!(result[0][0].len(), 4); + assert_eq!(result[1].len(), 1); + assert_eq!(result[1][0].len(), 4); + } + + #[test] + fn test_1() { + let paths = vec![ + vec![ + IntPoint::new(-10, 10), + IntPoint::new(-10, -10), + IntPoint::new(10, -10), + IntPoint::new(10, 10), + ], + vec![ + IntPoint::new(-5, -5), + IntPoint::new(-5, 5), + IntPoint::new(5, 5), + IntPoint::new(5, -5), + ], + ]; + + let result = paths.slice_by_line( + [IntPoint::new(-20, 0), IntPoint::new(20, 0)], + FillRule::NonZero, + ); + + assert_eq!(result.len(), 2); + assert_eq!(result[0].len(), 1); + assert_eq!(result[0][0].len(), 8); + assert_eq!(result[1].len(), 1); + assert_eq!(result[1][0].len(), 8); + } + + #[test] + fn test_2() { + let paths = vec![ + vec![ + IntPoint::new(0, 0), + IntPoint::new(35, 0), + IntPoint::new(35, 20), + IntPoint::new(0, 20), + ], + vec![ + IntPoint::new(5, 5), + IntPoint::new(5, 15), + IntPoint::new(15, 15), + IntPoint::new(15, 5), + ], + vec![ + IntPoint::new(20, 5), + IntPoint::new(20, 15), + IntPoint::new(30, 15), + IntPoint::new(30, 5), + ], + ]; + + let result = paths.slice_by_line( + [IntPoint::new(15, 10), IntPoint::new(20, 10)], + FillRule::NonZero, + ); + + assert_eq!(result.len(), 1); + assert_eq!(result[0].len(), 3); + } + + #[test] + fn test_3() { + let paths = vec![ + vec![ + IntPoint::new(0, 0), + IntPoint::new(35, 0), + IntPoint::new(35, 20), + IntPoint::new(0, 20), + ], + vec![ + IntPoint::new(5, 5), + IntPoint::new(5, 15), + IntPoint::new(15, 15), + IntPoint::new(15, 5), + ], + vec![ + IntPoint::new(20, 5), + IntPoint::new(20, 15), + IntPoint::new(30, 15), + IntPoint::new(30, 5), + ], + ]; + + let result = paths.slice_by_lines( + &vec![ + [IntPoint::new(15, 5), IntPoint::new(20, 5)], + [IntPoint::new(15, 15), IntPoint::new(20, 15)], + ], + FillRule::NonZero, + ); + + assert_eq!(result.len(), 2); + assert_eq!(result[0].len(), 2); + assert_eq!(result[1].len(), 1); + } + + #[test] + fn test_4() { + let paths = vec![ + vec![ + IntPoint::new(0, 0), + IntPoint::new(35, 0), + IntPoint::new(35, 35), + IntPoint::new(0, 35), + ], + vec![ + IntPoint::new(5, 5), + IntPoint::new(5, 15), + IntPoint::new(15, 15), + IntPoint::new(15, 5), + ], + vec![ + IntPoint::new(20, 5), + IntPoint::new(20, 15), + IntPoint::new(30, 15), + IntPoint::new(30, 5), + ], + vec![ + IntPoint::new(5, 20), + IntPoint::new(5, 30), + IntPoint::new(15, 30), + IntPoint::new(15, 20), + ], + vec![ + IntPoint::new(20, 20), + IntPoint::new(20, 30), + IntPoint::new(30, 30), + IntPoint::new(30, 20), + ], + ]; + + let result = paths.slice_by_lines( + &vec![ + [IntPoint::new(10, 15), IntPoint::new(10, 20)], + [IntPoint::new(25, 15), IntPoint::new(25, 20)], + [IntPoint::new(15, 10), IntPoint::new(20, 10)], + [IntPoint::new(15, 25), IntPoint::new(20, 25)], + ], + FillRule::NonZero, + ); + + assert_eq!(result.len(), 2); + assert_eq!(result[0].len(), 2); + assert_eq!(result[1].len(), 1); + } + + #[test] + fn test_5() { #[rustfmt::skip] let shapes = vec![ IntPoint::new(-2, -2), @@ -177,7 +345,7 @@ mod tests { } #[test] - fn test_1() { + fn test_6() { #[rustfmt::skip] let shapes = vec![ IntPoint::new(-2, -2), @@ -194,7 +362,7 @@ mod tests { } #[test] - fn test_2() { + fn test_7() { #[rustfmt::skip] let shapes = vec![ IntPoint::new(0, 0), @@ -215,7 +383,7 @@ mod tests { } #[test] - fn test_3() { + fn test_8() { #[rustfmt::skip] let shapes = vec![ IntPoint::new(-2, -2), @@ -224,7 +392,7 @@ mod tests { IntPoint::new(-2, 2), ] .slice_by_line( - [IntPoint::new(-2, 5), IntPoint::new(2, -5)], + [IntPoint::new(-2, 5), IntPoint::new(-2, -5)], FillRule::NonZero, ); @@ -232,7 +400,7 @@ mod tests { } #[test] - fn test_4() { + fn test_9() { #[rustfmt::skip] let shapes = vec![ IntPoint::new(-2, 0), From a85f28013c90f389da5f159c4f27cf2e1058c130 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Sun, 25 Jan 2026 14:31:04 +0400 Subject: [PATCH 3/3] clean up a little in string tests --- iOverlay/src/string/clip.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iOverlay/src/string/clip.rs b/iOverlay/src/string/clip.rs index c9e0cc1..9b6e848 100644 --- a/iOverlay/src/string/clip.rs +++ b/iOverlay/src/string/clip.rs @@ -247,7 +247,7 @@ impl IntClip for [IntPoint] { #[cfg(test)] mod tests { use alloc::vec; -use i_float::int::point::IntPoint; + use i_float::int::point::IntPoint; use i_shape::int::path::IntPath; use crate::core::fill_rule::FillRule; use crate::string::clip::{ClipRule, IntClip}; @@ -344,11 +344,11 @@ use i_float::int::point::IntPoint; ]; let result_0 = rect.clip_path(&path, FillRule::NonZero, - ClipRule { invert: false, boundary_included: false }, + ClipRule { invert: false, boundary_included: false }, ); let result_1 = rect.clip_path(&path, FillRule::NonZero, - ClipRule { invert: false, boundary_included: true }, + ClipRule { invert: false, boundary_included: true }, ); assert_eq!(result_0.len(), 3);