From e19909cc00fdbd6ce78afa42a7a7dea459c6e322 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 11 May 2026 00:19:49 +1000 Subject: [PATCH 1/2] Add RoundedRectanglePolygon and PathBuilder helpers. Fix #9 --- src/ImageSharp.Drawing/PathBuilder.cs | 69 +++++++++ src/ImageSharp.Drawing/RectangularPolygon.cs | 3 +- .../RoundedRectanglePolygon.cs | 141 ++++++++++++++++++ .../DrawingCanvasTests.Primitives.cs | 37 +++++ .../Shapes/PathBuilderTests.cs | 24 +++ .../Shapes/RoundedRectangleTests.cs | 77 ++++++++++ ...ctanglePolygon_MatchesReference_Rgba32.png | 3 + 7 files changed, 352 insertions(+), 2 deletions(-) create mode 100644 src/ImageSharp.Drawing/RoundedRectanglePolygon.cs create mode 100644 tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs create mode 100644 tests/Images/ReferenceOutput/Drawing/DrawingCanvasTests/RoundedRectanglePolygon_MatchesReference_Rgba32.png diff --git a/src/ImageSharp.Drawing/PathBuilder.cs b/src/ImageSharp.Drawing/PathBuilder.cs index c40489dd..12165b5d 100644 --- a/src/ImageSharp.Drawing/PathBuilder.cs +++ b/src/ImageSharp.Drawing/PathBuilder.cs @@ -477,6 +477,75 @@ public PathBuilder AddRectangle(float x, float y, float width, float height) new PointF(x + width, y + height), new PointF(x, y + height)); + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The rectangle bounds. + /// The x and y radius of each corner. + /// The . + public PathBuilder AddRoundedRectangle(RectangleF rectangle, float radius) + => this.AddRoundedRectangle(rectangle, new SizeF(radius, radius)); + + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The rectangle bounds. + /// The x and y radii of each corner. + /// The . + public PathBuilder AddRoundedRectangle(RectangleF rectangle, SizeF radius) + { + _ = this.StartFigure(); + + foreach (ILineSegment segment in new RoundedRectanglePolygon(rectangle, radius).LineSegments) + { + _ = this.AddSegment(segment); + } + + return this.CloseFigure(); + } + + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The rectangle bounds. + /// The x and y radius of each corner. + /// The . + public PathBuilder AddRoundedRectangle(Rectangle rectangle, float radius) + => this.AddRoundedRectangle((RectangleF)rectangle, radius); + + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The rectangle bounds. + /// The x and y radii of each corner. + /// The . + public PathBuilder AddRoundedRectangle(Rectangle rectangle, SizeF radius) + => this.AddRoundedRectangle((RectangleF)rectangle, radius); + + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The x-coordinate of the rectangle. + /// The y-coordinate of the rectangle. + /// The rectangle width. + /// The rectangle height. + /// The x and y radius of each corner. + /// The . + public PathBuilder AddRoundedRectangle(float x, float y, float width, float height, float radius) + => this.AddRoundedRectangle(new RectangleF(x, y, width, height), radius); + + /// + /// Adds a rounded rectangle to the current path as a closed figure. + /// + /// The x-coordinate of the rectangle. + /// The y-coordinate of the rectangle. + /// The rectangle width. + /// The rectangle height. + /// The x and y radii of each corner. + /// The . + public PathBuilder AddRoundedRectangle(float x, float y, float width, float height, SizeF radius) + => this.AddRoundedRectangle(new RectangleF(x, y, width, height), radius); + /// /// Adds a polygon to the current path as a closed figure. /// diff --git a/src/ImageSharp.Drawing/RectangularPolygon.cs b/src/ImageSharp.Drawing/RectangularPolygon.cs index f7501a5b..4a695550 100644 --- a/src/ImageSharp.Drawing/RectangularPolygon.cs +++ b/src/ImageSharp.Drawing/RectangularPolygon.cs @@ -6,9 +6,8 @@ namespace SixLabors.ImageSharp.Drawing; /// -/// A polygon tha allows the optimized drawing of rectangles. +/// A closed rectangular path defined by four straight edges. /// -/// public sealed class RectangularPolygon : IPath, ISimplePath, IPathInternals { private readonly Vector2 topLeft; diff --git a/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs b/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs new file mode 100644 index 00000000..6fd816a7 --- /dev/null +++ b/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs @@ -0,0 +1,141 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; + +namespace SixLabors.ImageSharp.Drawing; + +/// +/// A rounded rectangle shape defined by rectangle bounds and corner radii. +/// +public sealed class RoundedRectanglePolygon : Polygon +{ + /// + /// Initializes a new instance of the class. + /// + /// The rectangle bounds. + /// The x and y radius of each corner. + public RoundedRectanglePolygon(RectangleF rectangle, float radius) + : this(rectangle, new SizeF(radius, radius)) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The rectangle bounds. + /// The x and y radii of each corner. + public RoundedRectanglePolygon(RectangleF rectangle, SizeF radius) + : base(CreateSegments(rectangle, radius)) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The x-coordinate of the rectangle. + /// The y-coordinate of the rectangle. + /// The rectangle width. + /// The rectangle height. + /// The x and y radius of each corner. + public RoundedRectanglePolygon(float x, float y, float width, float height, float radius) + : this(new RectangleF(x, y, width, height), radius) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The x-coordinate of the rectangle. + /// The y-coordinate of the rectangle. + /// The rectangle width. + /// The rectangle height. + /// The x and y radii of each corner. + public RoundedRectanglePolygon(float x, float y, float width, float height, SizeF radius) + : this(new RectangleF(x, y, width, height), radius) + { + } + + private RoundedRectanglePolygon(ILineSegment[] segments) + : base(segments, true) + { + } + + /// + public override IPath Transform(Matrix4x4 matrix) + { + if (matrix.IsIdentity) + { + return this; + } + + ILineSegment[] segments = new ILineSegment[this.LineSegments.Count]; + + for (int i = 0; i < segments.Length; i++) + { + segments[i] = this.LineSegments[i].Transform(matrix); + } + + return new RoundedRectanglePolygon(segments); + } + + private static ILineSegment[] CreateSegments(RectangleF rectangle, SizeF radius) + { + float left = MathF.Min(rectangle.Left, rectangle.Right); + float top = MathF.Min(rectangle.Top, rectangle.Bottom); + float right = MathF.Max(rectangle.Left, rectangle.Right); + float bottom = MathF.Max(rectangle.Top, rectangle.Bottom); + float width = right - left; + float height = bottom - top; + + if (width <= 0 || height <= 0) + { + return []; + } + + float radiusX = radius.Width; + float radiusY = radius.Height; + + if (radiusX <= 0 || radiusY <= 0) + { + return + [ + new LinearLineSegment( + new PointF(left, top), + new PointF(right, top), + new PointF(right, bottom), + new PointF(left, bottom)) + ]; + } + + float radiusScale = MathF.Min(width / (radiusX + radiusX), height / (radiusY + radiusY)); + if (radiusScale < 1F) + { + // Preserve the supplied corner shape while shrinking it enough that opposing corners do not overlap. + radiusX *= radiusScale; + radiusY *= radiusScale; + } + + SizeF cornerRadius = new(radiusX, radiusY); + PointF topLeft = new(left + radiusX, top); + PointF topRight = new(right - radiusX, top); + PointF rightTop = new(right, top + radiusY); + PointF rightBottom = new(right, bottom - radiusY); + PointF bottomRight = new(right - radiusX, bottom); + PointF bottomLeft = new(left + radiusX, bottom); + PointF leftBottom = new(left, bottom - radiusY); + PointF leftTop = new(left, top + radiusY); + + return + [ + new LinearLineSegment(topLeft, topRight), + new ArcLineSegment(new PointF(right - radiusX, top + radiusY), cornerRadius, 0F, -90F, 90F), + new LinearLineSegment(rightTop, rightBottom), + new ArcLineSegment(new PointF(right - radiusX, bottom - radiusY), cornerRadius, 0F, 0F, 90F), + new LinearLineSegment(bottomRight, bottomLeft), + new ArcLineSegment(new PointF(left + radiusX, bottom - radiusY), cornerRadius, 0F, 90F, 90F), + new LinearLineSegment(leftBottom, leftTop), + new ArcLineSegment(new PointF(left + radiusX, top + radiusY), cornerRadius, 0F, 180F, 90F) + ]; + } +} diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.Primitives.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.Primitives.cs index 27f4cfc1..ea4ce8b8 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.Primitives.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.Primitives.cs @@ -192,6 +192,43 @@ public void FillPrimitiveHelpers_MatchesReference(TestImageProvider(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image target = provider.GetImage(); + using (DrawingCanvas canvas = CreateCanvas(provider, target, new DrawingOptions())) + { + canvas.Clear(Brushes.Solid(Color.White)); + + // Filled shape proves the rounded rectangle contributes a closed fill region. + canvas.Fill( + Brushes.Solid(Color.CornflowerBlue.WithAlpha(0.75F)), + new RoundedRectanglePolygon(18, 18, 138, 76, 18)); + + // Dashed stroke covers the original issue request: rounded corners must remain a normal strokable path. + canvas.Draw( + Pens.Dash(Color.DarkSlateBlue, 5F), + new RoundedRectanglePolygon(190, 18, 132, 76, 24)); + + // Elliptical radii exercise independent x/y corner curvature. + canvas.Fill( + Brushes.Solid(Color.MediumSeaGreen.WithAlpha(0.78F)), + new RoundedRectanglePolygon(26, 124, 118, 58, new SizeF(28, 12))); + + // Oversized radii should scale down to a capsule-like shape within the supplied bounds. + canvas.Draw( + Pens.Solid(Color.OrangeRed, 6F), + new RoundedRectanglePolygon(188, 122, 138, 62, 90)); + + canvas.Draw(Pens.Solid(Color.Black.WithAlpha(0.5F), 2F), new Rectangle(8, 8, 344, 204)); + } + + target.DebugSave(provider, appendSourceFileOrDescription: false); + target.CompareToReferenceOutput(provider, appendSourceFileOrDescription: false); + } + [Theory] [WithBlankImage(240, 160, PixelTypes.Rgba32)] public void DrawPieHelpers_MatchesReference(TestImageProvider provider) diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs index 4dba0550..7bc1621d 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs @@ -85,6 +85,30 @@ public void AddRectangleMatchesRectangularPolygon() AssertEquivalentPaths(actual, expected); } + [Fact] + public void AddRoundedRectangleMatchesRoundedRectangleShape() + { + PathBuilder builder = new(); + builder.AddRoundedRectangle(new RectangleF(10, 20, 30, 40), new SizeF(5, 8)); + + Polygon actual = Assert.IsType(builder.Build()); + RoundedRectanglePolygon expected = new(10, 20, 30, 40, new SizeF(5, 8)); + + AssertEquivalentPaths(actual, expected); + } + + [Fact] + public void AddRoundedRectangleRadiusOverloadMatchesRoundedRectangleShape() + { + PathBuilder builder = new(); + builder.AddRoundedRectangle(10, 20, 30, 40, 6); + + Polygon actual = Assert.IsType(builder.Build()); + RoundedRectanglePolygon expected = new(10, 20, 30, 40, 6); + + AssertEquivalentPaths(actual, expected); + } + [Fact] public void AddPolygonEnumerableMatchesPolygonShape() { diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs new file mode 100644 index 00000000..5b0dc9a5 --- /dev/null +++ b/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs @@ -0,0 +1,77 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; +using SixLabors.ImageSharp.Drawing.Tests; + +namespace SixLabors.ImageSharp.Drawing.Tests.Shapes; + +public class RoundedRectangleTests +{ + [Fact] + public void BoundsMatchRectangle() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); + + Assert.Equal(new RectangleF(10, 20, 100, 40), shape.Bounds); + } + + [Fact] + public void ZeroRadiusMatchesRectangularPolygon() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 0); + RectangularPolygon rectangle = new(10, 20, 100, 40); + PointF[] actualPoints = shape.Flatten().Single().Points.ToArray(); + PointF[] expectedPoints = rectangle.Flatten().Single().Points.ToArray(); + + Assert.Equal(expectedPoints, actualPoints); + } + + [Fact] + public void RoundedRectangleUsesCurvedCorners() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); + PointF[] points = shape.Flatten().Single().Points.ToArray(); + + Assert.True(points.Length > 4); + } + + [Fact] + public void OversizedRadiusScalesToFitBounds() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 100); + PointF[] points = shape.Flatten().Single().Points.ToArray(); + + Assert.Equal(new RectangleF(10, 20, 100, 40), shape.Bounds); + Assert.True(points.Length > 4); + } + + [Fact] + public void ShapePaths() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); + + Assert.Equal(shape, shape.AsClosedPath()); + } + + [Fact] + public void TransformIdentityReturnsShapeObject() + { + RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); + IPath transformedShape = shape.Transform(Matrix4x4.Identity); + + Assert.Same(shape, transformedShape); + } + + [Fact] + public void Transform() + { + RoundedRectanglePolygon shape = new(0, 0, 100, 40, 12); + + IPath newShape = shape.Transform(new Matrix4x4(new Matrix3x2(0, 1, 1, 0, 20, 2))); + + ApproximateFloatComparer comparer = new(1e-4F); + Assert.Equal(new PointF(20, 2), newShape.Bounds.Location, comparer); + Assert.Equal(new SizeF(40, 100), newShape.Bounds.Size, comparer); + } +} diff --git a/tests/Images/ReferenceOutput/Drawing/DrawingCanvasTests/RoundedRectanglePolygon_MatchesReference_Rgba32.png b/tests/Images/ReferenceOutput/Drawing/DrawingCanvasTests/RoundedRectanglePolygon_MatchesReference_Rgba32.png new file mode 100644 index 00000000..74ce8b7d --- /dev/null +++ b/tests/Images/ReferenceOutput/Drawing/DrawingCanvasTests/RoundedRectanglePolygon_MatchesReference_Rgba32.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc617c86052a45238e9140590a8518b7d90cc314a968293a348f3aa993d6387b +size 7438 From 82d769eb65aac0b081fe04a89bfc09943a414715 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 11 May 2026 00:47:38 +1000 Subject: [PATCH 2/2] Normalize XXPolygon naming --- README.md | 2 +- samples/DrawShapesWithImageSharp/Program.cs | 24 ++--- samples/DrawShapesWithImageSharp/README.md | 2 +- .../Scenes/ApplyReadbackScene.cs | 2 +- .../Scenes/ManualTextFlowScene.cs | 14 +-- .../Scenes/RichTextEditorScene.cs | 10 +- src/ImageSharp.Drawing/PathBuilder.cs | 8 +- .../{Pie.cs => PiePolygon.cs} | 28 +++--- .../Processing/DrawingCanvas.Shapes.cs | 50 +++++----- .../Processing/DrawingCanvas{TPixel}.cs | 4 +- ...tangularPolygon.cs => RectanglePolygon.cs} | 30 +++--- .../RoundedRectanglePolygon.cs | 2 +- src/ImageSharp.Drawing/Star.cs | 99 ------------------- src/ImageSharp.Drawing/StarPolygon.cs | 99 +++++++++++++++++++ .../Drawing/FillPathGradientBrush.cs | 2 +- .../Drawing/ComputeLength.cs | 6 +- .../Issues/Issue_224.cs | 12 +-- .../PolygonGeometry/PolygonClippingTests.cs | 38 +++---- .../Backends/WebGPUDeviceContextTests.cs | 8 +- .../Backends/WebGPUDrawingBackendTests.cs | 64 ++++++------ .../Processing/DrawingCanvasBatcherTests.cs | 6 +- .../DrawingCanvasTests.RegionAndState.cs | 4 +- .../DrawingCanvasTests.SaveCount.cs | 2 +- .../DrawingCanvasTests.SaveLayer.cs | 20 ++-- .../DrawingCanvasTests.TextMeasuring.cs | 20 ++-- .../ProcessWithDrawingCanvasTests.Clip.cs | 6 +- ...ssWithDrawingCanvasTests.FillSolidBrush.cs | 2 +- ...hDrawingCanvasTests.PathGradientBrushes.cs | 2 +- .../ProcessWithDrawingCanvasTests.Polygons.cs | 16 +-- ...rocessWithDrawingCanvasTests.Primitives.cs | 2 +- ...rocessWithDrawingCanvasTests.Robustness.cs | 2 +- .../Shapes/PathBuilderTests.cs | 14 +-- .../Shapes/PathTests.cs | 12 +-- .../{PieTests.cs => PiePolygonTests.cs} | 22 ++--- .../Shapes/RectangleTests.cs | 26 ++--- .../Shapes/RoundedRectangleTests.cs | 77 --------------- .../{StarTests.cs => StarPolygonTests.cs} | 16 +-- .../Shapes/TextBuilderTests.cs | 8 +- ...er.cs => RectanglePolygonValueComparer.cs} | 10 +- ...> FillPolygon_RectanglePolygon_Rgba32.png} | 0 ...ration_Rgba32_BasicTestPattern100x100.png} | 0 ...formed_Rgba32_BasicTestPattern100x100.png} | 0 42 files changed, 347 insertions(+), 424 deletions(-) rename src/ImageSharp.Drawing/{Pie.cs => PiePolygon.cs} (78%) rename src/ImageSharp.Drawing/{RectangularPolygon.cs => RectanglePolygon.cs} (86%) delete mode 100644 src/ImageSharp.Drawing/Star.cs create mode 100644 src/ImageSharp.Drawing/StarPolygon.cs rename tests/ImageSharp.Drawing.Tests/Shapes/{PieTests.cs => PiePolygonTests.cs} (76%) delete mode 100644 tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs rename tests/ImageSharp.Drawing.Tests/Shapes/{StarTests.cs => StarPolygonTests.cs} (83%) rename tests/ImageSharp.Drawing.Tests/TestUtilities/{RectangularPolygonValueComparer.cs => RectanglePolygonValueComparer.cs} (51%) rename tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/{FillPolygon_RectangularPolygon_Rgba32.png => FillPolygon_RectanglePolygon_Rgba32.png} (100%) rename tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/{FillPolygon_RectangularPolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png => FillPolygon_RectanglePolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png} (100%) rename tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/{FillPolygon_RectangularPolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png => FillPolygon_RectanglePolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png} (100%) diff --git a/README.md b/README.md index b4d18f27..ebb65d30 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ image.Mutate(ctx => ctx.Paint(canvas => { canvas.Fill(Brushes.Solid(Color.White)); canvas.Fill(Brushes.Solid(Color.Red), new EllipsePolygon(200, 200, 100)); - canvas.Draw(Pens.Solid(Color.Blue, 3F), new RectangularPolygon(50, 50, 200, 100)); + canvas.Draw(Pens.Solid(Color.Blue, 3F), new RectanglePolygon(50, 50, 200, 100)); })); ``` diff --git a/samples/DrawShapesWithImageSharp/Program.cs b/samples/DrawShapesWithImageSharp/Program.cs index 171bbfd0..431680d5 100644 --- a/samples/DrawShapesWithImageSharp/Program.cs +++ b/samples/DrawShapesWithImageSharp/Program.cs @@ -121,7 +121,7 @@ private static void DrawPosterComposition() // The lake is a plain rectangle filled with a vertical LinearGradientBrush. Building it // with PathBuilder keeps the construction style identical to the surrounding shapes - // even though a RectangularPolygon would also work for an axis-aligned rectangle. + // even though a RectanglePolygon would also work for an axis-aligned rectangle. PathBuilder lakeShape = new(); lakeShape.AddLines( new PointF(0, 432), @@ -175,7 +175,7 @@ private static void DrawPosterComposition() // Save pushes a clipping state; Restore pops it. Anything drawn between the two is // confined to lakeHighlight even though the brush spans its full bounding rectangle. canvas.Save(lakeHighlightClipOptions, lakeHighlight); - canvas.Fill(Brushes.ForwardDiagonal(Color.White.WithAlpha(.36F), Color.Transparent), new RectangularPolygon(lakeHighlightBounds)); + canvas.Fill(Brushes.ForwardDiagonal(Color.White.WithAlpha(.36F), Color.Transparent), new RectanglePolygon(lakeHighlightBounds)); canvas.Restore(); // Title panel: pushing posterPanelOptions onto the canvas with Save activates a @@ -249,7 +249,7 @@ private static void DrawPosterComposition() canvas.Save(posterPanelOptions); canvas.SaveLayer(new GraphicsOptions { BlendPercentage = .94F }, posterPanelLayerBounds); - canvas.Fill(Brushes.Solid(Color.White.WithAlpha(.86F)), new RectangularPolygon(posterPanelBounds)); + canvas.Fill(Brushes.Solid(Color.White.WithAlpha(.86F)), new RectanglePolygon(posterPanelBounds)); canvas.DrawText(posterTextOptions, posterText, Brushes.Solid(Color.DarkSlateGray), pen: null); canvas.Restore(); canvas.Restore(); @@ -296,8 +296,8 @@ private static void DrawTransitMap() pen: null); // Legend panel: reuse the route pens so the key is drawn with the same stroke options as the map. - canvas.Fill(Brushes.Solid(Color.White.WithAlpha(.9F)), new RectangularPolygon(680, 46, 220, 126)); - canvas.Draw(Pens.Solid(Color.LightSlateGray, 2), new RectangularPolygon(680, 46, 220, 126)); + canvas.Fill(Brushes.Solid(Color.White.WithAlpha(.9F)), new RectanglePolygon(680, 46, 220, 126)); + canvas.Draw(Pens.Solid(Color.LightSlateGray, 2), new RectanglePolygon(680, 46, 220, 126)); canvas.DrawLine(harborLinePen, new PointF(708, 78), new PointF(768, 78)); canvas.DrawLine(gardenLoopPen, new PointF(708, 112), new PointF(768, 112)); canvas.DrawLine(airportLinePen, new PointF(708, 146), new PointF(768, 146)); @@ -627,7 +627,7 @@ private static void DrawTypographySheet() // options the draw call uses, otherwise WrappingLength, LineSpacing, or font fallback // can change where the lines break and the box drifts off the text. FontRectangle measuredBox = TextMeasurer.MeasureRenderableBounds(measuredText, measuredOptions); - RectangularPolygon measuredBackground = new( + RectanglePolygon measuredBackground = new( measuredBox.X - 10, measuredBox.Y - 8, measuredBox.Width + 20, @@ -852,9 +852,9 @@ static void DrawPanel( Brush titleBrush, Pen rulePen) { - RectangularPolygon panel = new(origin.X, origin.Y, width, height); + RectanglePolygon panel = new(origin.X, origin.Y, width, height); - // RectangularPolygon implements IPath. The same shape can be both filled (with a + // RectanglePolygon implements IPath. The same shape can be both filled (with a // semi-transparent brush) and stroked (with a pen), which keeps the panel framing // consistent across the sheet without re-allocating geometry. canvas.Fill(Brushes.Solid(Color.White.WithAlpha(.54F)), panel); @@ -947,7 +947,7 @@ static void DrawBeforeAfterWipePanel( // involved. A simple right-half rectangle is the entire mask, so OilPaint runs only // on those pixels and the left half stays as the original photograph. float midX = imageArea.X + (imageArea.Width / 2F); - RectangularPolygon afterRegion = new( + RectanglePolygon afterRegion = new( midX, imageArea.Y, imageArea.Width / 2F, @@ -1019,7 +1019,7 @@ static void DrawImageBrushPanel( imageArea.Y + (imageArea.Height / 2F)); float outerRadius = (MathF.Min(imageArea.Width, imageArea.Height) / 2F) - 6F; float innerRadius = outerRadius * 0.5F; - Star star = new(starCenter.X, starCenter.Y, 5, innerRadius, outerRadius); + StarPolygon star = new(starCenter.X, starCenter.Y, 5, innerRadius, outerRadius); // ImageBrush samples the source image in world coordinates: a destination pixel at // (x, y) reads source pixel (x - offset.X, y - offset.Y) inside SourceRegion. The @@ -1080,7 +1080,7 @@ static void DrawPhotoInTextPanel( ShapeOptions = new ShapeOptions { BooleanOperation = BooleanOperation.Intersection }, }; - canvas.Fill(Brushes.Solid(Color.ParseHex("#E2DCC2")), new RectangularPolygon(imageArea)); + canvas.Fill(Brushes.Solid(Color.ParseHex("#E2DCC2")), new RectanglePolygon(imageArea)); canvas.Save(clipToGlyphs, glyphClips); canvas.DrawImage(source, source.Bounds, imageArea, null); canvas.Restore(); @@ -1109,7 +1109,7 @@ static float DrawPanelChrome( Color titleColor, Color captionColor) { - RectangularPolygon panelShape = new(panel); + RectanglePolygon panelShape = new(panel); canvas.Fill(Brushes.Solid(Color.White), panelShape); canvas.Draw(Pens.Solid(Color.ParseHex("#D7D2C0"), 1), panelShape); diff --git a/samples/DrawShapesWithImageSharp/README.md b/samples/DrawShapesWithImageSharp/README.md index 1225a347..a9b8a286 100644 --- a/samples/DrawShapesWithImageSharp/README.md +++ b/samples/DrawShapesWithImageSharp/README.md @@ -37,7 +37,7 @@ Image-compositing scene demonstrating four ways a photograph (`tests/Images/Inpu - **Before / after wipe** — `canvas.Apply(rightHalfRect, ctx => ctx.OilPaint(15, 5))` scopes an `OilPaint` processor to the right half of the photograph. - **Privacy redaction** — `canvas.Apply(ellipse, ctx => ctx.Pixelate(10))` pixelates an elliptical face-shaped region and leaves the rest untouched. -- **Image as a brush** — `new ImageBrush(source, source.Bounds, brushOffset)` wraps the photograph as a `Brush` so a `Star` path can be filled with it as a texture; the brush offset aligns the mountain in the photograph with the star's centre. +- **Image as a brush** — `new ImageBrush(source, source.Bounds, brushOffset)` wraps the photograph as a `Brush` so a `StarPolygon` path can be filled with it as a texture; the brush offset aligns the mountain in the photograph with the star's centre. - **Photo in text** — `TextBuilder.GeneratePaths("MASK", ...)` produces one `IPath` per glyph; `canvas.Save(intersectionOptions, glyphPaths)` uses them as a compound clip so `DrawImage` only renders inside the letterforms. ## Running diff --git a/samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs b/samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs index 55d10c68..b5118937 100644 --- a/samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs +++ b/samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs @@ -60,7 +60,7 @@ public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime) canvas.Apply(edgeRegion, ctx => ctx.DetectEdges()); canvas.Apply(blurRegion, ctx => ctx.GaussianBlur(Math.Max(3F, Math.Min(viewportSize.Width, viewportSize.Height) / 120F))); - canvas.Draw(Pens.Solid(OutlineColor, 3), new RectangularPolygon(edgeRegion)); + canvas.Draw(Pens.Solid(OutlineColor, 3), new RectanglePolygon(edgeRegion)); canvas.Draw(Pens.Solid(OutlineColor, 3), blurRegion); } diff --git a/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs b/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs index 8cbdaf54..b0641a54 100644 --- a/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs +++ b/samples/WebGPUExternalSurfaceDemo/Scenes/ManualTextFlowScene.cs @@ -185,8 +185,8 @@ public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime) this.cachedObstacleShape = this.obstacleShape; } - canvas.Fill(PageBrush, new RectangularPolygon(pageLeft, pageTop, pageRight - pageLeft, pageBottom - pageTop)); - canvas.Draw(PageOutlinePen, new RectangularPolygon(pageLeft, pageTop, pageRight - pageLeft, pageBottom - pageTop)); + canvas.Fill(PageBrush, new RectanglePolygon(pageLeft, pageTop, pageRight - pageLeft, pageBottom - pageTop)); + canvas.Draw(PageOutlinePen, new RectanglePolygon(pageLeft, pageTop, pageRight - pageLeft, pageBottom - pageTop)); canvas.Fill(ObstacleBrush, obstaclePath); canvas.Draw(ObstacleOutlinePen, obstaclePath); @@ -238,7 +238,7 @@ public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime) // The translucent slot fill is a visual aid for the sample. It // makes the row splitting visible so readers can compare the // available rectangles with the selected obstacle shape. - canvas.Fill(SlotBrush, new RectangularPolygon(slot.Left, y, slotWidth, lineHeight)); + canvas.Fill(SlotBrush, new RectanglePolygon(slot.Left, y, slotWidth, lineHeight)); canvas.DrawText(line, new PointF(slot.Left, y), TextBrush, pen: null); rowHeight = MathF.Max(rowHeight, lineHeight); @@ -274,14 +274,14 @@ private IPath CreateObstaclePath(PointF center, float size) // circle or rectangle math. return this.ObstacleShape switch { - ManualTextFlowObstacleShape.Rectangle => new RectangularPolygon( + ManualTextFlowObstacleShape.Rectangle => new RectanglePolygon( center.X - radius, center.Y - radius, size, size), ManualTextFlowObstacleShape.Triangle => new RegularPolygon(center, 3, radius, 180F), ManualTextFlowObstacleShape.Diamond => new RegularPolygon(center, 4, radius, 0F), - ManualTextFlowObstacleShape.Star => new Star(center, 5, radius * .45F, radius, -18F), + ManualTextFlowObstacleShape.Star => new StarPolygon(center, 5, radius * .45F, radius, -18F), _ => new EllipsePolygon(center, new SizeF(size, size)) }; } @@ -583,7 +583,7 @@ internal enum ManualTextFlowObstacleShape Circle, /// - /// A rectangular obstacle backed by . + /// A rectangular obstacle backed by . /// Rectangle, @@ -598,7 +598,7 @@ internal enum ManualTextFlowObstacleShape Diamond, /// - /// A concave star obstacle backed by . + /// A concave star obstacle backed by . /// Star } diff --git a/samples/WebGPUExternalSurfaceDemo/Scenes/RichTextEditorScene.cs b/samples/WebGPUExternalSurfaceDemo/Scenes/RichTextEditorScene.cs index 2d06daef..68cee345 100644 --- a/samples/WebGPUExternalSurfaceDemo/Scenes/RichTextEditorScene.cs +++ b/samples/WebGPUExternalSurfaceDemo/Scenes/RichTextEditorScene.cs @@ -209,10 +209,10 @@ public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime) } canvas.Fill(BackgroundBrush, canvas.Bounds); - canvas.Fill(EditorBrush, new RectangularPolygon(editorBounds)); - canvas.Draw(BorderPen, new RectangularPolygon(editorBounds)); + canvas.Fill(EditorBrush, new RectanglePolygon(editorBounds)); + canvas.Draw(BorderPen, new RectanglePolygon(editorBounds)); - IPath editorClip = new RectangularPolygon(editorBounds); + IPath editorClip = new RectanglePolygon(editorBounds); // Selection is painted before glyphs, matching normal editor behavior. // The clipping scope applies only to text so the editor chrome remains crisp. @@ -549,11 +549,11 @@ private void DrawSelection(DrawingCanvas canvas, TextMetrics metrics) // That keeps mixed-bidi ranges visually split instead of filling across reordered gaps. canvas.Fill( SelectionBrush, - new RectangularPolygon(rectangle.X, rectangle.Y, width, height)); + new RectanglePolygon(rectangle.X, rectangle.Y, width, height)); canvas.Draw( SelectionBorderPen, - new RectangularPolygon(rectangle.X, rectangle.Y, width, height)); + new RectanglePolygon(rectangle.X, rectangle.Y, width, height)); } } diff --git a/src/ImageSharp.Drawing/PathBuilder.cs b/src/ImageSharp.Drawing/PathBuilder.cs index 12165b5d..a59add5e 100644 --- a/src/ImageSharp.Drawing/PathBuilder.cs +++ b/src/ImageSharp.Drawing/PathBuilder.cs @@ -390,7 +390,7 @@ public PathBuilder AddArc(float x, float y, float radiusX, float radiusY, float /// /// Adds a pie sector to the current path as a closed figure. /// - /// The center point of the pie. + /// The center point of the pie sector. /// The x and y radii of the pie ellipse. /// The ellipse rotation in degrees. /// The pie start angle in degrees. @@ -400,7 +400,7 @@ public PathBuilder AddPie(PointF center, SizeF radius, float rotation, float sta { _ = this.StartFigure(); - foreach (ILineSegment segment in new Pie(center, radius, rotation, startAngle, sweepAngle).LineSegments) + foreach (ILineSegment segment in new PiePolygon(center, radius, rotation, startAngle, sweepAngle).LineSegments) { _ = this.AddSegment(segment); } @@ -411,7 +411,7 @@ public PathBuilder AddPie(PointF center, SizeF radius, float rotation, float sta /// /// Adds a pie sector to the current path as a closed figure. /// - /// The center point of the pie. + /// The center point of the pie sector. /// The x and y radii of the pie ellipse. /// The pie start angle in degrees. /// The pie sweep angle in degrees. @@ -648,7 +648,7 @@ public PathBuilder AddStar(PointF center, int prongs, float innerRadii, float ou { _ = this.StartFigure(); - foreach (ILineSegment segment in new Star(center, prongs, innerRadii, outerRadii, angle).LineSegments) + foreach (ILineSegment segment in new StarPolygon(center, prongs, innerRadii, outerRadii, angle).LineSegments) { _ = this.AddSegment(segment); } diff --git a/src/ImageSharp.Drawing/Pie.cs b/src/ImageSharp.Drawing/PiePolygon.cs similarity index 78% rename from src/ImageSharp.Drawing/Pie.cs rename to src/ImageSharp.Drawing/PiePolygon.cs index 62d02311..f0b8b8e9 100644 --- a/src/ImageSharp.Drawing/Pie.cs +++ b/src/ImageSharp.Drawing/PiePolygon.cs @@ -6,37 +6,37 @@ namespace SixLabors.ImageSharp.Drawing; /// -/// A pie sector shape defined by a center point, radii, rotation, and arc sweep. +/// A pie sector polygon defined by a center point, radii, rotation, and arc sweep. /// -public sealed class Pie : Polygon +public sealed class PiePolygon : Polygon { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The center point of the pie. + /// The center point of the pie sector. /// The x and y radii of the pie ellipse. /// The ellipse rotation in degrees. /// The pie start angle in degrees. /// The pie sweep angle in degrees. - public Pie(PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) + public PiePolygon(PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) : base(CreateSegments(center, radius, rotation, startAngle, sweepAngle)) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - /// The center point of the pie. + /// The center point of the pie sector. /// The x and y radii of the pie ellipse. /// The pie start angle in degrees. /// The pie sweep angle in degrees. - public Pie(PointF center, SizeF radius, float startAngle, float sweepAngle) + public PiePolygon(PointF center, SizeF radius, float startAngle, float sweepAngle) : this(center, radius, 0F, startAngle, sweepAngle) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The x-coordinate of the pie center. /// The y-coordinate of the pie center. @@ -45,13 +45,13 @@ public Pie(PointF center, SizeF radius, float startAngle, float sweepAngle) /// The ellipse rotation in degrees. /// The pie start angle in degrees. /// The pie sweep angle in degrees. - public Pie(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle) + public PiePolygon(float x, float y, float radiusX, float radiusY, float rotation, float startAngle, float sweepAngle) : this(new PointF(x, y), new SizeF(radiusX, radiusY), rotation, startAngle, sweepAngle) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The x-coordinate of the pie center. /// The y-coordinate of the pie center. @@ -59,12 +59,12 @@ public Pie(float x, float y, float radiusX, float radiusY, float rotation, float /// The y-radius of the pie ellipse. /// The pie start angle in degrees. /// The pie sweep angle in degrees. - public Pie(float x, float y, float radiusX, float radiusY, float startAngle, float sweepAngle) + public PiePolygon(float x, float y, float radiusX, float radiusY, float startAngle, float sweepAngle) : this(x, y, radiusX, radiusY, 0F, startAngle, sweepAngle) { } - private Pie(ILineSegment[] segments) + private PiePolygon(ILineSegment[] segments) : base(segments, true) { } @@ -84,7 +84,7 @@ public override IPath Transform(Matrix4x4 matrix) segments[i] = this.LineSegments[i].Transform(matrix); } - return new Pie(segments); + return new PiePolygon(segments); } private static ILineSegment[] CreateSegments(PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) diff --git a/src/ImageSharp.Drawing/Processing/DrawingCanvas.Shapes.cs b/src/ImageSharp.Drawing/Processing/DrawingCanvas.Shapes.cs index 2792eeec..1be510bb 100644 --- a/src/ImageSharp.Drawing/Processing/DrawingCanvas.Shapes.cs +++ b/src/ImageSharp.Drawing/Processing/DrawingCanvas.Shapes.cs @@ -31,7 +31,7 @@ public void Fill(Brush brush) { Rectangle bounds = this.Bounds; - this.Fill(brush, new RectangularPolygon(bounds)); + this.Fill(brush, new RectanglePolygon(bounds)); } /// @@ -40,7 +40,7 @@ public void Fill(Brush brush) /// Brush used to shade destination pixels. /// Region to fill in local coordinates. public void Fill(Brush brush, Rectangle region) - => this.Fill(brush, new RectangularPolygon(region)); + => this.Fill(brush, new RectanglePolygon(region)); /// /// Clears the whole canvas using the given brush and clear-style composition options. @@ -50,7 +50,7 @@ public void Clear(Brush brush) { Rectangle bounds = this.Bounds; - this.Clear(brush, new RectangularPolygon(bounds)); + this.Clear(brush, new RectanglePolygon(bounds)); } /// @@ -59,7 +59,7 @@ public void Clear(Brush brush) /// Brush used to shade destination pixels during clear. /// Region to clear in local coordinates. public void Clear(Brush brush, Rectangle region) - => this.Clear(brush, new RectangularPolygon(region)); + => this.Clear(brush, new RectanglePolygon(region)); /// /// Fills all paths in a collection using the given brush. @@ -113,24 +113,24 @@ public void FillArc(Brush brush, PointF center, SizeF radius, float rotation, fl /// Fills a pie sector using the provided brush. /// /// Brush used to shade covered pixels. - /// Pie center point in local coordinates. - /// Pie radii in local coordinates. + /// The center point of the pie sector in local coordinates. + /// The x and y radii of the pie sector in local coordinates. /// Ellipse rotation in degrees. - /// Pie start angle in degrees. - /// Pie sweep angle in degrees. + /// The start angle of the pie sector in degrees. + /// The sweep angle of the pie sector in degrees. public void FillPie(Brush brush, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) - => this.Fill(brush, new Pie(center, radius, rotation, startAngle, sweepAngle)); + => this.Fill(brush, new PiePolygon(center, radius, rotation, startAngle, sweepAngle)); /// /// Fills a pie sector using the provided brush. /// /// Brush used to shade covered pixels. - /// Pie center point in local coordinates. - /// Pie radii in local coordinates. - /// Pie start angle in degrees. - /// Pie sweep angle in degrees. + /// The center point of the pie sector in local coordinates. + /// The x and y radii of the pie sector in local coordinates. + /// The start angle of the pie sector in degrees. + /// The sweep angle of the pie sector in degrees. public void FillPie(Brush brush, PointF center, SizeF radius, float startAngle, float sweepAngle) - => this.Fill(brush, new Pie(center, radius, startAngle, sweepAngle)); + => this.Fill(brush, new PiePolygon(center, radius, startAngle, sweepAngle)); /// /// Draws an arc outline using the provided pen. @@ -169,24 +169,24 @@ public void DrawEllipse(Pen pen, PointF center, SizeF size) /// Draws a pie sector outline using the provided pen. /// /// Pen used to generate the pie outline. - /// Pie center point in local coordinates. - /// Pie radii in local coordinates. + /// The center point of the pie sector in local coordinates. + /// The x and y radii of the pie sector in local coordinates. /// Ellipse rotation in degrees. - /// Pie start angle in degrees. - /// Pie sweep angle in degrees. + /// The start angle of the pie sector in degrees. + /// The sweep angle of the pie sector in degrees. public void DrawPie(Pen pen, PointF center, SizeF radius, float rotation, float startAngle, float sweepAngle) - => this.Draw(pen, new Pie(center, radius, rotation, startAngle, sweepAngle)); + => this.Draw(pen, new PiePolygon(center, radius, rotation, startAngle, sweepAngle)); /// /// Draws a pie sector outline using the provided pen. /// /// Pen used to generate the pie outline. - /// Pie center point in local coordinates. - /// Pie radii in local coordinates. - /// Pie start angle in degrees. - /// Pie sweep angle in degrees. + /// The center point of the pie sector in local coordinates. + /// The x and y radii of the pie sector in local coordinates. + /// The start angle of the pie sector in degrees. + /// The sweep angle of the pie sector in degrees. public void DrawPie(Pen pen, PointF center, SizeF radius, float startAngle, float sweepAngle) - => this.Draw(pen, new Pie(center, radius, startAngle, sweepAngle)); + => this.Draw(pen, new PiePolygon(center, radius, startAngle, sweepAngle)); /// /// Draws a rectangular outline using the provided pen. @@ -194,7 +194,7 @@ public void DrawPie(Pen pen, PointF center, SizeF radius, float startAngle, floa /// Pen used to generate the rectangle outline. /// Rectangle region to stroke. public void Draw(Pen pen, Rectangle region) - => this.Draw(pen, new RectangularPolygon(region)); + => this.Draw(pen, new RectanglePolygon(region)); /// /// Draws all paths in a collection using the provided pen. diff --git a/src/ImageSharp.Drawing/Processing/DrawingCanvas{TPixel}.cs b/src/ImageSharp.Drawing/Processing/DrawingCanvas{TPixel}.cs index e6ba364d..dc4bb784 100644 --- a/src/ImageSharp.Drawing/Processing/DrawingCanvas{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/DrawingCanvas{TPixel}.cs @@ -283,7 +283,7 @@ public override void Fill(Brush brush, IPath path) /// public override void Apply(Rectangle region, Action operation) - => this.Apply(new RectangularPolygon(region), operation); + => this.Apply(new RectanglePolygon(region), operation); /// public override void Apply(PathBuilder pathBuilder, Action operation) @@ -813,7 +813,7 @@ private void DrawImageCore( } ImageBrush brush = new(brushImage, brushImageRegion); - IPath destinationPath = new RectangularPolygon( + IPath destinationPath = new RectanglePolygon( renderDestinationRect.X, renderDestinationRect.Y, renderDestinationRect.Width, diff --git a/src/ImageSharp.Drawing/RectangularPolygon.cs b/src/ImageSharp.Drawing/RectanglePolygon.cs similarity index 86% rename from src/ImageSharp.Drawing/RectangularPolygon.cs rename to src/ImageSharp.Drawing/RectanglePolygon.cs index 4a695550..352fea7c 100644 --- a/src/ImageSharp.Drawing/RectangularPolygon.cs +++ b/src/ImageSharp.Drawing/RectanglePolygon.cs @@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Drawing; /// /// A closed rectangular path defined by four straight edges. /// -public sealed class RectangularPolygon : IPath, ISimplePath, IPathInternals +public sealed class RectanglePolygon : IPath, ISimplePath, IPathInternals { private readonly Vector2 topLeft; private readonly Vector2 bottomRight; @@ -18,27 +18,27 @@ public sealed class RectangularPolygon : IPath, ISimplePath, IPathInternals private LinearGeometryCache geometryCache; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The horizontal position of the rectangle. /// The vertical position of the rectangle. /// The width of the rectangle. /// The height of the rectangle. - public RectangularPolygon(float x, float y, float width, float height) + public RectanglePolygon(float x, float y, float width, float height) : this(new PointF(x, y), new SizeF(width, height)) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The which specifies the rectangles top/left point in a two-dimensional plane. + /// The which specifies the rectangle's top-left point in a two-dimensional plane. /// /// - /// The which specifies the rectangles bottom/right point in a two-dimensional plane. + /// The which specifies the rectangle's bottom-right point in a two-dimensional plane. /// - public RectangularPolygon(PointF topLeft, PointF bottomRight) + public RectanglePolygon(PointF topLeft, PointF bottomRight) { this.Location = topLeft; this.topLeft = topLeft; @@ -59,24 +59,24 @@ public RectangularPolygon(PointF topLeft, PointF bottomRight) } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// - /// The which specifies the rectangles point in a two-dimensional plane. + /// The which specifies the rectangle's point in a two-dimensional plane. /// /// - /// The which specifies the rectangles height and width. + /// The which specifies the rectangle's height and width. /// - public RectangularPolygon(PointF point, SizeF size) + public RectanglePolygon(PointF point, SizeF size) : this(point, point + size) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The rectangle. - public RectangularPolygon(RectangleF rectangle) + public RectanglePolygon(RectangleF rectangle) : this(rectangle.Location, rectangle.Location + rectangle.Size) { } @@ -149,10 +149,10 @@ public RectangularPolygon(RectangleF rectangle) public PointF Center => (this.topLeft + this.bottomRight) / 2; /// - /// Converts the polygon to a rectangular polygon from its bounds. + /// Converts a polygon to a rectangle polygon from its bounds. /// /// The polygon to convert. - public static explicit operator RectangularPolygon(Polygon polygon) + public static explicit operator RectanglePolygon(Polygon polygon) => new(polygon.Bounds.X, polygon.Bounds.Y, polygon.Bounds.Width, polygon.Bounds.Height); /// diff --git a/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs b/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs index 6fd816a7..b24d60a0 100644 --- a/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs +++ b/src/ImageSharp.Drawing/RoundedRectanglePolygon.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Drawing; /// -/// A rounded rectangle shape defined by rectangle bounds and corner radii. +/// A closed rectangular path with rounded corners. /// public sealed class RoundedRectanglePolygon : Polygon { diff --git a/src/ImageSharp.Drawing/Star.cs b/src/ImageSharp.Drawing/Star.cs deleted file mode 100644 index 380cb68d..00000000 --- a/src/ImageSharp.Drawing/Star.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -using System.Numerics; - -namespace SixLabors.ImageSharp.Drawing; - -/// -/// A shape made up of a single closed path made up of one of more s -/// -public sealed class Star : Polygon -{ - /// - /// Initializes a new instance of the class. - /// - /// The location the center of the polygon will be placed. - /// The number of points the should have. - /// The inner radii. - /// The outer radii. - /// The angle of rotation in degrees. - public Star(PointF location, int prongs, float innerRadii, float outerRadii, float angle) - : base(CreateSegment(location, innerRadii, outerRadii, prongs, angle)) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The location the center of the polygon will be placed. - /// The number of vertices the should have. - /// The inner radii. - /// The outer radii. - public Star(PointF location, int prongs, float innerRadii, float outerRadii) - : this(location, prongs, innerRadii, outerRadii, 0) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The x-coordinate of the center of the polygon. - /// The y-coordinate of the center of the polygon. - /// The number of vertices the should have. - /// The inner radii. - /// The outer radii. - /// The angle of rotation in degrees. - public Star(float x, float y, int prongs, float innerRadii, float outerRadii, float angle) - : this(new PointF(x, y), prongs, innerRadii, outerRadii, angle) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The x-coordinate of the center of the polygon. - /// The y-coordinate of the center of the polygon. - /// The number of vertices the should have. - /// The inner radii. - /// The outer radii. - public Star(float x, float y, int prongs, float innerRadii, float outerRadii) - : this(new PointF(x, y), prongs, innerRadii, outerRadii) - { - } - - private static LinearLineSegment CreateSegment(Vector2 location, float innerRadii, float outerRadii, int prongs, float angle) - { - Guard.MustBeGreaterThan(prongs, 2, nameof(prongs)); - Guard.MustBeGreaterThan(innerRadii, 0, nameof(innerRadii)); - Guard.MustBeGreaterThan(outerRadii, 0, nameof(outerRadii)); - - Vector2 distanceVectorInner = new(0, innerRadii); - Vector2 distanceVectorOuter = new(0, outerRadii); - - int vertices = prongs * 2; - float anglePerSegments = (float)(2 * Math.PI / vertices); - float current = GeometryUtilities.DegreeToRadian(angle); - PointF[] points = new PointF[vertices]; - Vector2 distance = distanceVectorInner; - for (int i = 0; i < vertices; i++) - { - if (distance == distanceVectorInner) - { - distance = distanceVectorOuter; - } - else - { - distance = distanceVectorInner; - } - - Vector2 rotated = PointF.Transform(distance, Matrix4x4.CreateRotationZ(current)); - - points[i] = rotated + location; - - current += anglePerSegments; - } - - return new LinearLineSegment(points); - } -} diff --git a/src/ImageSharp.Drawing/StarPolygon.cs b/src/ImageSharp.Drawing/StarPolygon.cs new file mode 100644 index 00000000..68a27955 --- /dev/null +++ b/src/ImageSharp.Drawing/StarPolygon.cs @@ -0,0 +1,99 @@ +// Copyright (c) Six Labors. +// Licensed under the Six Labors Split License. + +using System.Numerics; + +namespace SixLabors.ImageSharp.Drawing; + +/// +/// A star-shaped polygon defined by alternating inner and outer radii. +/// +public sealed class StarPolygon : Polygon +{ + /// + /// Initializes a new instance of the class. + /// + /// The center point of the star. + /// The number of star prongs. + /// The inner star radius. + /// The outer star radius. + /// The angle of rotation in degrees. + public StarPolygon(PointF location, int prongs, float innerRadii, float outerRadii, float angle) + : base(CreateSegment(location, innerRadii, outerRadii, prongs, angle)) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The center point of the star. + /// The number of star prongs. + /// The inner star radius. + /// The outer star radius. + public StarPolygon(PointF location, int prongs, float innerRadii, float outerRadii) + : this(location, prongs, innerRadii, outerRadii, 0) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The x-coordinate of the star center. + /// The y-coordinate of the star center. + /// The number of star prongs. + /// The inner star radius. + /// The outer star radius. + /// The angle of rotation in degrees. + public StarPolygon(float x, float y, int prongs, float innerRadii, float outerRadii, float angle) + : this(new PointF(x, y), prongs, innerRadii, outerRadii, angle) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The x-coordinate of the star center. + /// The y-coordinate of the star center. + /// The number of star prongs. + /// The inner star radius. + /// The outer star radius. + public StarPolygon(float x, float y, int prongs, float innerRadii, float outerRadii) + : this(new PointF(x, y), prongs, innerRadii, outerRadii) + { + } + + private static LinearLineSegment CreateSegment(Vector2 location, float innerRadii, float outerRadii, int prongs, float angle) + { + Guard.MustBeGreaterThan(prongs, 2, nameof(prongs)); + Guard.MustBeGreaterThan(innerRadii, 0, nameof(innerRadii)); + Guard.MustBeGreaterThan(outerRadii, 0, nameof(outerRadii)); + + Vector2 distanceVectorInner = new(0, innerRadii); + Vector2 distanceVectorOuter = new(0, outerRadii); + + int vertices = prongs * 2; + float anglePerSegments = (float)(2 * Math.PI / vertices); + float current = GeometryUtilities.DegreeToRadian(angle); + PointF[] points = new PointF[vertices]; + Vector2 distance = distanceVectorInner; + for (int i = 0; i < vertices; i++) + { + if (distance == distanceVectorInner) + { + distance = distanceVectorOuter; + } + else + { + distance = distanceVectorInner; + } + + Vector2 rotated = PointF.Transform(distance, Matrix4x4.CreateRotationZ(current)); + + points[i] = rotated + location; + + current += anglePerSegments; + } + + return new LinearLineSegment(points); + } +} diff --git a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs index d42b5deb..01d1e408 100644 --- a/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs +++ b/tests/ImageSharp.Drawing.Benchmarks/Drawing/FillPathGradientBrush.cs @@ -21,7 +21,7 @@ public class FillPathGradientBrush [Benchmark] public void FillGradientBrush_ImageSharp() { - Star star = new(50, 50, 5, 20, 45); + StarPolygon star = new(50, 50, 5, 20, 45); PointF[] points = star.Points.ToArray(); Color[] colors = [ diff --git a/tests/ImageSharp.Drawing.Tests/Drawing/ComputeLength.cs b/tests/ImageSharp.Drawing.Tests/Drawing/ComputeLength.cs index cba7efce..ca46d384 100644 --- a/tests/ImageSharp.Drawing.Tests/Drawing/ComputeLength.cs +++ b/tests/ImageSharp.Drawing.Tests/Drawing/ComputeLength.cs @@ -8,7 +8,7 @@ public class ComputeLength [Fact] public void CanComputeUnrolledLength() { - RectangularPolygon polygon = new(PointF.Empty, new PointF(100, 200)); + RectanglePolygon polygon = new(PointF.Empty, new PointF(100, 200)); Assert.Equal(600, polygon.ComputeLength()); } @@ -17,8 +17,8 @@ public void CanComputeUnrolledLength() public void CanComputeUnrolledLengthComplexPath() { ComplexPolygon polygon = new( - new RectangularPolygon(PointF.Empty, new PointF(100, 200)), - new RectangularPolygon(new PointF(1000, 1000), new PointF(1100, 1200))); + new RectanglePolygon(PointF.Empty, new PointF(100, 200)), + new RectanglePolygon(new PointF(1000, 1000), new PointF(1100, 1200))); Assert.Equal(1200, polygon.ComputeLength()); } diff --git a/tests/ImageSharp.Drawing.Tests/Issues/Issue_224.cs b/tests/ImageSharp.Drawing.Tests/Issues/Issue_224.cs index f32eb5fe..997345ff 100644 --- a/tests/ImageSharp.Drawing.Tests/Issues/Issue_224.cs +++ b/tests/ImageSharp.Drawing.Tests/Issues/Issue_224.cs @@ -11,7 +11,7 @@ public class Issue_224 [Fact] public async Task OutliningWithZeroWidth_MultiplePatterns() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(0, [1, 2])); } @@ -19,7 +19,7 @@ public async Task OutliningWithZeroWidth_MultiplePatterns() [Fact] public async Task OutliningWithZeroWidth_SinglePAttern() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(0, [1])); } @@ -27,7 +27,7 @@ public async Task OutliningWithZeroWidth_SinglePAttern() [Fact] public async Task OutliningWithZeroWidth_NoPattern() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(0)); } @@ -35,7 +35,7 @@ public async Task OutliningWithZeroWidth_NoPattern() [Fact] public async Task OutliningWithLessThanZeroWidth_MultiplePatterns() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(-10, [1, 2])); } @@ -43,7 +43,7 @@ public async Task OutliningWithLessThanZeroWidth_MultiplePatterns() [Fact] public async Task OutliningWithLessThanZeroWidth_SinglePAttern() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(-10, [1])); } @@ -51,7 +51,7 @@ public async Task OutliningWithLessThanZeroWidth_SinglePAttern() [Fact] public async Task OutliningWithLessThanZeroWidth_NoPattern() { - RectangularPolygon shape = new(10, 10, 10, 10); + RectanglePolygon shape = new(10, 10, 10, 10); await CompletesIn(TimeSpan.FromSeconds(1), () => _ = shape.GenerateOutline(-10)); } diff --git a/tests/ImageSharp.Drawing.Tests/PolygonGeometry/PolygonClippingTests.cs b/tests/ImageSharp.Drawing.Tests/PolygonGeometry/PolygonClippingTests.cs index 4e741462..f4e0899f 100644 --- a/tests/ImageSharp.Drawing.Tests/PolygonGeometry/PolygonClippingTests.cs +++ b/tests/ImageSharp.Drawing.Tests/PolygonGeometry/PolygonClippingTests.cs @@ -10,11 +10,11 @@ namespace SixLabors.ImageSharp.Drawing.Tests.PolygonGeometry; public class PolygonClippingTests { - private readonly RectangularPolygon bigSquare = new(10, 10, 40, 40); - private readonly RectangularPolygon hole = new(20, 20, 10, 10); - private readonly RectangularPolygon topLeft = new(0, 0, 20, 20); - private readonly RectangularPolygon topRight = new(30, 0, 20, 20); - private readonly RectangularPolygon topMiddle = new(20, 0, 10, 20); + private readonly RectanglePolygon bigSquare = new(10, 10, 40, 40); + private readonly RectanglePolygon hole = new(20, 20, 10, 10); + private readonly RectanglePolygon topLeft = new(0, 0, 20, 20); + private readonly RectanglePolygon topRight = new(30, 0, 20, 20); + private readonly RectanglePolygon topMiddle = new(20, 0, 10, 20); private readonly Polygon bigTriangle = new(new LinearLineSegment( new Vector2(10, 10), @@ -58,19 +58,19 @@ public void OverlappingTriangles() Assert.Equal(7, path.Length); foreach (Vector2 p in this.bigTriangle.Flatten().First().Points.ToArray()) { - Assert.Contains(p, path, new ApproximateFloatComparer(RectangularPolygonValueComparer.DefaultTolerance)); + Assert.Contains(p, path, new ApproximateFloatComparer(RectanglePolygonValueComparer.DefaultTolerance)); } } [Fact] public void NonOverlapping() { - IEnumerable shapes = Clip(this.topLeft, this.topRight).Paths - .OfType().Select(x => (RectangularPolygon)x); + IEnumerable shapes = Clip(this.topLeft, this.topRight).Paths + .OfType().Select(x => (RectanglePolygon)x); Assert.Single(shapes); Assert.Contains( - shapes, x => RectangularPolygonValueComparer.Equals(this.topLeft, x)); + shapes, x => RectanglePolygonValueComparer.Equals(this.topLeft, x)); Assert.DoesNotContain(this.topRight, shapes); } @@ -81,20 +81,20 @@ public void OverLappingReturns1NewShape() ComplexPolygon shapes = Clip(this.bigSquare, this.topLeft); Assert.Single(shapes.Paths); - Assert.DoesNotContain(shapes.Paths, x => RectangularPolygonValueComparer.Equals(this.bigSquare, x)); - Assert.DoesNotContain(shapes.Paths, x => RectangularPolygonValueComparer.Equals(this.topLeft, x)); + Assert.DoesNotContain(shapes.Paths, x => RectanglePolygonValueComparer.Equals(this.bigSquare, x)); + Assert.DoesNotContain(shapes.Paths, x => RectanglePolygonValueComparer.Equals(this.topLeft, x)); } [Fact] public void OverlappingButNotCrossingReturnsOrigionalShapes() { - IEnumerable shapes = Clip(this.bigSquare, this.hole).Paths - .OfType().Select(x => (RectangularPolygon)x); + IEnumerable shapes = Clip(this.bigSquare, this.hole).Paths + .OfType().Select(x => (RectanglePolygon)x); Assert.Equal(2, shapes.Count()); - Assert.Contains(shapes, x => RectangularPolygonValueComparer.Equals(this.bigSquare, x)); - Assert.Contains(shapes, x => RectangularPolygonValueComparer.Equals(this.hole, x)); + Assert.Contains(shapes, x => RectanglePolygonValueComparer.Equals(this.bigSquare, x)); + Assert.Contains(shapes, x => RectanglePolygonValueComparer.Equals(this.hole, x)); } [Fact] @@ -102,15 +102,15 @@ public void TouchingButNotOverlapping() { ComplexPolygon shapes = Clip(this.topMiddle, this.topLeft); Assert.Single(shapes.Paths); - Assert.DoesNotContain(shapes.Paths, x => RectangularPolygonValueComparer.Equals(this.topMiddle, x)); - Assert.DoesNotContain(shapes.Paths, x => RectangularPolygonValueComparer.Equals(this.topLeft, x)); + Assert.DoesNotContain(shapes.Paths, x => RectanglePolygonValueComparer.Equals(this.topMiddle, x)); + Assert.DoesNotContain(shapes.Paths, x => RectanglePolygonValueComparer.Equals(this.topLeft, x)); } [Fact] public void ClippingRectanglesCreateCorrectNumberOfPoints() { - IEnumerable paths = new RectangularPolygon(10, 10, 40, 40) - .Clip(new RectangularPolygon(20, 0, 20, 20)) + IEnumerable paths = new RectanglePolygon(10, 10, 40, 40) + .Clip(new RectanglePolygon(20, 0, 20, 20)) .Flatten(); Assert.Single(paths); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDeviceContextTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDeviceContextTests.cs index a983022b..d27504a5 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDeviceContextTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDeviceContextTests.cs @@ -51,7 +51,7 @@ public void CreateCanvas_WithExternalTexture_UsesGpuPath() 32, 24)) { - canvas.Fill(Brushes.Solid(Color.Red), new RectangularPolygon(0, 0, 32, 24)); + canvas.Fill(Brushes.Solid(Color.Red), new RectanglePolygon(0, 0, 32, 24)); } using Image readback = target.ReadbackImage(); @@ -65,7 +65,7 @@ public void RenderTarget_CreateCanvas_RendersAndReadsBack() using WebGPURenderTarget target = drawing.CreateRenderTarget(18, 14); using (DrawingCanvas canvas = target.CreateCanvas()) { - canvas.Fill(Brushes.Solid(Color.Green), new RectangularPolygon(0, 0, 18, 14)); + canvas.Fill(Brushes.Solid(Color.Green), new RectanglePolygon(0, 0, 18, 14)); } using Image readback = target.ReadbackImage(); @@ -78,7 +78,7 @@ public void RenderTarget_ReadbackImage_UsesTargetFormat() using WebGPURenderTarget target = new(WebGPUTextureFormat.Bgra8Unorm, 8, 6); using (DrawingCanvas canvas = target.CreateCanvas()) { - canvas.Fill(Brushes.Solid(Color.Red), new RectangularPolygon(0, 0, 8, 6)); + canvas.Fill(Brushes.Solid(Color.Red), new RectanglePolygon(0, 0, 8, 6)); } using Image readback = target.ReadbackImage(); @@ -94,7 +94,7 @@ public void RenderTarget_ReadbackInto_BufferRegion_WritesSubregion() using WebGPURenderTarget target = new(6, 4); using (DrawingCanvas canvas = target.CreateCanvas()) { - canvas.Fill(Brushes.Solid(Color.Red), new RectangularPolygon(-1, -1, target.Width + 2, target.Height + 2)); + canvas.Fill(Brushes.Solid(Color.Red), new RectanglePolygon(-1, -1, target.Width + 2, target.Height + 2)); } using Image destination = new(10, 8, Color.Blue.ToPixel()); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDrawingBackendTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDrawingBackendTests.cs index 8e012d50..2c12a30e 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDrawingBackendTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/Backends/WebGPUDrawingBackendTests.cs @@ -43,7 +43,7 @@ public void FillPath_WithWebGPUCoverageBackend_MatchesDefaultOutput(Test GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon polygon = new(48.25F, 63.5F, 401.25F, 302.75F); + RectanglePolygon polygon = new(48.25F, 63.5F, 401.25F, 302.75F); Brush brush = Brushes.Solid(Color.Black); void DrawAction(DrawingCanvas canvas) => canvas.Fill(brush, polygon); @@ -151,7 +151,7 @@ public void FillPath_WithImageBrush_MatchesDefaultOutput(TestImageProvid GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon polygon = new(36.5F, 26.25F, 312.5F, 188.5F); + RectanglePolygon polygon = new(36.5F, 26.25F, 312.5F, 188.5F); Brush clearBrush = Brushes.Solid(Color.White); using Image foreground = provider.GetImage(); @@ -248,7 +248,7 @@ public void FillPath_WithGraphicsOptionsModes_SolidBrush_MatchesDefaultOutput { - RectangularPolygon polygon = new(26.5F, 18.25F, 324.5F, 208.75F); + RectanglePolygon polygon = new(26.5F, 18.25F, 324.5F, 208.75F); Brush brush = Brushes.Solid(Color.OrangeRed.WithAlpha(0.78F)); DrawingOptions drawingOptions = new() @@ -298,7 +298,7 @@ public void FillPath_WithGraphicsOptionsModes_ImageBrush_MatchesDefaultOutput { - RectangularPolygon polygon = new(26.5F, 18.25F, 324.5F, 208.75F); + RectanglePolygon polygon = new(26.5F, 18.25F, 324.5F, 208.75F); DrawingOptions drawingOptions = new() { @@ -394,7 +394,7 @@ public void FillPath_WithWebGPUCoverageBackend_NativeSurface_MatchesDefaultOutpu GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon polygon = new(48.25F, 63.5F, 401.25F, 302.75F); + RectanglePolygon polygon = new(48.25F, 63.5F, 401.25F, 302.75F); Brush brush = Brushes.Solid(Color.Black); Brush clearBrush = Brushes.Solid(Color.White); void DrawAction(DrawingCanvas canvas) @@ -431,7 +431,7 @@ public void FillPath_WithWebGPUCoverageBackend_NativeSurfaceSubregion_MatchesDef GraphicsOptions = new GraphicsOptions { Antialias = true } }; Rectangle region = new(72, 64, 320, 240); - RectangularPolygon localPolygon = new(16.25F, 24.5F, 250.5F, 160.75F); + RectanglePolygon localPolygon = new(16.25F, 24.5F, 250.5F, 160.75F); Brush brush = Brushes.Solid(Color.Black); Brush clearBrush = Brushes.Solid(Color.White); void DrawAction(DrawingCanvas canvas) @@ -477,8 +477,8 @@ public void Fill_AfterPreviousFrameOnNativeSurface_MatchesDefaultOutput( Brush firstFill = Brushes.Solid(Color.OrangeRed); Brush secondBackground = Brushes.Solid(Color.MidnightBlue); Brush secondFill = Brushes.Solid(Color.LimeGreen); - RectangularPolygon firstRect = new(18, 26, 176, 92); - RectangularPolygon secondRect = new(96, 54, 42, 38); + RectanglePolygon firstRect = new(18, 26, 176, 92); + RectanglePolygon secondRect = new(96, 54, 42, 38); void DrawFirstFrame(DrawingCanvas canvas) { @@ -713,7 +713,7 @@ private static IPath CreateClipReduceLayerLocalPath(int layerIndex, Rectangle la int innerHeight = Math.Max(4, layerBounds.Height - insetY - heightTrim); return (layerIndex & 1) == 0 - ? new RectangularPolygon(insetX, insetY, innerWidth, innerHeight) + ? new RectanglePolygon(insetX, insetY, innerWidth, innerHeight) : new EllipsePolygon( insetX + (innerWidth / 2F), insetY + (innerHeight / 2F), @@ -1133,7 +1133,7 @@ void DrawAction(DrawingCanvas canvas) { float x = 20 + (i * 24); float y = 20 + (i * 22); - canvas.Fill(brush, new RectangularPolygon(x, y, 80, 60)); + canvas.Fill(brush, new RectanglePolygon(x, y, 80, 60)); } } @@ -1333,8 +1333,8 @@ public void MultipleFlushes_OnSameBackend_ProduceCorrectResults(TestImag Brush redBrush = Brushes.Solid(Color.Red); Brush blueBrush = Brushes.Solid(Color.Blue); - RectangularPolygon rect1 = new(20, 20, 120, 80); - RectangularPolygon rect2 = new(160, 100, 120, 80); + RectanglePolygon rect1 = new(20, 20, 120, 80); + RectanglePolygon rect2 = new(160, 100, 120, 80); void DrawAction(DrawingCanvas canvas) { canvas.Clear(Brushes.Solid(Color.White)); @@ -1592,7 +1592,7 @@ public void FillPath_WithLinearGradientBrush_Repeat_MatchesDefaultOutput GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon rect = new(16, 16, 224, 224); + RectanglePolygon rect = new(16, 16, 224, 224); Brush brush = new LinearGradientBrush( new PointF(64, 64), new PointF(128, 128), @@ -1630,7 +1630,7 @@ public void FillPath_WithRadialGradientBrush_SingleCircle_MatchesDefaultOutput(Test GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon rect = new(16, 16, 224, 224); + RectanglePolygon rect = new(16, 16, 224, 224); Brush brush = new EllipticGradientBrush( new PointF(128, 128), new PointF(228, 128), @@ -1788,7 +1788,7 @@ public void FillPath_WithSweepGradientBrush_PartialArc_MatchesDefaultOutput(TestImag }; Rectangle region = new(72, 40, 240, 176); - RectangularPolygon localPolygon = new(12, 10, 216, 156); + RectanglePolygon localPolygon = new(12, 10, 216, 156); EllipsePolygon persistedShape = new(new PointF(176, 128), new SizeF(320, 176)); Brush persistedBrush = Brushes.Solid(Color.DarkSlateBlue); Brush brush = new PathGradientBrush( @@ -1894,7 +1894,7 @@ public void FillPath_WithPatternBrush_MatchesDefaultOutput(TestImageProv GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon rect = new(16, 16, 224, 224); + RectanglePolygon rect = new(16, 16, 224, 224); Brush brush = Brushes.Horizontal(Color.Black, Color.White); void DrawAction(DrawingCanvas canvas) => canvas.Fill(brush, rect); @@ -1960,7 +1960,7 @@ public void FillPath_WithRecolorBrush_MatchesDefaultOutput(TestImageProv GraphicsOptions = new GraphicsOptions { Antialias = true } }; - RectangularPolygon rect = new(16, 16, 224, 224); + RectanglePolygon rect = new(16, 16, 224, 224); Brush brush = new RecolorBrush(Color.Red, Color.Blue, 0.5F); void DrawAction(DrawingCanvas canvas) => canvas.Fill(brush, rect); @@ -1993,7 +1993,7 @@ public void FillPath_WithLinearGradientBrush_ThreePoint_MatchesDefaultOutput(TestImageProvider { DrawingOptions drawingOptions = new(); Brush brush = Brushes.Solid(Color.Red); - RectangularPolygon polygon = new(10, 10, 80, 80); + RectanglePolygon polygon = new(10, 10, 80, 80); void DrawAction(DrawingCanvas canvas) { @@ -2334,7 +2334,7 @@ public void SaveLayer_HalfOpacity_MatchesDefaultOutput(TestImageProvider { DrawingOptions drawingOptions = new(); Brush brush = Brushes.Solid(Color.Red); - RectangularPolygon polygon = new(10, 10, 80, 80); + RectanglePolygon polygon = new(10, 10, 80, 80); void DrawAction(DrawingCanvas canvas) { @@ -2375,11 +2375,11 @@ static void DrawAction(DrawingCanvas canvas) // Outer layer: red fill. canvas.SaveLayer(); - canvas.Fill(Brushes.Solid(Color.Red), new RectangularPolygon(0, 0, 128, 128)); + canvas.Fill(Brushes.Solid(Color.Red), new RectanglePolygon(0, 0, 128, 128)); // Inner layer: blue fill over center. canvas.SaveLayer(); - canvas.Fill(Brushes.Solid(Color.Blue), new RectangularPolygon(32, 32, 64, 64)); + canvas.Fill(Brushes.Solid(Color.Blue), new RectanglePolygon(32, 32, 64, 64)); canvas.Restore(); // Composites blue onto red. canvas.Restore(); // Composites red+blue onto white. @@ -2413,7 +2413,7 @@ public void SaveLayer_WithBlendMode_MatchesDefaultOutput(TestImageProvid static void DrawAction(DrawingCanvas canvas) { canvas.Fill(Brushes.Solid(Color.White)); - canvas.Fill(Brushes.Solid(Color.Red), new RectangularPolygon(20, 20, 88, 88)); + canvas.Fill(Brushes.Solid(Color.Red), new RectanglePolygon(20, 20, 88, 88)); canvas.SaveLayer(new GraphicsOptions { @@ -2422,7 +2422,7 @@ static void DrawAction(DrawingCanvas canvas) BlendPercentage = 1f }); - canvas.Fill(Brushes.Solid(Color.Blue), new RectangularPolygon(40, 40, 88, 88)); + canvas.Fill(Brushes.Solid(Color.Blue), new RectanglePolygon(40, 40, 88, 88)); canvas.Restore(); } @@ -2457,7 +2457,7 @@ static void DrawAction(DrawingCanvas canvas) // Layer bounds restrict compositing without shifting canvas coordinates. canvas.SaveLayer(new GraphicsOptions(), new Rectangle(16, 16, 96, 96)); - canvas.Fill(Brushes.Solid(Color.Green), new RectangularPolygon(0, 0, 96, 96)); + canvas.Fill(Brushes.Solid(Color.Green), new RectanglePolygon(0, 0, 96, 96)); canvas.Restore(); } @@ -2495,7 +2495,7 @@ static void DrawAction(DrawingCanvas canvas) canvas.SaveLayer(); // layer canvas.Save(); // plain save - canvas.Fill(Brushes.Solid(Color.Green), new RectangularPolygon(0, 0, 128, 128)); + canvas.Fill(Brushes.Solid(Color.Green), new RectanglePolygon(0, 0, 128, 128)); canvas.RestoreTo(before); } @@ -2548,7 +2548,7 @@ static void DrawAction(DrawingCanvas canvas) Transform = new Matrix4x4(Matrix3x2.CreateRotation(0.18F, new Vector2(120, 78))) }; - _ = outerRegion.Save(outerOptions, new RectangularPolygon(18, 14, 204, 128)); + _ = outerRegion.Save(outerOptions, new RectanglePolygon(18, 14, 204, 128)); outerRegion.Fill(Brushes.Solid(Color.MediumPurple.WithAlpha(0.35F)), new Rectangle(16, 16, 208, 124)); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasBatcherTests.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasBatcherTests.cs index 553694f5..260fd0a9 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasBatcherTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasBatcherTests.cs @@ -20,7 +20,7 @@ public void Flush_SamePathDifferentBrushes_UsesSingleCoverageDefinition() configuration.SetDrawingBackend(backend); using Image image = new(configuration, 40, 40); - IPath path = new RectangularPolygon(4, 6, 18, 12); + IPath path = new RectanglePolygon(4, 6, 18, 12); DrawingOptions options = new(); Brush brushA = Brushes.Solid(Color.Red); Brush brushB = Brushes.Solid(Color.Blue); @@ -47,7 +47,7 @@ public void Flush_SamePathDifferentBrushes_ReusesSourcePath() configuration.SetDrawingBackend(backend); using Image image = new(configuration, 40, 40); - IPath path = new RectangularPolygon(4, 6, 18, 12); + IPath path = new RectanglePolygon(4, 6, 18, 12); DrawingOptions options = new(); using (DrawingCanvas canvas = image.Frames.RootFrame.CreateCanvas(configuration, options)) @@ -73,7 +73,7 @@ public void Flush_SamePathReusedMultipleTimes_GroupsCommandsByCoverageDefinition configuration.SetDrawingBackend(backend); using Image image = new(configuration, 100, 100); - IPath path = new RectangularPolygon(10, 10, 40, 40); + IPath path = new RectanglePolygon(10, 10, 40, 40); DrawingOptions options = new(); using (DrawingCanvas canvas = image.Frames.RootFrame.CreateCanvas(configuration, options)) diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.RegionAndState.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.RegionAndState.cs index 96cc8899..a7c3b78d 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.RegionAndState.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.RegionAndState.cs @@ -84,7 +84,7 @@ public void RestoreTo_MultipleStates_MatchesReference(TestImageProvider< { canvas.Clear(Brushes.Solid(Color.White)); - int firstSaveCount = canvas.Save(firstOptions, new RectangularPolygon(20, 20, 144, 104)); + int firstSaveCount = canvas.Save(firstOptions, new RectanglePolygon(20, 20, 144, 104)); canvas.Fill(Brushes.Solid(Color.SkyBlue.WithAlpha(0.8F)), new Rectangle(0, 0, 120, 84)); _ = canvas.Save(secondOptions, new EllipsePolygon(new PointF(112, 80), new SizeF(130, 90))); @@ -136,7 +136,7 @@ public void CreateRegion_NestedRegionsAndStateIsolation_MatchesReference Transform = new Matrix4x4(Matrix3x2.CreateRotation(0.18F, new Vector2(120, 78))) }; - _ = outerRegion.Save(outerOptions, new RectangularPolygon(18, 14, 204, 128)); + _ = outerRegion.Save(outerOptions, new RectanglePolygon(18, 14, 204, 128)); outerRegion.Fill(Brushes.Solid(Color.MediumPurple.WithAlpha(0.35F)), new Rectangle(16, 16, 208, 124)); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveCount.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveCount.cs index 5ddbfc48..ecb8e20b 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveCount.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveCount.cs @@ -43,7 +43,7 @@ public void SaveWithOptions_IncrementsSaveCount() using Image target = new(64, 64); using DrawingCanvas canvas = CreateCanvas(provider, target, new DrawingOptions()); - int count = canvas.Save(new DrawingOptions(), new RectangularPolygon(0, 0, 32, 32)); + int count = canvas.Save(new DrawingOptions(), new RectanglePolygon(0, 0, 32, 32)); Assert.Equal(2, count); Assert.Equal(2, canvas.SaveCount); } diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveLayer.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveLayer.cs index f9a601bc..66c7f4f0 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveLayer.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.SaveLayer.cs @@ -58,7 +58,7 @@ public void SaveLayer_WithBounds_DoesNotShiftCanvasCoordinates() canvas.Fill(new SolidBrush(Color.White)); canvas.SaveLayer(new GraphicsOptions(), new Rectangle(10, 10, 32, 32)); - canvas.Fill(new SolidBrush(Color.Red), new RectangularPolygon(10, 10, 10, 10)); + canvas.Fill(new SolidBrush(Color.Red), new RectanglePolygon(10, 10, 10, 10)); canvas.Restore(); } @@ -82,7 +82,7 @@ public void SaveLayer_WithBounds_UsesCurrentTransformForLayerBounds() canvas.Save(translatedOptions); canvas.SaveLayer(new GraphicsOptions(), new Rectangle(10, 10, 10, 10)); - canvas.Fill(new SolidBrush(Color.Red), new RectangularPolygon(10, 10, 10, 10)); + canvas.Fill(new SolidBrush(Color.Red), new RectanglePolygon(10, 10, 10, 10)); canvas.Restore(); canvas.Restore(); } @@ -133,7 +133,7 @@ public void SaveLayer_DrawAndRestore_CompositesLayerOntoTarget() // SaveLayer with full opacity, draw red rectangle, then restore. canvas.SaveLayer(); - canvas.Fill(new SolidBrush(Color.Red), new RectangularPolygon(10, 10, 20, 20)); + canvas.Fill(new SolidBrush(Color.Red), new RectanglePolygon(10, 10, 20, 20)); canvas.Restore(); } @@ -158,7 +158,7 @@ public void SaveLayer_WithHalfOpacity_CompositesWithBlend() // SaveLayer with 50% opacity, draw red rectangle, then restore. canvas.SaveLayer(new GraphicsOptions { BlendPercentage = 0.5f }); - canvas.Fill(new SolidBrush(Color.Red), new RectangularPolygon(10, 10, 20, 20)); + canvas.Fill(new SolidBrush(Color.Red), new RectanglePolygon(10, 10, 20, 20)); canvas.Restore(); } @@ -180,7 +180,7 @@ public void SaveLayer_Dispose_CompositesActiveLayer() { canvas.Fill(new SolidBrush(Color.White)); canvas.SaveLayer(); - canvas.Fill(new SolidBrush(Color.Blue), new RectangularPolygon(0, 0, 32, 32)); + canvas.Fill(new SolidBrush(Color.Blue), new RectanglePolygon(0, 0, 32, 32)); // Dispose should composite the layer. } @@ -201,7 +201,7 @@ public void SaveLayer_Dispose_UsesStoredLayerOptions() { canvas.Fill(new SolidBrush(Color.White)); canvas.SaveLayer(new GraphicsOptions { BlendPercentage = 0.5f }); - canvas.Fill(new SolidBrush(Color.Blue), new RectangularPolygon(0, 0, 32, 32)); + canvas.Fill(new SolidBrush(Color.Blue), new RectanglePolygon(0, 0, 32, 32)); canvas.Restore(); } @@ -209,7 +209,7 @@ public void SaveLayer_Dispose_UsesStoredLayerOptions() { canvas.Fill(new SolidBrush(Color.White)); canvas.SaveLayer(new GraphicsOptions { BlendPercentage = 0.5f }); - canvas.Fill(new SolidBrush(Color.Blue), new RectangularPolygon(0, 0, 32, 32)); + canvas.Fill(new SolidBrush(Color.Blue), new RectanglePolygon(0, 0, 32, 32)); } ImageComparer.Exact.VerifySimilarity(restoredTarget, disposedTarget); @@ -226,11 +226,11 @@ public void SaveLayer_NestedLayers_CompositeCorrectly() // Outer layer. canvas.SaveLayer(); - canvas.Fill(new SolidBrush(Color.Red), new RectangularPolygon(0, 0, 64, 64)); + canvas.Fill(new SolidBrush(Color.Red), new RectanglePolygon(0, 0, 64, 64)); // Inner layer. canvas.SaveLayer(); - canvas.Fill(new SolidBrush(Color.Blue), new RectangularPolygon(16, 16, 32, 32)); + canvas.Fill(new SolidBrush(Color.Blue), new RectanglePolygon(16, 16, 32, 32)); canvas.Restore(); // Closes blue onto red. canvas.Restore(); // Closes red+blue onto white. @@ -259,7 +259,7 @@ public void SaveLayer_MixedSaveAndSaveLayer_WorksCorrectly() canvas.Save(); // SaveCount = 4 (plain save) Assert.Equal(4, canvas.SaveCount); - canvas.Fill(new SolidBrush(Color.Green), new RectangularPolygon(0, 0, 64, 64)); + canvas.Fill(new SolidBrush(Color.Green), new RectanglePolygon(0, 0, 64, 64)); // RestoreTo(1) should pop all states including the layer. canvas.RestoreTo(1); diff --git a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.TextMeasuring.cs b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.TextMeasuring.cs index 36fc2ab9..976f0dd3 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.TextMeasuring.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/DrawingCanvasTests.TextMeasuring.cs @@ -51,7 +51,7 @@ public void TextMeasuring_RenderedMetrics_MatchesReference(TestImageProv canvas.Fill( Brushes.Solid(bandColors[i % bandColors.Length]), - new RectangularPolygon(startX, lineOriginY, endX - startX, line.LineHeight)); + new RectanglePolygon(startX, lineOriginY, endX - startX, line.LineHeight)); canvas.DrawLine( Pens.Solid(Color.Teal.WithAlpha(0.9F), 1.5F), @@ -77,7 +77,7 @@ public void TextMeasuring_RenderedMetrics_MatchesReference(TestImageProv FontRectangle rb = metrics.GraphemeMetrics[i].RenderableBounds; canvas.Draw( Pens.Solid(Color.Black, 1), - new RectangularPolygon(rb.X, rb.Y, rb.Width, rb.Height)); + new RectanglePolygon(rb.X, rb.Y, rb.Width, rb.Height)); } // Character bounds: alternating filled rectangles behind the glyphs. @@ -92,7 +92,7 @@ public void TextMeasuring_RenderedMetrics_MatchesReference(TestImageProv FontRectangle b = metrics.GraphemeMetrics[i].Bounds; canvas.Fill( Brushes.Solid(charColors[i % charColors.Length]), - new RectangularPolygon(b.X, b.Y, b.Width, b.Height)); + new RectanglePolygon(b.X, b.Y, b.Width, b.Height)); } // Render the text. @@ -102,19 +102,19 @@ public void TextMeasuring_RenderedMetrics_MatchesReference(TestImageProv FontRectangle advance = metrics.Advance; canvas.Draw( Pens.Solid(Color.SeaGreen, 2), - new RectangularPolygon(origin.X + advance.X, origin.Y + advance.Y, advance.Width, advance.Height)); + new RectanglePolygon(origin.X + advance.X, origin.Y + advance.Y, advance.Width, advance.Height)); // Bounds rectangle (dodger blue outline). FontRectangle bounds = metrics.Bounds; canvas.Draw( Pens.Solid(Color.DodgerBlue, 2), - new RectangularPolygon(bounds.X, bounds.Y, bounds.Width, bounds.Height)); + new RectanglePolygon(bounds.X, bounds.Y, bounds.Width, bounds.Height)); // Renderable bounds rectangle (black outline). FontRectangle renderableBounds = metrics.RenderableBounds; canvas.Draw( Pens.Solid(Color.Black, 2), - new RectangularPolygon(renderableBounds.X, renderableBounds.Y, renderableBounds.Width, renderableBounds.Height)); + new RectanglePolygon(renderableBounds.X, renderableBounds.Y, renderableBounds.Width, renderableBounds.Height)); // Origin crosshair. canvas.DrawLine(Pens.Solid(Color.Gray, 1), new PointF(origin.X - 12, origin.Y), new PointF(origin.X + 12, origin.Y)); @@ -157,23 +157,23 @@ public void TextMeasuring_RenderedMetrics_MatchesReference(TestImageProv { canvas.Fill( Brushes.Solid(keyEntries[i].Color1), - new RectangularPolygon(x, y, halfW, swatchH)); + new RectanglePolygon(x, y, halfW, swatchH)); canvas.Fill( Brushes.Solid(c2), - new RectangularPolygon(x + halfW, y, halfW, swatchH)); + new RectanglePolygon(x + halfW, y, halfW, swatchH)); } else { canvas.Fill( Brushes.Solid(keyEntries[i].Color1), - new RectangularPolygon(x, y, swatchW, swatchH)); + new RectanglePolygon(x, y, swatchW, swatchH)); } } else { canvas.Draw( Pens.Solid(keyEntries[i].Color1, 2), - new RectangularPolygon(x, y, swatchW, swatchH)); + new RectanglePolygon(x, y, swatchW, swatchH)); } RichTextOptions keyTextOptions = new(keyFont) { Origin = new PointF(x + labelOffset, y - 1) }; diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Clip.cs b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Clip.cs index 4addb6a8..61795408 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Clip.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Clip.cs @@ -25,7 +25,7 @@ public void ClipOffset(TestImageProvider provider, float dx, flo { Rectangle bounds = canvas.Bounds; int outerRadii = (int)(Math.Min(bounds.Width, bounds.Height) * sizeMult); - Star star = new(new PointF(bounds.Width / 2F, bounds.Height / 2F), 5, outerRadii / 2F, outerRadii); + StarPolygon star = new(new PointF(bounds.Width / 2F, bounds.Height / 2F), 5, outerRadii / 2F, outerRadii); Matrix4x4 builder = Matrix4x4.CreateTranslation(dx, dy, 0); canvas.Apply(star.Transform(builder), ctx => ctx.DetectEdges()); }), @@ -43,7 +43,7 @@ public void ClipConstrainsOperationToClipBounds(TestImageProvider ctx.Flip(FlipMode.Vertical)); }), appendPixelTypeToFileName: false, @@ -52,7 +52,7 @@ public void ClipConstrainsOperationToClipBounds(TestImageProvider( if (triggerFillRegion) { - RectangularPolygon path = new(0, 0, 16, 16); + RectanglePolygon path = new(0, 0, 16, 16); image.Mutate(c => c.Paint(options, canvas => canvas.Fill(Brushes.Solid(fillColor), path))); } else diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.PathGradientBrushes.cs b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.PathGradientBrushes.cs index 899aa181..d2eb7448 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.PathGradientBrushes.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.PathGradientBrushes.cs @@ -185,7 +185,7 @@ public void FillPathGradientBrushFillComplex(TestImageProvider p new TolerantImageComparer(0.2f), image => { - Star star = new(50, 50, 5, 20, 45); + StarPolygon star = new(50, 50, 5, 20, 45); PointF[] points = star.Points.ToArray(); Color[] colors = [ diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Polygons.cs b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Polygons.cs index db07d7a9..4894c3ed 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Polygons.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Polygons.cs @@ -104,10 +104,10 @@ public void FillPolygon_Solid_Transformed(TestImageProvider prov [Theory] [WithBasicTestPatternImages(100, 100, PixelTypes.Rgba32)] - public void FillPolygon_RectangularPolygon_Solid_Transformed(TestImageProvider provider) + public void FillPolygon_RectanglePolygon_Solid_Transformed(TestImageProvider provider) where TPixel : unmanaged, IPixel { - RectangularPolygon polygon = new(25, 25, 50, 50); + RectanglePolygon polygon = new(25, 25, 50, 50); DrawingOptions options = new() { Transform = new Matrix4x4(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) @@ -119,10 +119,10 @@ public void FillPolygon_RectangularPolygon_Solid_Transformed(TestImagePr [Theory] [WithBasicTestPatternImages(100, 100, PixelTypes.Rgba32)] - public void FillPolygon_RectangularPolygon_Solid_TransformedUsingConfiguration(TestImageProvider provider) + public void FillPolygon_RectanglePolygon_Solid_TransformedUsingConfiguration(TestImageProvider provider) where TPixel : unmanaged, IPixel { - RectangularPolygon polygon = new(25, 25, 50, 50); + RectanglePolygon polygon = new(25, 25, 50, 50); DrawingOptions options = new() { Transform = new Matrix4x4(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) @@ -199,7 +199,7 @@ public void FillPolygon_Concave(TestImageProvider provider, bool public void FillPolygon_StarCircle(TestImageProvider provider) { EllipsePolygon circle = new(32, 32, 30); - Star star = new(32, 32, 7, 10, 27); + StarPolygon star = new(32, 32, 7, 10, 27); IPath shape = circle.Clip(star); provider.RunValidatingProcessorTest( @@ -217,7 +217,7 @@ public void FillPolygon_StarCircle(TestImageProvider provider) public void FillPolygon_StarCircle_AllOperations(TestImageProvider provider, BooleanOperation operation) { IPath circle = new EllipsePolygon(36, 36, 36).Translate(28, 28); - Star star = new(64, 64, 5, 24, 64); + StarPolygon star = new(64, 64, 5, 24, 64); // See http://www.angusj.com/clipper2/Docs/Units/Clipper/Types/ClipType.htm for reference. ShapeOptions shapeOptions = new() { BooleanOperation = operation }; @@ -304,10 +304,10 @@ public void FillPolygon_ImageBrush_Rect(TestImageProvider provid [Theory] [WithBasicTestPatternImages(250, 250, PixelTypes.Rgba32)] - public void FillPolygon_RectangularPolygon(TestImageProvider provider) + public void FillPolygon_RectanglePolygon(TestImageProvider provider) where TPixel : unmanaged, IPixel { - RectangularPolygon polygon = new(10, 10, 190, 140); + RectanglePolygon polygon = new(10, 10, 190, 140); Color color = Color.White; provider.RunValidatingProcessorTest( diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Primitives.cs b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Primitives.cs index ecf54b24..b5b00025 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Primitives.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Primitives.cs @@ -455,7 +455,7 @@ public void DrawPolygon_Transformed(TestImageProvider provider) public void DrawPolygonRectangular_Transformed(TestImageProvider provider) where TPixel : unmanaged, IPixel { - RectangularPolygon polygon = new(25, 25, 50, 50); + RectanglePolygon polygon = new(25, 25, 50, 50); DrawingOptions options = new() { Transform = new Matrix4x4(Matrix3x2.CreateRotation((float)Math.PI / 4, new PointF(50, 50))) diff --git a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Robustness.cs b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Robustness.cs index 07e95d71..e1dc1325 100644 --- a/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Robustness.cs +++ b/tests/ImageSharp.Drawing.Tests/Processing/ProcessWithDrawingCanvasTests.Robustness.cs @@ -30,7 +30,7 @@ public void CompareToSkiaResults_SmallCircle(TestImageProvider provider) public void CompareToSkiaResults_StarCircle(TestImageProvider provider) { EllipsePolygon circle = new(32, 32, 30); - Star star = new(32, 32, 7, 10, 27); + StarPolygon star = new(32, 32, 7, 10, 27); IPath shape = circle.Clip(star); CompareToSkiaResultsImpl(provider, shape); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs index 7bc1621d..2355b816 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathBuilderTests.cs @@ -56,7 +56,7 @@ public void AddPieRotationOverloadMatchesPieShape() builder.AddPie(10, 20, 30, 40, 15, 120, 210); Polygon actual = Assert.IsType(builder.Build()); - Pie expected = new(10, 20, 30, 40, 15, 120, 210); + PiePolygon expected = new(10, 20, 30, 40, 15, 120, 210); AssertEquivalentPaths(actual, expected); } @@ -68,25 +68,25 @@ public void AddPieNoRotationOverloadMatchesPieShape() builder.AddPie(new PointF(10, 20), new SizeF(30, 40), 15, 120); Polygon actual = Assert.IsType(builder.Build()); - Pie expected = new(new PointF(10, 20), new SizeF(30, 40), 15, 120); + PiePolygon expected = new(new PointF(10, 20), new SizeF(30, 40), 15, 120); AssertEquivalentPaths(actual, expected); } [Fact] - public void AddRectangleMatchesRectangularPolygon() + public void AddRectangleMatchesRectanglePolygon() { PathBuilder builder = new(); builder.AddRectangle(new RectangleF(10, 20, 30, 40)); Polygon actual = Assert.IsType(builder.Build()); - RectangularPolygon expected = new(10, 20, 30, 40); + RectanglePolygon expected = new(10, 20, 30, 40); AssertEquivalentPaths(actual, expected); } [Fact] - public void AddRoundedRectangleMatchesRoundedRectangleShape() + public void AddRoundedRectangleMatchesRoundedRectanglePolygon() { PathBuilder builder = new(); builder.AddRoundedRectangle(new RectangleF(10, 20, 30, 40), new SizeF(5, 8)); @@ -98,7 +98,7 @@ public void AddRoundedRectangleMatchesRoundedRectangleShape() } [Fact] - public void AddRoundedRectangleRadiusOverloadMatchesRoundedRectangleShape() + public void AddRoundedRectangleRadiusOverloadMatchesRoundedRectanglePolygon() { PathBuilder builder = new(); builder.AddRoundedRectangle(10, 20, 30, 40, 6); @@ -147,7 +147,7 @@ public void AddStarMatchesStarShape() builder.AddStar(new PointF(10, 20), 5, 15, 30, 45); Polygon actual = Assert.IsType(builder.Build()); - Star expected = new(new PointF(10, 20), 5, 15, 30, 45); + StarPolygon expected = new(new PointF(10, 20), 5, 15, 30, 45); AssertEquivalentPaths(actual, expected); } diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs index 2df21b4c..32eec9a9 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs @@ -117,8 +117,8 @@ public void TryParseSvgPath_ReturnsFalseForInvalidPathDataBoundaries(string svgP [Fact] public void PathCollection_EnumerableConstructor_PreservesPaths() { - IPath first = new RectangularPolygon(1, 2, 3, 4); - IPath second = new RectangularPolygon(10, 20, 5, 6); + IPath first = new RectanglePolygon(1, 2, 3, 4); + IPath second = new RectanglePolygon(10, 20, 5, 6); PathCollection collection = new(new[] { first, second }.AsEnumerable()); @@ -132,8 +132,8 @@ public void PathCollection_EnumerableConstructor_PreservesPaths() public void PathCollection_Bounds_AggregatesPathBounds() { PathCollection collection = new( - new RectangularPolygon(1, 2, 3, 4), - new RectangularPolygon(10, 20, 5, 6)); + new RectanglePolygon(1, 2, 3, 4), + new RectanglePolygon(10, 20, 5, 6)); Assert.Equal(new RectangleF(1, 2, 14, 24), collection.Bounds); } @@ -150,8 +150,8 @@ public void PathCollection_Bounds_ReturnsEmptyForEmptyCollection() public void PathCollection_Transform_TransformsEachPath() { PathCollection collection = new( - new RectangularPolygon(1, 2, 3, 4), - new RectangularPolygon(10, 20, 5, 6)); + new RectanglePolygon(1, 2, 3, 4), + new RectanglePolygon(10, 20, 5, 6)); Matrix4x4 matrix = Matrix4x4.CreateTranslation(7, 11, 0); IPathCollection transformed = collection.Transform(matrix); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/PieTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/PiePolygonTests.cs similarity index 76% rename from tests/ImageSharp.Drawing.Tests/Shapes/PieTests.cs rename to tests/ImageSharp.Drawing.Tests/Shapes/PiePolygonTests.cs index 63609a4d..fd989b7d 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/PieTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/PiePolygonTests.cs @@ -6,7 +6,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Shapes; -public class PieTests +public class PiePolygonTests { [Theory] [InlineData(-1, true)] @@ -17,12 +17,12 @@ public void RadiusXMustBeGreaterThan0(float radiusX, bool throws) { if (throws) { - ArgumentOutOfRangeException ex = Assert.Throws(() => new Pie(0, 0, radiusX, 99, 0, 90)); + ArgumentOutOfRangeException ex = Assert.Throws(() => new PiePolygon(0, 0, radiusX, 99, 0, 90)); Assert.Equal("radiusX", ex.ParamName); } else { - Pie p = new(0, 0, radiusX, 99, 0, 90); + PiePolygon p = new(0, 0, radiusX, 99, 0, 90); Assert.NotNull(p); } } @@ -36,12 +36,12 @@ public void RadiusYMustBeGreaterThan0(float radiusY, bool throws) { if (throws) { - ArgumentOutOfRangeException ex = Assert.Throws(() => new Pie(0, 0, 99, radiusY, 0, 90)); + ArgumentOutOfRangeException ex = Assert.Throws(() => new PiePolygon(0, 0, 99, radiusY, 0, 90)); Assert.Equal("radiusY", ex.ParamName); } else { - Pie p = new(0, 0, 99, radiusY, 0, 90); + PiePolygon p = new(0, 0, 99, radiusY, 0, 90); Assert.NotNull(p); } } @@ -49,8 +49,8 @@ public void RadiusYMustBeGreaterThan0(float radiusY, bool throws) [Fact] public void NoRotationOverloadMatchesZeroRotation() { - Pie withRotation = new(new PointF(10, 20), new SizeF(30, 40), 0, 15, 120); - Pie withoutRotation = new(new PointF(10, 20), new SizeF(30, 40), 15, 120); + PiePolygon withRotation = new(new PointF(10, 20), new SizeF(30, 40), 0, 15, 120); + PiePolygon withoutRotation = new(new PointF(10, 20), new SizeF(30, 40), 15, 120); PointF[] withRotationPoints = withRotation.Flatten().Single().Points.ToArray(); PointF[] withoutRotationPoints = withoutRotation.Flatten().Single().Points.ToArray(); @@ -67,7 +67,7 @@ public void NoRotationOverloadMatchesZeroRotation() [Fact] public void BoundsIncludeCenterAndArcExtents() { - Pie pie = new(new PointF(10, 20), new SizeF(30, 40), 0, 0, 90); + PiePolygon pie = new(new PointF(10, 20), new SizeF(30, 40), 0, 0, 90); Assert.Equal(10, pie.Bounds.Left, 4F); Assert.Equal(40, pie.Bounds.Right, 4F); @@ -78,7 +78,7 @@ public void BoundsIncludeCenterAndArcExtents() [Fact] public void ShapePaths() { - Pie shape = new(new PointF(10, 20), new SizeF(30, 40), 0, 90); + PiePolygon shape = new(new PointF(10, 20), new SizeF(30, 40), 0, 90); Assert.Equal(shape, shape.AsClosedPath()); } @@ -86,7 +86,7 @@ public void ShapePaths() [Fact] public void TransformIdentityReturnsShapeObject() { - Pie shape = new(new PointF(10, 20), new SizeF(30, 40), 20, 140); + PiePolygon shape = new(new PointF(10, 20), new SizeF(30, 40), 20, 140); IPath transformedShape = shape.Transform(Matrix4x4.Identity); Assert.Same(shape, transformedShape); @@ -95,7 +95,7 @@ public void TransformIdentityReturnsShapeObject() [Fact] public void Transform() { - Pie shape = new(new PointF(10, 20), new SizeF(30, 40), 0, 0, 90); + PiePolygon shape = new(new PointF(10, 20), new SizeF(30, 40), 0, 0, 90); IPath newShape = shape.Transform(new Matrix4x4(new Matrix3x2(0, 1, 1, 0, 20, 2))); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs index f2905b7f..83684b45 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs @@ -69,35 +69,35 @@ public class RectangleTests [Fact] public void Left() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(10, shape.Left); } [Fact] public void Right() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(22, shape.Right); } [Fact] public void Top() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(11, shape.Top); } [Fact] public void Bottom() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(24, shape.Bottom); } [Fact] public void SizeF() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(12, shape.Size.Width); Assert.Equal(13, shape.Size.Height); } @@ -105,7 +105,7 @@ public void SizeF() [Fact] public void Bounds_Shape() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(10, shape.Bounds.Left); Assert.Equal(22, shape.Bounds.Right); Assert.Equal(11, shape.Bounds.Top); @@ -115,7 +115,7 @@ public void Bounds_Shape() [Fact] public void LinearSegments() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); PointF[] segments = shape.Flatten().ToArray()[0].Points.ToArray(); Assert.Equal(new PointF(10, 11), segments[0]); Assert.Equal(new PointF(22, 11), segments[1]); @@ -126,7 +126,7 @@ public void LinearSegments() [Fact] public void Bounds_Path() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(10, shape.Bounds.Left); Assert.Equal(22, shape.Bounds.Right); Assert.Equal(11, shape.Bounds.Top); @@ -136,7 +136,7 @@ public void Bounds_Path() [Fact] public void ShapePaths() { - RectangularPolygon shape = new(10, 11, 12, 13); + RectanglePolygon shape = new(10, 11, 12, 13); Assert.Equal(shape, shape.AsClosedPath()); } @@ -144,7 +144,7 @@ public void ShapePaths() [Fact] public void TransformIdentityReturnsShapeObject() { - RectangularPolygon shape = new(0, 0, 200, 60); + RectanglePolygon shape = new(0, 0, 200, 60); IPath transformedShape = shape.Transform(Matrix4x4.Identity); Assert.Same(shape, transformedShape); @@ -153,7 +153,7 @@ public void TransformIdentityReturnsShapeObject() [Fact] public void Transform() { - RectangularPolygon shape = new(0, 0, 200, 60); + RectanglePolygon shape = new(0, 0, 200, 60); IPath newShape = shape.Transform(new Matrix4x4(new Matrix3x2(0, 1, 1, 0, 20, 2))); @@ -164,7 +164,7 @@ public void Transform() [Fact] public void Center() { - RectangularPolygon shape = new(50, 50, 200, 60); + RectanglePolygon shape = new(50, 50, 200, 60); Assert.Equal(new PointF(150, 80), shape.Center); } @@ -181,7 +181,7 @@ public void Center() [InlineData(620, 150, 50, Pi)] // wrap about end of path public void PointOnPath(float distance, float expectedX, float expectedY, float expectedAngle) { - RectangularPolygon shape = new(50, 50, 200, 60); + RectanglePolygon shape = new(50, 50, 200, 60); SegmentInfo point = ((IPathInternals)shape).PointAlongPath(distance); Assert.Equal(expectedX, point.Point.X); Assert.Equal(expectedY, point.Point.Y); diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs deleted file mode 100644 index 5b0dc9a5..00000000 --- a/tests/ImageSharp.Drawing.Tests/Shapes/RoundedRectangleTests.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Six Labors Split License. - -using System.Numerics; -using SixLabors.ImageSharp.Drawing.Tests; - -namespace SixLabors.ImageSharp.Drawing.Tests.Shapes; - -public class RoundedRectangleTests -{ - [Fact] - public void BoundsMatchRectangle() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); - - Assert.Equal(new RectangleF(10, 20, 100, 40), shape.Bounds); - } - - [Fact] - public void ZeroRadiusMatchesRectangularPolygon() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 0); - RectangularPolygon rectangle = new(10, 20, 100, 40); - PointF[] actualPoints = shape.Flatten().Single().Points.ToArray(); - PointF[] expectedPoints = rectangle.Flatten().Single().Points.ToArray(); - - Assert.Equal(expectedPoints, actualPoints); - } - - [Fact] - public void RoundedRectangleUsesCurvedCorners() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); - PointF[] points = shape.Flatten().Single().Points.ToArray(); - - Assert.True(points.Length > 4); - } - - [Fact] - public void OversizedRadiusScalesToFitBounds() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 100); - PointF[] points = shape.Flatten().Single().Points.ToArray(); - - Assert.Equal(new RectangleF(10, 20, 100, 40), shape.Bounds); - Assert.True(points.Length > 4); - } - - [Fact] - public void ShapePaths() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); - - Assert.Equal(shape, shape.AsClosedPath()); - } - - [Fact] - public void TransformIdentityReturnsShapeObject() - { - RoundedRectanglePolygon shape = new(10, 20, 100, 40, 12); - IPath transformedShape = shape.Transform(Matrix4x4.Identity); - - Assert.Same(shape, transformedShape); - } - - [Fact] - public void Transform() - { - RoundedRectanglePolygon shape = new(0, 0, 100, 40, 12); - - IPath newShape = shape.Transform(new Matrix4x4(new Matrix3x2(0, 1, 1, 0, 20, 2))); - - ApproximateFloatComparer comparer = new(1e-4F); - Assert.Equal(new PointF(20, 2), newShape.Bounds.Location, comparer); - Assert.Equal(new SizeF(40, 100), newShape.Bounds.Size, comparer); - } -} diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/StarPolygonTests.cs similarity index 83% rename from tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs rename to tests/ImageSharp.Drawing.Tests/Shapes/StarPolygonTests.cs index ce5cf926..07e43e2f 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/StarTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/StarPolygonTests.cs @@ -5,7 +5,7 @@ namespace SixLabors.ImageSharp.Drawing.Tests.Shapes; -public class StarTests +public class StarPolygonTests { [Theory] [InlineData(0, true)] @@ -17,13 +17,13 @@ public void RequiresAtLeast3Verticies(int points, bool throws) { if (throws) { - ArgumentOutOfRangeException ex = Assert.Throws(() => new Star(Vector2.Zero, points, 10f, 20f, 0)); + ArgumentOutOfRangeException ex = Assert.Throws(() => new StarPolygon(Vector2.Zero, points, 10f, 20f, 0)); Assert.Equal("prongs", ex.ParamName); } else { - Star p = new(Vector2.Zero, points, 10f, 20f, 0); + StarPolygon p = new(Vector2.Zero, points, 10f, 20f, 0); Assert.NotNull(p); } } @@ -37,15 +37,15 @@ public void RadiusMustBeGreaterThan0(float radius, bool throws) { if (throws) { - ArgumentOutOfRangeException ex = Assert.Throws(() => new Star(Vector2.Zero, 3, radius, 20f, 0)); - ArgumentOutOfRangeException ex2 = Assert.Throws(() => new Star(Vector2.Zero, 3, 20f, radius, 0)); + ArgumentOutOfRangeException ex = Assert.Throws(() => new StarPolygon(Vector2.Zero, 3, radius, 20f, 0)); + ArgumentOutOfRangeException ex2 = Assert.Throws(() => new StarPolygon(Vector2.Zero, 3, 20f, radius, 0)); Assert.Equal("innerRadii", ex.ParamName); Assert.Equal("outerRadii", ex2.ParamName); } else { - Star p = new(Vector2.Zero, 3, radius, radius, 0); + StarPolygon p = new(Vector2.Zero, 3, radius, radius, 0); Assert.NotNull(p); } } @@ -57,7 +57,7 @@ public void GeneratesCorrectPath() const float radius2 = 30; int pointsCount = new Random().Next(3, 20); - Star poly = new(Vector2.Zero, pointsCount, radius, radius2, 0); + StarPolygon poly = new(Vector2.Zero, pointsCount, radius, radius2, 0); PointF[] points = poly.Flatten().ToArray()[0].Points.ToArray(); @@ -100,7 +100,7 @@ public void AngleChangesOnePointToStartAtThatPosition() expectedAngleDegrees -= 360D; } - Star poly = new(Vector2.Zero, 3, radius, radius2, (float)anAngleDegrees); + StarPolygon poly = new(Vector2.Zero, 3, radius, radius2, (float)anAngleDegrees); ISimplePath[] points = [.. poly.Flatten()]; IEnumerable allAngles = points[0].Points.ToArray() diff --git a/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs b/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs index 3906384a..6a8899cd 100644 --- a/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs +++ b/tests/ImageSharp.Drawing.Tests/Shapes/TextBuilderTests.cs @@ -73,8 +73,8 @@ public void TextBuilder_Bounds_AreCorrect_Glyphs() [Fact] public void GlyphPathCollection_PreservesLayerMetadataAndFiltersPaths() { - RectangularPolygon glyphPath = new(0, 0, 10, 12); - RectangularPolygon paintedPath = new(20, 4, 6, 8); + RectanglePolygon glyphPath = new(0, 0, 10, 12); + RectanglePolygon paintedPath = new(20, 4, 6, 8); SolidPaint paint = new() { CompositeMode = CompositeMode.Multiply }; GlyphPathCollection.Builder builder = new(); @@ -118,7 +118,7 @@ public void GlyphPathCollection_PreservesLayerMetadataAndFiltersPaths() [Fact] public void GlyphPathCollection_Transform_TransformsPathsAndLayerBounds() { - RectangularPolygon path = new(2, 3, 10, 5); + RectanglePolygon path = new(2, 3, 10, 5); GlyphPathCollection.Builder builder = new(); builder.AddPath(path); @@ -142,7 +142,7 @@ public void GlyphPathCollection_Transform_TransformsPathsAndLayerBounds() public void GlyphPathCollection_BuilderRejectsOutOfRangeLayerSpan() { GlyphPathCollection.Builder builder = new(); - builder.AddPath(new RectangularPolygon(0, 0, 10, 10)); + builder.AddPath(new RectanglePolygon(0, 0, 10, 10)); ArgumentOutOfRangeException ex = Assert.Throws( () => builder.AddLayer(1, 1, null, FillRule.NonZero, RectangleF.Empty)); diff --git a/tests/ImageSharp.Drawing.Tests/TestUtilities/RectangularPolygonValueComparer.cs b/tests/ImageSharp.Drawing.Tests/TestUtilities/RectanglePolygonValueComparer.cs similarity index 51% rename from tests/ImageSharp.Drawing.Tests/TestUtilities/RectangularPolygonValueComparer.cs rename to tests/ImageSharp.Drawing.Tests/TestUtilities/RectanglePolygonValueComparer.cs index 91f64607..8b2aef51 100644 --- a/tests/ImageSharp.Drawing.Tests/TestUtilities/RectangularPolygonValueComparer.cs +++ b/tests/ImageSharp.Drawing.Tests/TestUtilities/RectanglePolygonValueComparer.cs @@ -4,18 +4,18 @@ namespace SixLabors.ImageSharp.Drawing.Tests.TestUtilities; /// -/// Allows the comparison of rectangular polygons by value. +/// Allows the comparison of rectangle polygons by value. /// -internal static class RectangularPolygonValueComparer +internal static class RectanglePolygonValueComparer { public const float DefaultTolerance = 1e-05F; - public static bool Equals(RectangularPolygon x, RectangularPolygon y, float epsilon = DefaultTolerance) + public static bool Equals(RectanglePolygon x, RectanglePolygon y, float epsilon = DefaultTolerance) => Math.Abs(x.Left - y.Left) < epsilon && Math.Abs(x.Top - y.Top) < epsilon && Math.Abs(x.Right - y.Right) < epsilon && Math.Abs(x.Bottom - y.Bottom) < epsilon; - public static bool Equals(RectangularPolygon x, object y, float epsilon = DefaultTolerance) - => y is RectangularPolygon polygon && Equals(x, polygon, epsilon); + public static bool Equals(RectanglePolygon x, object y, float epsilon = DefaultTolerance) + => y is RectanglePolygon polygon && Equals(x, polygon, epsilon); } diff --git a/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Rgba32.png b/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Rgba32.png similarity index 100% rename from tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Rgba32.png rename to tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Rgba32.png diff --git a/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png b/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png similarity index 100% rename from tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png rename to tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Solid_TransformedUsingConfiguration_Rgba32_BasicTestPattern100x100.png diff --git a/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png b/tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png similarity index 100% rename from tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectangularPolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png rename to tests/Images/ReferenceOutput/Drawing/ProcessWithDrawingCanvasTests/FillPolygon_RectanglePolygon_Solid_Transformed_Rgba32_BasicTestPattern100x100.png