Skip to content

Commit 5e6ee64

Browse files
committed
removed PointF from EllipticalArcLineSegment, added addEllipticalArc overloads
1 parent 2023202 commit 5e6ee64

2 files changed

Lines changed: 39 additions & 13 deletions

File tree

src/ImageSharp.Drawing/Shapes/EllipticalArcLineSegment.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public sealed class EllipticalArcLineSegment : ILineSegment
1515
{
1616
private const float MinimumSqrDistance = 1.75f;
1717
private readonly PointF[] linePoints;
18-
private PointF center;
18+
private readonly float x;
19+
private readonly float y;
1920
private readonly float radiusX;
2021
private readonly float radiusY;
2122
private readonly float rotation;
@@ -26,18 +27,20 @@ public sealed class EllipticalArcLineSegment : ILineSegment
2627
/// <summary>
2728
/// Initializes a new instance of the <see cref="EllipticalArcLineSegment"/> class.
2829
/// </summary>
29-
/// <param name="center"> The center point of the ellipsis the arc is a part of.</param>
30+
/// <param name="x"> The x-coordinate of the center point of the ellips from which the arc is taken.</param>
31+
/// <param name="y"> The y-coordinate of the center point of the ellips from which the arc is taken.</param>
3032
/// <param name="radiusX">X radius of the ellipsis.</param>
3133
/// <param name="radiusY">Y radius of the ellipsis.</param>
32-
/// <param name="rotation">The rotation of (<paramref name="radiusX"/> to the X-axis and (<paramref name="radiusY"/> to the Y-axis,measured in degrees anticlockwise.</param>
34+
/// <param name="rotation">The rotation of (<paramref name="radiusX"/> to the X-axis and (<paramref name="radiusY"/> to the Y-axis, measured in degrees anticlockwise.</param>
3335
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
3436
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
3537
/// <param name="transformation">The Tranformation matrix, that should be used on the arc.</param>
36-
public EllipticalArcLineSegment(PointF center, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle, Matrix3x2 transformation)
38+
public EllipticalArcLineSegment(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle, Matrix3x2 transformation)
3739
{
3840
Guard.MustBeGreaterThan(radiusX, 0, nameof(radiusX));
3941
Guard.MustBeGreaterThan(radiusY, 0, nameof(radiusY));
40-
this.center = center;
42+
this.x = x;
43+
this.y = y;
4144
this.radiusX = radiusX;
4245
this.radiusY = radiusY;
4346
this.rotation = rotation % 360;
@@ -78,7 +81,7 @@ public EllipticalArcLineSegment Transform(Matrix3x2 matrix)
7881
return this;
7982
}
8083

81-
return new EllipticalArcLineSegment(this.center, this.radiusX, this.radiusY, this.rotation, this.startAngle, this.sweepAngle, Matrix3x2.Multiply(this.transformation, matrix));
84+
return new EllipticalArcLineSegment(this.x, this.y, this.radiusX, this.radiusY, this.rotation, this.startAngle, this.sweepAngle, Matrix3x2.Multiply(this.transformation, matrix));
8285
}
8386

8487
/// <summary>
@@ -151,8 +154,8 @@ private List<PointF> GetDrawingPoints(float start, float end, int depth)
151154

152155
private PointF CalculatePoint(float angle)
153156
{
154-
float x = (this.radiusX * MathF.Sin(MathF.PI * angle / 180) * MathF.Cos(MathF.PI * this.rotation / 180)) - (this.radiusY * MathF.Cos(MathF.PI * angle / 180) * MathF.Sin(MathF.PI * this.rotation / 180)) + this.center.X;
155-
float y = (this.radiusX * MathF.Sin(MathF.PI * angle / 180) * MathF.Sin(MathF.PI * this.rotation / 180)) + (this.radiusY * MathF.Cos(MathF.PI * angle / 180) * MathF.Cos(MathF.PI * this.rotation / 180)) + this.center.Y;
157+
float x = (this.radiusX * MathF.Sin(MathF.PI * angle / 180) * MathF.Cos(MathF.PI * this.rotation / 180)) - (this.radiusY * MathF.Cos(MathF.PI * angle / 180) * MathF.Sin(MathF.PI * this.rotation / 180)) + this.x;
158+
float y = (this.radiusX * MathF.Sin(MathF.PI * angle / 180) * MathF.Sin(MathF.PI * this.rotation / 180)) + (this.radiusY * MathF.Cos(MathF.PI * angle / 180) * MathF.Cos(MathF.PI * this.rotation / 180)) + this.y;
156159
var currPoint = new PointF(x, y);
157160
return PointF.Transform(currPoint, this.transformation);
158161
}

