From 81c03d3da1ed3fb822cbafd30a553c03b8ae06bd Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Tue, 27 Jan 2026 17:02:22 +0400 Subject: [PATCH 1/2] add tests for string clip edge cases --- iOverlay/src/string/clip.rs | 104 +++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/iOverlay/src/string/clip.rs b/iOverlay/src/string/clip.rs index 9b6e848..2e79c07 100644 --- a/iOverlay/src/string/clip.rs +++ b/iOverlay/src/string/clip.rs @@ -243,7 +243,6 @@ impl IntClip for [IntPoint] { } } - #[cfg(test)] mod tests { use alloc::vec; @@ -354,4 +353,107 @@ mod tests { assert_eq!(result_0.len(), 3); assert_eq!(result_1.len(), 2); } + + #[test] + fn test_tiny_shape() { + let path = vec![ + IntPoint::new(-1, 0), + IntPoint::new(1, 0), + IntPoint::new(0, 1), + ]; + + let result_0 = path.clip_line( + [IntPoint::new(0, -1), IntPoint::new(0, 2)], + FillRule::NonZero, + ClipRule { invert: false, boundary_included: false }, + ); + + let result_1 = path.clip_line( + [IntPoint::new(0, -1), IntPoint::new(0, 2)], + FillRule::NonZero, + ClipRule { invert: true, boundary_included: false }, + ); + + assert_eq!(result_0.len(), 1); + assert_eq!(result_1.len(), 2); + } + + #[test] + fn test_shared_vertices_0() { + let path = vec![ + IntPoint::new(-1, -1), + IntPoint::new(1, -1), + IntPoint::new(1, 1), + IntPoint::new(-1, 1), + ]; + + let result_0 = path.clip_line( + [IntPoint::new(-1, -1), IntPoint::new(1, -1)], + FillRule::NonZero, + ClipRule { invert: false, boundary_included: false }, + ); + + let result_1 = path.clip_line( + [IntPoint::new(-1, -1), IntPoint::new(1, -1)], + FillRule::NonZero, + ClipRule { invert: false, boundary_included: true }, + ); + + assert_eq!(result_0.len(), 0); + assert_eq!(result_1.len(), 1); + } + + #[test] + fn test_shared_vertices_1() { + let rect = vec![ + IntPoint::new(-2, -2), + IntPoint::new(2, -2), + IntPoint::new(3, 0), + IntPoint::new(-3, 0), + ]; + + let path = vec![ + IntPoint::new(-4, 1), + IntPoint::new(-2, -2), + IntPoint::new(2, -2), + IntPoint::new(4, 1), + ]; + + let result_0 = rect.clip_path(&path, FillRule::NonZero, + ClipRule { invert: false, boundary_included: false }, + ); + + let result_1 = rect.clip_path(&path, FillRule::NonZero, + ClipRule { invert: false, boundary_included: true }, + ); + + assert_eq!(result_0.len(), 0); + assert_eq!(result_1.len(), 1); + } + + #[test] + fn test_sliding_intersection() { + let path = vec![ + IntPoint::new(0, 0), + IntPoint::new(2, 0), + IntPoint::new(2, 2), + IntPoint::new(1, 0), + IntPoint::new(0, 2), + ]; + + let result_0 = path.clip_line( + [IntPoint::new(-3, 2), IntPoint::new(3, 2)], + FillRule::NonZero, + ClipRule { invert: false, boundary_included: false }, + ); + + let result_1 = path.clip_line( + [IntPoint::new(-3, 2), IntPoint::new(3, 2)], + FillRule::NonZero, + ClipRule { invert: false, boundary_included: false }, + ); + + assert_eq!(result_0.len(), 0); + assert_eq!(result_1.len(), 0); + } } From 73269da38913f1c2c0455bcc170197ab54688d16 Mon Sep 17 00:00:00 2001 From: mikhailofff Date: Tue, 27 Jan 2026 21:53:16 +0400 Subject: [PATCH 2/2] refactor for correct variable name --- 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 2e79c07..3d9d935 100644 --- a/iOverlay/src/string/clip.rs +++ b/iOverlay/src/string/clip.rs @@ -405,7 +405,7 @@ mod tests { #[test] fn test_shared_vertices_1() { - let rect = vec![ + let contour = vec![ IntPoint::new(-2, -2), IntPoint::new(2, -2), IntPoint::new(3, 0), @@ -419,11 +419,11 @@ mod tests { IntPoint::new(4, 1), ]; - let result_0 = rect.clip_path(&path, FillRule::NonZero, + let result_0 = contour.clip_path(&path, FillRule::NonZero, ClipRule { invert: false, boundary_included: false }, ); - let result_1 = rect.clip_path(&path, FillRule::NonZero, + let result_1 = contour.clip_path(&path, FillRule::NonZero, ClipRule { invert: false, boundary_included: true }, );