Skip to content

Commit c90e14d

Browse files
committed
add support for negative sweeping angle
1 parent f6d5679 commit c90e14d

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/ImageSharp.Drawing/Shapes/EllipticalArcLineSegment.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public EllipticalArcLineSegment(PointF center, float firstRadius, float secondRa
3737
{
3838
Guard.MustBeGreaterThan(firstRadius, 0, nameof(firstRadius));
3939
Guard.MustBeGreaterThan(secondRadius, 0, nameof(secondRadius));
40-
Guard.MustBeGreaterThanOrEqualTo(rotation, 0, nameof(rotation));
41-
Guard.MustBeGreaterThanOrEqualTo(startAngle, 0, nameof(startAngle));
42-
Guard.MustBeGreaterThanOrEqualTo(sweepAngle, 0, nameof(sweepAngle));
4340
this.center = center;
4441
this.firstRadius = firstRadius;
4542
this.secondRadius = secondRadius;
@@ -51,6 +48,10 @@ public EllipticalArcLineSegment(PointF center, float firstRadius, float secondRa
5148
{
5249
this.sweepAngle = 360;
5350
}
51+
if (sweepAngle < -360)
52+
{
53+
this.sweepAngle = -360;
54+
}
5455

5556
this.linePoints = this.GetDrawingPoints();
5657
this.EndPoint = this.linePoints[this.linePoints.Length - 1];
@@ -92,16 +93,31 @@ private PointF[] GetDrawingPoints()
9293
{
9394
this.CalculatePoint(this.startAngle)
9495
};
95-
96-
for (float i = this.startAngle; i < this.startAngle + this.sweepAngle; i++)
96+
if (this.sweepAngle < 0)
9797
{
98-
float end = i + 1;
99-
if (end >= this.startAngle + this.sweepAngle)
98+
for (float i = this.startAngle; i > this.startAngle + this.sweepAngle; i--)
10099
{
101-
end = this.startAngle + this.sweepAngle;
100+
float end = i - 1;
101+
if (end <= this.startAngle + this.sweepAngle)
102+
{
103+
end = this.startAngle + this.sweepAngle;
104+
}
105+
106+
points.AddRange(this.GetDrawingPoints(i, end, 0));
102107
}
108+
}
109+
else
110+
{
111+
for (float i = this.startAngle; i < this.startAngle + this.sweepAngle; i++)
112+
{
113+
float end = i + 1;
114+
if (end >= this.startAngle + this.sweepAngle)
115+
{
116+
end = this.startAngle + this.sweepAngle;
117+
}
103118

104-
points.AddRange(this.GetDrawingPoints(i, end, 0));
119+
points.AddRange(this.GetDrawingPoints(i, end, 0));
120+
}
105121
}
106122

107123
return points.ToArray();

0 commit comments

Comments
 (0)