@@ -243,7 +243,6 @@ impl IntClip for [IntPoint] {
243243 }
244244}
245245
246-
247246#[ cfg( test) ]
248247mod tests {
249248 use alloc:: vec;
@@ -354,4 +353,107 @@ mod tests {
354353 assert_eq ! ( result_0. len( ) , 3 ) ;
355354 assert_eq ! ( result_1. len( ) , 2 ) ;
356355 }
356+
357+ #[ test]
358+ fn test_tiny_shape ( ) {
359+ let path = vec ! [
360+ IntPoint :: new( -1 , 0 ) ,
361+ IntPoint :: new( 1 , 0 ) ,
362+ IntPoint :: new( 0 , 1 ) ,
363+ ] ;
364+
365+ let result_0 = path. clip_line (
366+ [ IntPoint :: new ( 0 , -1 ) , IntPoint :: new ( 0 , 2 ) ] ,
367+ FillRule :: NonZero ,
368+ ClipRule { invert : false , boundary_included : false } ,
369+ ) ;
370+
371+ let result_1 = path. clip_line (
372+ [ IntPoint :: new ( 0 , -1 ) , IntPoint :: new ( 0 , 2 ) ] ,
373+ FillRule :: NonZero ,
374+ ClipRule { invert : true , boundary_included : false } ,
375+ ) ;
376+
377+ assert_eq ! ( result_0. len( ) , 1 ) ;
378+ assert_eq ! ( result_1. len( ) , 2 ) ;
379+ }
380+
381+ #[ test]
382+ fn test_shared_vertices_0 ( ) {
383+ let path = vec ! [
384+ IntPoint :: new( -1 , -1 ) ,
385+ IntPoint :: new( 1 , -1 ) ,
386+ IntPoint :: new( 1 , 1 ) ,
387+ IntPoint :: new( -1 , 1 ) ,
388+ ] ;
389+
390+ let result_0 = path. clip_line (
391+ [ IntPoint :: new ( -1 , -1 ) , IntPoint :: new ( 1 , -1 ) ] ,
392+ FillRule :: NonZero ,
393+ ClipRule { invert : false , boundary_included : false } ,
394+ ) ;
395+
396+ let result_1 = path. clip_line (
397+ [ IntPoint :: new ( -1 , -1 ) , IntPoint :: new ( 1 , -1 ) ] ,
398+ FillRule :: NonZero ,
399+ ClipRule { invert : false , boundary_included : true } ,
400+ ) ;
401+
402+ assert_eq ! ( result_0. len( ) , 0 ) ;
403+ assert_eq ! ( result_1. len( ) , 1 ) ;
404+ }
405+
406+ #[ test]
407+ fn test_shared_vertices_1 ( ) {
408+ let contour = vec ! [
409+ IntPoint :: new( -2 , -2 ) ,
410+ IntPoint :: new( 2 , -2 ) ,
411+ IntPoint :: new( 3 , 0 ) ,
412+ IntPoint :: new( -3 , 0 ) ,
413+ ] ;
414+
415+ let path = vec ! [
416+ IntPoint :: new( -4 , 1 ) ,
417+ IntPoint :: new( -2 , -2 ) ,
418+ IntPoint :: new( 2 , -2 ) ,
419+ IntPoint :: new( 4 , 1 ) ,
420+ ] ;
421+
422+ let result_0 = contour. clip_path ( & path, FillRule :: NonZero ,
423+ ClipRule { invert : false , boundary_included : false } ,
424+ ) ;
425+
426+ let result_1 = contour. clip_path ( & path, FillRule :: NonZero ,
427+ ClipRule { invert : false , boundary_included : true } ,
428+ ) ;
429+
430+ assert_eq ! ( result_0. len( ) , 0 ) ;
431+ assert_eq ! ( result_1. len( ) , 1 ) ;
432+ }
433+
434+ #[ test]
435+ fn test_sliding_intersection ( ) {
436+ let path = vec ! [
437+ IntPoint :: new( 0 , 0 ) ,
438+ IntPoint :: new( 2 , 0 ) ,
439+ IntPoint :: new( 2 , 2 ) ,
440+ IntPoint :: new( 1 , 0 ) ,
441+ IntPoint :: new( 0 , 2 ) ,
442+ ] ;
443+
444+ let result_0 = path. clip_line (
445+ [ IntPoint :: new ( -3 , 2 ) , IntPoint :: new ( 3 , 2 ) ] ,
446+ FillRule :: NonZero ,
447+ ClipRule { invert : false , boundary_included : false } ,
448+ ) ;
449+
450+ let result_1 = path. clip_line (
451+ [ IntPoint :: new ( -3 , 2 ) , IntPoint :: new ( 3 , 2 ) ] ,
452+ FillRule :: NonZero ,
453+ ClipRule { invert : false , boundary_included : false } ,
454+ ) ;
455+
456+ assert_eq ! ( result_0. len( ) , 0 ) ;
457+ assert_eq ! ( result_1. len( ) , 0 ) ;
458+ }
357459}
0 commit comments