diff --git a/src/ImageSharp.Drawing.Paths/DrawShape.cs b/src/ImageSharp.Drawing.Paths/DrawShape.cs
deleted file mode 100644
index 748bb6a11..000000000
--- a/src/ImageSharp.Drawing.Paths/DrawShape.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using System;
-
- using Drawing;
- using Drawing.Brushes;
- using Drawing.Pens;
-
- using SixLabors.Shapes;
-
- ///
- /// Extension methods for the type.
- ///
- public static partial class ImageExtensions
- {
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The pen.
- /// The shape.
- /// The options.
- /// The .
- public static Image Draw(this Image source, IPen pen, IShape shape, GraphicsOptions options)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(pen, new ShapePath(shape), options);
- }
-
- ///
- /// Draws the outline of the polygon with the provided pen.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The pen.
- /// The shape.
- /// The .
- public static Image Draw(this Image source, IPen pen, IShape shape)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(pen, shape, GraphicsOptions.Default);
- }
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The shape.
- /// The options.
- /// The .
- public static Image Draw(this Image source, IBrush brush, float thickness, IShape shape, GraphicsOptions options)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(new Pen(brush, thickness), shape, options);
- }
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The brush.
- /// The thickness.
- /// The shape.
- /// The .
- public static Image Draw(this Image source, IBrush brush, float thickness, IShape shape)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(new Pen(brush, thickness), shape);
- }
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The shape.
- /// The options.
- /// The .
- public static Image Draw(this Image source, TColor color, float thickness, IShape shape, GraphicsOptions options)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(new SolidBrush(color), thickness, shape, options);
- }
-
- ///
- /// Draws the outline of the polygon with the provided brush at the provided thickness.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The color.
- /// The thickness.
- /// The shape.
- /// The .
- public static Image Draw(this Image source, TColor color, float thickness, IShape shape)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Draw(new SolidBrush(color), thickness, shape);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing.Paths/FillShape.cs b/src/ImageSharp.Drawing.Paths/FillShape.cs
deleted file mode 100644
index f143e75b7..000000000
--- a/src/ImageSharp.Drawing.Paths/FillShape.cs
+++ /dev/null
@@ -1,78 +0,0 @@
-//
-// Copyright (c) James Jackson-South and contributors.
-// Licensed under the Apache License, Version 2.0.
-//
-
-namespace ImageSharp
-{
- using System;
-
- using Drawing;
- using Drawing.Brushes;
-
- using SixLabors.Shapes;
-
- ///
- /// Extension methods for the type.
- ///
- public static partial class ImageExtensions
- {
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The brush.
- /// The shape.
- /// The graphics options.
- /// The .
- public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Fill(brush, new ShapeRegion(shape), options);
- }
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush.
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The brush.
- /// The shape.
- /// The .
- public static Image Fill(this Image source, IBrush brush, IShape shape)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default);
- }
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush..
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The color.
- /// The shape.
- /// The options.
- /// The .
- public static Image Fill(this Image source, TColor color, IShape shape, GraphicsOptions options)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Fill(new SolidBrush(color), shape, options);
- }
-
- ///
- /// Flood fills the image in the shape of the provided polygon with the specified brush..
- ///
- /// The type of the color.
- /// The image this method extends.
- /// The color.
- /// The shape.
- /// The .
- public static Image Fill(this Image source, TColor color, IShape shape)
- where TColor : struct, IPackedPixel, IEquatable
- {
- return source.Fill(new SolidBrush(color), shape);
- }
- }
-}
diff --git a/src/ImageSharp.Drawing.Paths/ShapePath.cs b/src/ImageSharp.Drawing.Paths/ShapePath.cs
index 5ea38a365..d0376ccc1 100644
--- a/src/ImageSharp.Drawing.Paths/ShapePath.cs
+++ b/src/ImageSharp.Drawing.Paths/ShapePath.cs
@@ -14,53 +14,27 @@ namespace ImageSharp.Drawing
using Rectangle = ImageSharp.Rectangle;
///
- /// A drawable mapping between a / and a drawable/fillable region.
+ /// A drawable mapping between a and a drawable region.
///
internal class ShapePath : Drawable
{
- ///
- /// The fillable shape
- ///
- private readonly IShape shape;
-
///
/// Initializes a new instance of the class.
///
/// The path.
public ShapePath(IPath path)
- : this(ImmutableArray.Create(path))
{
- this.shape = path.AsShape();
- this.Bounds = RectangleF.Ceiling(path.Bounds.Convert());
+ this.Path = path;
+ this.Bounds = path.Bounds.Convert();
}
///
- /// Initializes a new instance of the class.
+ /// Gets the fillable shape
///
- /// The shape.
- public ShapePath(IShape shape)
- : this(shape.Paths)
- {
- this.shape = shape;
- this.Bounds = RectangleF.Ceiling(shape.Bounds.Convert());
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The paths.
- private ShapePath(ImmutableArray paths)
- {
- this.Paths = paths;
- }
-
- ///
- /// Gets the drawable paths
- ///
- public ImmutableArray Paths { get; }
+ public IPath Path { get; }
///
- public override int MaxIntersections => this.shape.MaxIntersections;
+ public override int MaxIntersections => this.Path.MaxIntersections;
///
public override Rectangle Bounds { get; }
@@ -73,7 +47,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool.Shared.Rent(length);
try
{
- int count = this.shape.FindIntersections(start, end, innerbuffer, length, 0);
+ int count = this.Path.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{
@@ -96,7 +70,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool.Shared.Rent(length);
try
{
- int count = this.shape.FindIntersections(start, end, innerbuffer, length, 0);
+ int count = this.Path.FindIntersections(start, end, innerbuffer, length, 0);
for (int i = 0; i < count; i++)
{
@@ -115,24 +89,15 @@ namespace ImageSharp.Drawing
public override PointInfo GetPointInfo(int x, int y)
{
Vector2 point = new Vector2(x, y);
- float distanceFromPath = float.MaxValue;
- float distanceAlongPath = 0;
-
- // ReSharper disable once ForCanBeConvertedToForeach
- for (int i = 0; i < this.Paths.Length; i++)
- {
- SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point);
- if (p.DistanceFromPath < distanceFromPath)
- {
- distanceFromPath = p.DistanceFromPath;
- distanceAlongPath = p.DistanceAlongPath;
- }
- }
+ SixLabors.Shapes.PointInfo dist = this.Path.Distance(point);
return new PointInfo
{
- DistanceAlongPath = distanceAlongPath,
- DistanceFromPath = distanceFromPath
+ DistanceAlongPath = dist.DistanceAlongPath,
+ DistanceFromPath =
+ dist.DistanceFromPath < 0
+ ? -dist.DistanceFromPath
+ : dist.DistanceFromPath
};
}
}
diff --git a/src/ImageSharp.Drawing.Paths/ShapeRegion.cs b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs
index dc035e3b0..b02c5c2e5 100644
--- a/src/ImageSharp.Drawing.Paths/ShapeRegion.cs
+++ b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs
@@ -13,33 +13,24 @@ namespace ImageSharp.Drawing
using Rectangle = ImageSharp.Rectangle;
///
- /// A drawable mapping between a / and a drawable/fillable region.
+ /// A mapping between a and a region.
///
internal class ShapeRegion : Region
{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The path.
- public ShapeRegion(IPath path)
- : this(path.AsShape())
- {
- }
-
///
/// Initializes a new instance of the class.
///
/// The shape.
- public ShapeRegion(IShape shape)
+ public ShapeRegion(IPath shape)
{
- this.Shape = shape;
+ this.Shape = shape.AsClosedPath();
this.Bounds = shape.Bounds.Convert();
}
///
/// Gets the fillable shape
///
- public IShape Shape { get; }
+ public IPath Shape { get; }
///
public override int MaxIntersections => this.Shape.MaxIntersections;
diff --git a/src/ImageSharp.Drawing.Paths/project.json b/src/ImageSharp.Drawing.Paths/project.json
index c903f805a..1cc729380 100644
--- a/src/ImageSharp.Drawing.Paths/project.json
+++ b/src/ImageSharp.Drawing.Paths/project.json
@@ -44,7 +44,7 @@
"ImageSharp.Drawing": {
"target": "project"
},
- "SixLabors.Shapes": "0.1.0-alpha0004",
+ "SixLabors.Shapes": "0.1.0-alpha0005",
"StyleCop.Analyzers": {
"version": "1.0.0",
"type": "build"
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs
index 0d3b46981..82e2f72a2 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs
@@ -50,9 +50,10 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
+ Assert.NotNull(path.Path);
+
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -71,9 +72,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -92,9 +92,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -115,9 +114,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -138,9 +136,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
@@ -157,9 +154,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
BezierLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs
index bbed3cae6..cc126614f 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs
@@ -50,9 +50,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -71,9 +70,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -92,9 +90,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -115,9 +112,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -138,9 +134,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
@@ -157,9 +152,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- SixLabors.Shapes.Path vector = Assert.IsType(path.Paths[0]);
+ SixLabors.Shapes.Path vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs
index 531546370..6c1c06813 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs
@@ -50,8 +50,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Pen pen = Assert.IsType>(processor.Pen);
Assert.Equal(brush, pen.Brush);
@@ -69,8 +68,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Pen pen = Assert.IsType>(processor.Pen);
Assert.Equal(brush, pen.Brush);
@@ -88,8 +86,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Pen pen = Assert.IsType>(processor.Pen);
Assert.Equal(thickness, pen.Width);
@@ -109,8 +106,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Pen pen = Assert.IsType>(processor.Pen);
Assert.Equal(thickness, pen.Width);
@@ -130,8 +126,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Assert.Equal(pen, processor.Pen);
}
@@ -147,8 +142,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(path, shapepath.Paths[0]);
+ Assert.Equal(path, shapepath.Path);
Assert.Equal(pen, processor.Pen);
}
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs
index 399e79dae..9de052331 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs
@@ -50,9 +50,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -71,9 +70,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -92,9 +90,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -115,9 +112,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Pen pen = Assert.IsType>(processor.Pen);
@@ -138,9 +134,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
@@ -157,9 +152,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType(processor.Path);
- Assert.NotEmpty(path.Paths);
- Polygon vector = Assert.IsType(path.Paths[0].AsShape());
+ Polygon vector = Assert.IsType(path.Path);
LinearLineSegment segment = Assert.IsType(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs
index 3842063b3..215d5a7c7 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs
@@ -46,8 +46,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
@@ -70,9 +69,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
@@ -95,9 +93,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
@@ -122,9 +119,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
@@ -149,9 +145,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
@@ -172,9 +167,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Paths[0].AsShape());
+ SixLabors.Shapes.Rectangle rect = Assert.IsType(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs
deleted file mode 100644
index 30a6646f4..000000000
--- a/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs
+++ /dev/null
@@ -1,156 +0,0 @@
-
-namespace ImageSharp.Tests.Drawing.Paths
-{
- using System;
- using System.IO;
- using ImageSharp;
- using ImageSharp.Drawing.Brushes;
- using Processing;
- using System.Collections.Generic;
- using Xunit;
- using ImageSharp.Drawing;
- using System.Numerics;
- using SixLabors.Shapes;
- using ImageSharp.Drawing.Processors;
- using ImageSharp.Drawing.Pens;
-
- public class DrawShape: IDisposable
- {
- float thickness = 7.2f;
- GraphicsOptions noneDefault = new GraphicsOptions();
- Color color = Color.HotPink;
- SolidBrush brush = Brushes.Solid(Color.HotPink);
- Pen pen = new Pen(Color.Gray, 99.9f);
- IShape shape = new SixLabors.Shapes.Polygon(new LinearLineSegment(new Vector2[] {
- new Vector2(10,10),
- new Vector2(20,10),
- new Vector2(20,10),
- new Vector2(30,10),
- }));
- private ProcessorWatchingImage img;
-
- public DrawShape()
- {
- this.img = new Paths.ProcessorWatchingImage(10, 10);
- }
-
- public void Dispose()
- {
- img.Dispose();
- }
-
- [Fact]
- public void CorrectlySetsBrushThicknessAndShape()
- {
- img.Draw(brush, thickness, shape);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(GraphicsOptions.Default, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Pen pen = Assert.IsType>(processor.Pen);
- Assert.Equal(brush, pen.Brush);
- Assert.Equal(thickness, pen.Width);
- }
-
- [Fact]
- public void CorrectlySetsBrushThicknessShapeAndOptions()
- {
- img.Draw(brush, thickness, shape, noneDefault);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(noneDefault, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Pen pen = Assert.IsType>(processor.Pen);
- Assert.Equal(brush, pen.Brush);
- Assert.Equal(thickness, pen.Width);
- }
-
- [Fact]
- public void CorrectlySetsColorThicknessAndShape()
- {
- img.Draw(color, thickness, shape);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(GraphicsOptions.Default, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Pen pen = Assert.IsType>(processor.Pen);
- Assert.Equal(thickness, pen.Width);
-
- SolidBrush brush = Assert.IsType>(pen.Brush);
- Assert.Equal(color, brush.Color);
- }
-
- [Fact]
- public void CorrectlySetsColorThicknessShapeAndOptions()
- {
- img.Draw(color, thickness, shape, noneDefault);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(noneDefault, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Pen pen = Assert.IsType>(processor.Pen);
- Assert.Equal(thickness, pen.Width);
-
- SolidBrush brush = Assert.IsType>(pen.Brush);
- Assert.Equal(color, brush.Color);
- }
-
- [Fact]
- public void CorrectlySetsPenAndShape()
- {
- img.Draw(pen, shape);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(GraphicsOptions.Default, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Assert.Equal(pen, processor.Pen);
- }
-
- [Fact]
- public void CorrectlySetsPenShapeAndOptions()
- {
- img.Draw(pen, shape, noneDefault);
-
- Assert.NotEmpty(img.ProcessorApplications);
- DrawPathProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(noneDefault, processor.Options);
-
- ShapePath shapepath = Assert.IsType(processor.Path);
- Assert.NotEmpty(shapepath.Paths);
- Assert.Equal(shape, shapepath.Paths[0].AsShape());
-
- Assert.Equal(pen, processor.Pen);
- }
- }
-}
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs
deleted file mode 100644
index 140870a3c..000000000
--- a/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs
+++ /dev/null
@@ -1,107 +0,0 @@
-
-namespace ImageSharp.Tests.Drawing.Paths
-{
- using System;
- using System.IO;
- using ImageSharp;
- using ImageSharp.Drawing.Brushes;
- using Processing;
- using System.Collections.Generic;
- using Xunit;
- using ImageSharp.Drawing;
- using System.Numerics;
- using SixLabors.Shapes;
- using ImageSharp.Drawing.Processors;
- using ImageSharp.Drawing.Pens;
-
- public class FillShape : IDisposable
- {
- GraphicsOptions noneDefault = new GraphicsOptions();
- Color color = Color.HotPink;
- SolidBrush brush = Brushes.Solid(Color.HotPink);
- IShape shape = new Polygon(new LinearLineSegment(new Vector2[] {
- new Vector2(10,10),
- new Vector2(20,10),
- new Vector2(20,10),
- new Vector2(30,10),
- }));
- private ProcessorWatchingImage img;
-
- public FillShape()
- {
- this.img = new Paths.ProcessorWatchingImage(10, 10);
- }
-
- public void Dispose()
- {
- img.Dispose();
- }
-
- [Fact]
- public void CorrectlySetsBrushAndShape()
- {
- img.Fill(brush, shape);
-
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(GraphicsOptions.Default, processor.Options);
-
- ShapeRegion region = Assert.IsType(processor.Region);
- Assert.Equal(shape, region.Shape);
-
- Assert.Equal(brush, processor.Brush);
- }
-
- [Fact]
- public void CorrectlySetsBrushShapeAndOptions()
- {
- img.Fill(brush, shape, noneDefault);
-
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(noneDefault, processor.Options);
-
- ShapeRegion region = Assert.IsType(processor.Region);
- Assert.Equal(shape, region.Shape);
-
- Assert.Equal(brush, processor.Brush);
- }
-
- [Fact]
- public void CorrectlySetsColorAndShape()
- {
- img.Fill(color, shape);
-
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(GraphicsOptions.Default, processor.Options);
-
- ShapeRegion region = Assert.IsType(processor.Region);
- Assert.Equal(shape, region.Shape);
-
- SolidBrush brush = Assert.IsType>(processor.Brush);
- Assert.Equal(color, brush.Color);
- }
-
- [Fact]
- public void CorrectlySetsColorShapeAndOptions()
- {
- img.Fill(color, shape, noneDefault);
-
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
- Assert.Equal(noneDefault, processor.Options);
-
- ShapeRegion region = Assert.IsType(processor.Region);
- Assert.Equal(shape, region.Shape);
-
- SolidBrush brush = Assert.IsType>(processor.Brush);
- Assert.Equal(color, brush.Color);
-
- }
- }
-}
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs
index 5fc967846..494e2a672 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs
+++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs
@@ -20,30 +20,18 @@ namespace ImageSharp.Tests.Drawing.Paths
{
private readonly Mock pathMock1;
private readonly Mock pathMock2;
- private readonly Mock shapeMock1;
private readonly SixLabors.Shapes.Rectangle bounds1;
public ShapePathTests()
{
- this.shapeMock1 = new Mock();
this.pathMock2 = new Mock();
this.pathMock1 = new Mock();
this.bounds1 = new SixLabors.Shapes.Rectangle(10.5f, 10, 10, 10);
pathMock1.Setup(x => x.Bounds).Returns(this.bounds1);
pathMock2.Setup(x => x.Bounds).Returns(this.bounds1);
- shapeMock1.Setup(x => x.Bounds).Returns(this.bounds1);
// wire up the 2 mocks to reference eachother
- pathMock1.Setup(x => x.AsShape()).Returns(() => shapeMock1.Object);
- shapeMock1.Setup(x => x.Paths).Returns(() => ImmutableArray.Create(pathMock1.Object, pathMock2.Object));
- }
-
- [Fact]
- public void ShapePathWithPathCallsAsShape()
- {
- new ShapePath(pathMock1.Object);
-
- pathMock1.Verify(x => x.AsShape());
+ pathMock1.Setup(x => x.AsClosedPath()).Returns(() => pathMock2.Object);
}
[Fact]
@@ -63,7 +51,7 @@ namespace ImageSharp.Tests.Drawing.Paths
ShapePath region = new ShapePath(pathMock1.Object);
int i = region.MaxIntersections;
- shapeMock1.Verify(x => x.MaxIntersections);
+ pathMock1.Verify(x => x.MaxIntersections);
}
[Fact]
@@ -72,7 +60,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int xToScan = 10;
ShapePath region = new ShapePath(pathMock1.Object);
- shapeMock1.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
+ pathMock1.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()))
.Callback((s, e, b, c, o) => {
Assert.Equal(xToScan, s.X);
Assert.Equal(xToScan, e.X);
@@ -82,7 +70,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanX(xToScan, new float[0], 0, 0);
- shapeMock1.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once);
+ pathMock1.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny