@@ -564,4 +564,63 @@ describe('polygon subdivision', () => {
564564 // eslint-disable-next-line @typescript-eslint/no-unsafe-call
565565 expect ( result [ 7 ] [ 0 ] ) . toEqualRing ( [ new Point ( 90 , 47 ) , new Point ( 100 , 50 ) , new Point ( 100 , 60 ) , new Point ( 90 , 58 ) , new Point ( 90 , 47 ) ] ) ;
566566 } ) ;
567+
568+ test ( 'grid snapping to fix precision issues' , ( ) => {
569+ // Real-world polygon that caused precision issues without grid snapping fix.
570+ // The martinez library can produce nearly-coincident vertices that should be
571+ // identical, causing rendering artifacts.
572+ const subject = [
573+ new Point ( 1569 , 3677 ) , new Point ( 1737 , 3023 ) , new Point ( 1825 , 2634 ) ,
574+ new Point ( 1952 , 1864 ) , new Point ( 2077 , 728 ) , new Point ( 2111 , - 1 ) ,
575+ new Point ( 4966 , - 1 ) , new Point ( 4960 , 192 ) , new Point ( 4843 , 1624 ) ,
576+ new Point ( 4681 , 2642 ) , new Point ( 4455 , 3748 ) , new Point ( 4278 , 4475 ) ,
577+ new Point ( 1569 , 3677 )
578+ ] ;
579+
580+ const edges = new MockEdgeIterator ( [
581+ [ new Point ( 3959 , - 8562 ) , new Point ( 868 , - 7651 ) ] ,
582+ [ new Point ( 4357 , - 7209 ) , new Point ( 1246 , - 6374 ) ] ,
583+ [ new Point ( 4703 , - 5781 ) , new Point ( 1546 , - 5138 ) ] ,
584+ [ new Point ( 4945 , - 4322 ) , new Point ( 1752 , - 3891 ) ] ,
585+ [ new Point ( 5013 , - 2859 ) , new Point ( 1970 , - 2624 ) ] ,
586+ [ new Point ( 5086 , - 1399 ) , new Point ( 2035 , - 1346 ) ] ,
587+ [ new Point ( 5063 , 67 ) , new Point ( 2014 , - 69 ) ] ,
588+ [ new Point ( 4954 , 1538 ) , new Point ( 1921 , 1195 ) ] ,
589+ [ new Point ( 4730 , 3006 ) , new Point ( 1731 , 2437 ) ] ,
590+ [ new Point ( 4440 , 4288 ) , new Point ( 1463 , 3611 ) ]
591+ ] ) ;
592+
593+ const result = polygonSubdivision ( [ subject ] , edges ) ;
594+
595+ expect ( result . length ) . toBe ( 5 ) ;
596+
597+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
598+ expect ( result [ 0 ] [ 0 ] ) . toEqualRing ( [
599+ new Point ( 1569 , 3677 ) , new Point ( 1579 , 3637 ) , new Point ( 4330 , 4263 ) ,
600+ new Point ( 4278 , 4475 ) , new Point ( 1569 , 3677 )
601+ ] ) ;
602+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
603+ expect ( result [ 1 ] [ 0 ] ) . toEqualRing ( [
604+ new Point ( 1579 , 3637 ) , new Point ( 1737 , 3023 ) , new Point ( 1825 , 2634 ) ,
605+ new Point ( 1854 , 2460 ) , new Point ( 4611 , 2983 ) , new Point ( 4455 , 3748 ) ,
606+ new Point ( 4330 , 4263 ) , new Point ( 1579 , 3637 )
607+ ] ) ;
608+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
609+ expect ( result [ 2 ] [ 0 ] ) . toEqualRing ( [
610+ new Point ( 1854 , 2460 ) , new Point ( 1952 , 1864 ) , new Point ( 2024 , 1207 ) ,
611+ new Point ( 4851 , 1526 ) , new Point ( 4843 , 1624 ) , new Point ( 4681 , 2642 ) ,
612+ new Point ( 4611 , 2983 ) , new Point ( 1854 , 2460 )
613+ ] ) ;
614+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
615+ expect ( result [ 3 ] [ 0 ] ) . toEqualRing ( [
616+ new Point ( 2024 , 1207 ) , new Point ( 2077 , 728 ) , new Point ( 2111 , - 1 ) ,
617+ new Point ( 3539 , - 1 ) , new Point ( 4964 , 63 ) , new Point ( 4960 , 192 ) ,
618+ new Point ( 4851 , 1526 ) , new Point ( 2024 , 1207 )
619+ ] ) ;
620+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
621+ expect ( result [ 4 ] [ 0 ] ) . toEqualRing ( [
622+ new Point ( 3539 , - 1 ) , new Point ( 4966 , - 1 ) , new Point ( 4964 , 63 ) ,
623+ new Point ( 3539 , - 1 )
624+ ] ) ;
625+ } ) ;
567626} ) ;
0 commit comments