@@ -60,24 +60,45 @@ public double MiterLimitTheta
6060
6161 public double MiterLimit { get ; set ; } = 4 ;
6262
63- public Polygon ProcessPath ( ReadOnlySpan < PointF > pathPoints )
63+ public Polygon ProcessPath ( ReadOnlySpan < PointF > pathPoints , bool isClosed )
6464 {
6565 for ( int i = 0 ; i < pathPoints . Length ; i ++ )
6666 {
6767 PointF point = pathPoints [ i ] ;
6868 this . AddVertex ( point . X , point . Y , PathCommand . LineTo ) ;
6969 }
7070
71- this . AddVertex ( pathPoints [ ^ 1 ] . X , pathPoints [ ^ 1 ] . Y , PathCommand . LineTo ) ;
72- this . closed = 1 ;
73- this . Rewind ( ) ;
71+ if ( isClosed )
72+ {
73+ this . AddVertex ( 0 , 0 , PathCommand . EndPoly | ( PathCommand ) PathFlags . Close ) ;
74+ }
7475
7576 double x = 0 ;
7677 double y = 0 ;
77- List < PointF > results = new ( pathPoints . Length ) ;
78- while ( ! ( _ = this . Vertex ( ref x , ref y ) ) . Stop ( ) )
78+ List < PointF > results = new ( pathPoints . Length * 3 ) ;
79+
80+ int startIndex = 0 ;
81+ PointF ? lastPoint = null ;
82+ PathCommand command ;
83+ while ( ! ( command = this . Vertex ( ref x , ref y ) ) . Stop ( ) )
7984 {
80- results . Add ( new PointF ( ( float ) x , ( float ) y ) ) ;
85+ PointF currentPoint ;
86+ if ( command . EndPoly ( ) && results . Count > 0 )
87+ {
88+ PointF initial = results [ startIndex ] ;
89+ currentPoint = new ( initial . X , initial . Y ) ;
90+ results . Add ( currentPoint ) ;
91+ startIndex = results . Count ;
92+ }
93+ else
94+ {
95+ currentPoint = new ( ( float ) x , ( float ) y ) ;
96+ if ( currentPoint != lastPoint )
97+ {
98+ results . Add ( currentPoint ) ;
99+ lastPoint = currentPoint ;
100+ }
101+ }
81102 }
82103
83104 return new Polygon ( results . ToArray ( ) ) ;
0 commit comments