@@ -36,42 +36,52 @@ public ComplexPolygon(params IPath[] paths)
3636 {
3737 this . paths = paths ?? throw new ArgumentNullException ( nameof ( paths ) ) ;
3838
39- float minX = float . MaxValue ;
40- float maxX = float . MinValue ;
41- float minY = float . MaxValue ;
42- float maxY = float . MinValue ;
43- float length = 0 ;
44- int intersections = 0 ;
45-
46- foreach ( IPath s in this . paths )
39+ if ( paths . Length > 0 )
4740 {
48- length += s . Length ;
49- if ( s . Bounds . Left < minX )
41+ float minX = float . MaxValue ;
42+ float maxX = float . MinValue ;
43+ float minY = float . MaxValue ;
44+ float maxY = float . MinValue ;
45+ float length = 0 ;
46+ int intersections = 0 ;
47+
48+ foreach ( IPath s in this . paths )
5049 {
51- minX = s . Bounds . Left ;
52- }
50+ length += s . Length ;
51+ if ( s . Bounds . Left < minX )
52+ {
53+ minX = s . Bounds . Left ;
54+ }
5355
54- if ( s . Bounds . Right > maxX )
55- {
56- maxX = s . Bounds . Right ;
57- }
56+ if ( s . Bounds . Right > maxX )
57+ {
58+ maxX = s . Bounds . Right ;
59+ }
5860
59- if ( s . Bounds . Top < minY )
60- {
61- minY = s . Bounds . Top ;
62- }
61+ if ( s . Bounds . Top < minY )
62+ {
63+ minY = s . Bounds . Top ;
64+ }
6365
64- if ( s . Bounds . Bottom > maxY )
65- {
66- maxY = s . Bounds . Bottom ;
66+ if ( s . Bounds . Bottom > maxY )
67+ {
68+ maxY = s . Bounds . Bottom ;
69+ }
70+
71+ intersections += s . MaxIntersections ;
6772 }
6873
69- intersections += s . MaxIntersections ;
74+ this . MaxIntersections = intersections ;
75+ this . Length = length ;
76+ this . Bounds = new RectangleF ( minX , minY , maxX - minX , maxY - minY ) ;
77+ }
78+ else
79+ {
80+ this . MaxIntersections = 0 ;
81+ this . Length = 0 ;
82+ this . Bounds = RectangleF . Empty ;
7083 }
7184
72- this . MaxIntersections = intersections ;
73- this . Length = length ;
74- this . Bounds = new RectangleF ( minX , minY , maxX - minX , maxY - minY ) ;
7585 this . PathType = PathTypes . Mixed ;
7686 }
7787
0 commit comments