55using System . Collections . Generic ;
66using System . Numerics ;
77
8- namespace SixLabors . ImageSharp . Drawing . Shapes
8+ namespace SixLabors . ImageSharp . Drawing
99{
1010 /// <summary>
1111 /// Represents a line segment that contains radii and angles that will be rendered as a elliptical arc
@@ -69,6 +69,7 @@ public EllipticalArcLineSegment Transform(Matrix3x2 matrix)
6969 }
7070
7171 // TODO
72+ return this ;
7273 }
7374
7475 /// <summary>
@@ -88,31 +89,40 @@ private PointF[] GetDrawingPoints()
8889 for ( float i = this . startAngle ; i < this . startAngle + this . sweepAngle ; i ++ )
8990 {
9091 float end = i + 1 ;
91- if ( end < = this . startAngle + this . sweepAngle )
92+ if ( end > = this . startAngle + this . sweepAngle )
9293 {
9394 end = this . startAngle + this . sweepAngle ;
9495 }
9596
96- points . AddRange ( this . GetDrawingPoints ( points [ points . Count - 1 ] , i , end ) ) ;
97+ points . AddRange ( this . GetDrawingPoints ( i , end , 0 ) ) ;
9798 }
9899
99100 return points . ToArray ( ) ;
100101 }
101102
102- private List < PointF > GetDrawingPoints ( PointF start , float startAngle , float end )
103+ private List < PointF > GetDrawingPoints ( float start , float end , int depth )
103104 {
105+ if ( depth > 1000 )
106+ {
107+ return new List < PointF > ( ) ;
108+ }
109+
104110 var points = new List < PointF > ( ) ;
111+
112+ float startX = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * start / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) - ( this . secondRadius * Math . Cos ( Math . PI * start / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + this . center . X ) ;
113+ float startY = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * start / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + ( this . secondRadius * Math . Cos ( Math . PI * start / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) + this . center . Y ) ;
114+
105115 float endX = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * end / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) - ( this . secondRadius * Math . Cos ( Math . PI * end / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + this . center . X ) ;
106116 float endY = ( float ) ( ( this . firstRadius * Math . Sin ( Math . PI * end / 180 ) * Math . Sin ( Math . PI * this . rotation / 180 ) ) + ( this . secondRadius * Math . Cos ( Math . PI * end / 180 ) * Math . Cos ( Math . PI * this . rotation / 180 ) ) + this . center . Y ) ;
107- if ( ( new Vector2 ( endX , endY ) - new Vector2 ( start . X , start . Y ) ) . LengthSquared ( ) < MinimumSqrDistance )
117+ if ( ( new Vector2 ( endX , endY ) - new Vector2 ( startX , startY ) ) . LengthSquared ( ) < MinimumSqrDistance )
108118 {
109119 points . Add ( new PointF ( endX , endY ) ) ;
110120 }
111121 else
112122 {
113- float mid = startAngle + ( ( startAngle - end ) / 2 ) ;
114- points . AddRange ( this . GetDrawingPoints ( start , startAngle , mid ) ) ;
115- points . AddRange ( this . GetDrawingPoints ( points [ points . Count - 1 ] , mid , end ) ) ;
123+ float mid = start + ( ( end - start ) / 2 ) ;
124+ points . AddRange ( this . GetDrawingPoints ( start , mid , depth + 1 ) ) ;
125+ points . AddRange ( this . GetDrawingPoints ( mid , end , depth + 1 ) ) ;
116126 }
117127
118128 return points ;
0 commit comments