src/ImageSharp.Drawing/Shapes/PathBuilder.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,41 @@ public PathBuilder AddBezier(PointF startPoint, PointF controlPoint1, PointF con
200200
}
201201

202202
/// <summary>
203-
/// Adds a elliptical arc to the current figure
203+
/// Adds an elliptical arc to the current figure
204204
/// </summary>
205-
/// <param name="center"> The center point of the ellipsis the arc is a part of.</param>
205+
/// <param name="rect"> A <see cref="RectangleF"/> that represents the rectangular bounds of the ellipse from which the arc is taken.</param>
206+
/// <param name="rotation">The rotation of (<paramref name="rect"/>, measured in degrees anticlockwise.</param>
207+
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
208+
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
209+
/// <returns>The <see cref="PathBuilder"/></returns>
210+
public PathBuilder AddEllipticalArc(RectangleF rect, float rotation, float startAngle, float sweepAngle) => this.AddEllipticalArc((rect.Right + rect.Left) / 2, (rect.Bottom + rect.Top) / 2, rect.Width / 2, rect.Height / 2, rotation, startAngle, sweepAngle);
211+
212+
/// <summary>
213+
/// Adds an elliptical arc to the current figure
214+
/// </summary>
215+
/// <param name="center"> The center point of the ellips from which the arc is taken.</param>
216+
/// <param name="radiusX">X radius of the ellipsis.</param>
217+
/// <param name="radiusY">Y radius of the ellipsis.</param>
218+
/// <param name="rotation">The rotation of (<paramref name="radiusX"/> to the X-axis and (<paramref name="radiusY"/> to the Y-axis, measured in degrees anticlockwise.</param>
219+
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
220+
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
221+
/// <returns>The <see cref="PathBuilder"/></returns>
222+
public PathBuilder AddEllipticalArc(PointF center, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle) => this.AddEllipticalArc(center.X, center.Y, radiusX, radiusY, rotation, startAngle, sweepAngle);
223+
224+
/// <summary>
225+
/// Adds an elliptical arc to the current figure
226+
/// </summary>
227+
/// <param name="x"> The x-coordinate of the center point of the ellips from which the arc is taken.</param>
228+
/// <param name="y"> The y-coordinate of the center point of the ellips from which the arc is taken.</param>
206229
/// <param name="radiusX">X radius of the ellipsis.</param>
207230
/// <param name="radiusY">Y radius of the ellipsis.</param>
208-
/// <param name="rotation">The rotation of (<paramref name="radiusX"/> to the X-axis and (<paramref name="radiusY"/> to the Y-axis,measured in degrees anticlockwise.</param>
231+
/// <param name="rotation">The rotation of (<paramref name="radiusX"/> to the X-axis and (<paramref name="radiusY"/> to the Y-axis, measured in degrees anticlockwise.</param>
209232
/// <param name="startAngle">The Start angle of the ellipsis, measured in degrees anticlockwise from the Y-axis.</param>
210233
/// <param name="sweepAngle"> The angle between (<paramref name="startAngle"/> and the end of the arc. </param>
211234
/// <returns>The <see cref="PathBuilder"/></returns>
212-
public PathBuilder AddEllipticalArc(PointF center, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle)
235+
public PathBuilder AddEllipticalArc(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle)
213236
{
214-
this.currentFigure.AddSegment(new EllipticalArcLineSegment(center, radiusX, radiusY, rotation, startAngle, sweepAngle, this.currentTransform));
237+
this.currentFigure.AddSegment(new EllipticalArcLineSegment(x, y, radiusX, radiusY, rotation, startAngle, sweepAngle, this.currentTransform));
215238

216239
return this;
217240
}

0 commit comments

Comments
 (0)