diff --git a/src/ImageSharp.Drawing.Paths/DrawPolygon.cs b/src/ImageSharp.Drawing.Paths/DrawPolygon.cs index 73d8ec0e7..571b13c1e 100644 --- a/src/ImageSharp.Drawing.Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing.Paths/DrawPolygon.cs @@ -84,6 +84,22 @@ namespace ImageSharp return source.DrawPolygon(new SolidBrush(color), thickness, points, options); } + /// + /// Draws the provided Points as a closed Linear Polygon with the provided Pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// + /// The Image + /// + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); + } + /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// diff --git a/src/ImageSharp.Drawing.Paths/FillShapes.cs b/src/ImageSharp.Drawing.Paths/FillShape.cs similarity index 98% rename from src/ImageSharp.Drawing.Paths/FillShapes.cs rename to src/ImageSharp.Drawing.Paths/FillShape.cs index 9fe473ee1..6e50f7377 100644 --- a/src/ImageSharp.Drawing.Paths/FillShapes.cs +++ b/src/ImageSharp.Drawing.Paths/FillShape.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs b/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs index 05d6bb6ce..8369cc83f 100644 --- a/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs +++ b/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs @@ -26,11 +26,11 @@ namespace ImageSharp.Drawing.Processors /// A representation of this public static Rectangle Convert(this SixLabors.Shapes.Rectangle source) { - int y = (int)Math.Floor(source.Y); - int width = (int)Math.Ceiling(source.Size.Width); - int x = (int)Math.Floor(source.X); - int height = (int)Math.Ceiling(source.Size.Height); - return new Rectangle(x, y, width, height); + int left = (int)Math.Floor(source.Left); + int right = (int)Math.Ceiling(source.Right); + int top = (int)Math.Floor(source.Top); + int bottom = (int)Math.Ceiling(source.Bottom); + return new Rectangle(left, top, right - left, bottom - top); } } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing.Paths/ShapePath.cs b/src/ImageSharp.Drawing.Paths/ShapePath.cs index 63d5fc9e1..cd994515e 100644 --- a/src/ImageSharp.Drawing.Paths/ShapePath.cs +++ b/src/ImageSharp.Drawing.Paths/ShapePath.cs @@ -25,11 +25,6 @@ namespace ImageSharp.Drawing /// private readonly IShape shape; - /// - /// The drawable paths - /// - private readonly ImmutableArray paths; - /// /// Initializes a new instance of the class. /// @@ -58,9 +53,17 @@ namespace ImageSharp.Drawing /// The paths. private ShapePath(ImmutableArray paths) { - this.paths = paths; + this.Paths = paths; } + /// + /// Gets the drawable paths + /// + /// + /// The paths. + /// + public ImmutableArray Paths { get; } + /// /// Gets the maximum number of intersections to could be returned. /// @@ -163,9 +166,9 @@ namespace ImageSharp.Drawing SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo); float distance = float.MaxValue; - for (int i = 0; i < this.paths.Length; i++) + for (int i = 0; i < this.Paths.Length; i++) { - var p = this.paths[i].Distance(point); + var p = this.Paths[i].Distance(point); if (p.DistanceFromPath < distance) { distance = p.DistanceFromPath; diff --git a/src/ImageSharp.Drawing.Paths/ShapeRegion.cs b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs index d1a59a99d..b43ad26b4 100644 --- a/src/ImageSharp.Drawing.Paths/ShapeRegion.cs +++ b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs @@ -20,11 +20,6 @@ namespace ImageSharp.Drawing /// internal class ShapeRegion : Region { - /// - /// The fillable shape - /// - private readonly IShape shape; - /// /// Initializes a new instance of the class. /// @@ -40,17 +35,22 @@ namespace ImageSharp.Drawing /// The shape. public ShapeRegion(IShape shape) { - this.shape = shape; + this.Shape = shape; this.Bounds = shape.Bounds.Convert(); } + /// + /// Gets the fillable shape + /// + public IShape Shape { get; } + /// /// Gets the maximum number of intersections to could be returned. /// /// /// The maximum intersections. /// - public override int MaxIntersections => this.shape.MaxIntersections; + public override int MaxIntersections => this.Shape.MaxIntersections; /// /// Gets the bounds. @@ -77,7 +77,7 @@ namespace ImageSharp.Drawing Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); try { - int count = this.shape.FindIntersections( + int count = this.Shape.FindIntersections( start, end, innerbuffer, @@ -114,7 +114,7 @@ namespace ImageSharp.Drawing Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); try { - int count = this.shape.FindIntersections( + int count = this.Shape.FindIntersections( start, end, innerbuffer, diff --git a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs index 1513443c4..3fe557080 100644 --- a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs @@ -25,10 +25,6 @@ namespace ImageSharp.Drawing.Processors private const float AntialiasFactor = 1f; private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor - private readonly IPen pen; - private readonly Path region; - private readonly GraphicsOptions options; - /// /// Initializes a new instance of the class. /// @@ -37,16 +33,40 @@ namespace ImageSharp.Drawing.Processors /// The options. public DrawPathProcessor(IPen pen, Path region, GraphicsOptions options) { - this.region = region; - this.pen = pen; - this.options = options; + this.Path = region; + this.Pen = pen; + this.Options = options; } + /// + /// Gets the options. + /// + /// + /// The options. + /// + public GraphicsOptions Options { get; } + + /// + /// Gets the pen. + /// + /// + /// The pen. + /// + public IPen Pen { get; } + + /// + /// Gets the path. + /// + /// + /// The path. + /// + public Path Path { get; } + /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { using (PixelAccessor sourcePixels = source.Lock()) - using (PenApplicator applicator = this.pen.CreateApplicator(sourcePixels, this.region.Bounds)) + using (PenApplicator applicator = this.Pen.CreateApplicator(sourcePixels, this.Path.Bounds)) { var rect = RectangleF.Ceiling(applicator.RequiredRegion); @@ -89,7 +109,7 @@ namespace ImageSharp.Drawing.Processors { // TODO add find intersections code to skip and scan large regions of this. int offsetX = x - startX; - var info = this.region.GetPointInfo(offsetX, offsetY); + var info = this.Path.GetPointInfo(offsetX, offsetY); var color = applicator.GetColor(offsetX, offsetY, info); @@ -120,7 +140,7 @@ namespace ImageSharp.Drawing.Processors { return 1; } - else if (this.options.Antialias && distance < AntialiasFactor) + else if (this.Options.Antialias && distance < AntialiasFactor) { return 1 - (distance / AntialiasFactor); } diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index 2f6f8af7b..6719d365a 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -22,9 +22,6 @@ namespace ImageSharp.Drawing.Processors { private const float AntialiasFactor = 1f; private const int DrawPadding = 1; - private readonly IBrush fillColor; - private readonly Region region; - private readonly GraphicsOptions options; /// /// Initializes a new instance of the class. @@ -34,15 +31,39 @@ namespace ImageSharp.Drawing.Processors /// The options. public FillRegionProcessor(IBrush brush, Region region, GraphicsOptions options) { - this.region = region; - this.fillColor = brush; - this.options = options; + this.Region = region; + this.Brush = brush; + this.Options = options; } + /// + /// Gets the brush. + /// + /// + /// The brush. + /// + public IBrush Brush { get; } + + /// + /// Gets the region. + /// + /// + /// The region. + /// + public Region Region { get; } + + /// + /// Gets the options. + /// + /// + /// The options. + /// + public GraphicsOptions Options { get; } + /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - Rectangle rect = RectangleF.Ceiling(this.region.Bounds); // rounds the points out away from the center + Rectangle rect = RectangleF.Ceiling(this.Region.Bounds); // rounds the points out away from the center int polyStartY = sourceRectangle.Y - DrawPadding; int polyEndY = sourceRectangle.Bottom + DrawPadding; @@ -62,10 +83,10 @@ namespace ImageSharp.Drawing.Processors ArrayPool arrayPool = ArrayPool.Shared; - int maxIntersections = this.region.MaxIntersections; + int maxIntersections = this.Region.MaxIntersections; using (PixelAccessor sourcePixels = source.Lock()) - using (BrushApplicator applicator = this.fillColor.CreateApplicator(sourcePixels, rect)) + using (BrushApplicator applicator = this.Brush.CreateApplicator(sourcePixels, rect)) { Parallel.For( minY, @@ -80,7 +101,7 @@ namespace ImageSharp.Drawing.Processors float right = endX; // foreach line we get all the points where this line crosses the polygon - int pointsFound = this.region.ScanY(y, buffer, maxIntersections, 0); + int pointsFound = this.Region.ScanY(y, buffer, maxIntersections, 0); if (pointsFound == 0) { // nothign on this line skip @@ -156,7 +177,7 @@ namespace ImageSharp.Drawing.Processors float opacity = 1; if (!isInside && !onCorner) { - if (this.options.Antialias) + if (this.Options.Antialias) { float distance = float.MaxValue; if (x == lastPoint || x == nextPoint) @@ -207,7 +228,7 @@ namespace ImageSharp.Drawing.Processors } }); - if (this.options.Antialias) + if (this.Options.Antialias) { // we only need to do the X can for antialiasing purposes Parallel.For( @@ -224,7 +245,7 @@ namespace ImageSharp.Drawing.Processors float right = polyEndY; // foreach line we get all the points where this line crosses the polygon - int pointsFound = this.region.ScanX(x, buffer, maxIntersections, 0); + int pointsFound = this.Region.ScanX(x, buffer, maxIntersections, 0); if (pointsFound == 0) { // nothign on this line skip @@ -314,7 +335,7 @@ namespace ImageSharp.Drawing.Processors float opacity = 1; if (!isInside && !onCorner) { - if (this.options.Antialias) + if (this.Options.Antialias) { float distance = float.MaxValue; if (y == lastPoint || y == nextPoint) diff --git a/src/ImageSharp/Image/ImageBase{TColor}.cs b/src/ImageSharp/Image/ImageBase{TColor}.cs index 1b3abd360..b179d1158 100644 --- a/src/ImageSharp/Image/ImageBase{TColor}.cs +++ b/src/ImageSharp/Image/ImageBase{TColor}.cs @@ -7,6 +7,7 @@ namespace ImageSharp { using System; using System.Diagnostics; + using Processing; /// /// The base class of all images. Encapsulates the basic properties and methods required to manipulate @@ -120,6 +121,16 @@ namespace ImageSharp /// public Configuration Configuration { get; private set; } + /// + /// Applies the processor. + /// + /// The processor. + /// The rectangle. + public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + processor.Apply(this, rectangle); + } + /// public void Dispose() { diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs index d9073ad16..db07afe2a 100644 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ b/src/ImageSharp/Image/ImageProcessingExtensions.cs @@ -41,13 +41,7 @@ namespace ImageSharp public static Image Apply(this Image source, Rectangle sourceRectangle, IImageProcessor processor) where TColor : struct, IPackedPixel, IEquatable { - processor.Apply(source, sourceRectangle); - - foreach (ImageFrame sourceFrame in source.Frames) - { - processor.Apply(sourceFrame, sourceRectangle); - } - + source.ApplyProcessor(processor, sourceRectangle); return source; } } diff --git a/src/ImageSharp/Image/Image{TColor}.cs b/src/ImageSharp/Image/Image{TColor}.cs index 5c83ef9bb..84bae39cc 100644 --- a/src/ImageSharp/Image/Image{TColor}.cs +++ b/src/ImageSharp/Image/Image{TColor}.cs @@ -16,6 +16,7 @@ namespace ImageSharp using System.Threading.Tasks; using Formats; + using Processing; /// /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. @@ -219,6 +220,21 @@ namespace ImageSharp /// public ExifProfile ExifProfile { get; set; } + /// + /// Applies the processor to the image. + /// + /// The processor to apply to the image. + /// The structure that specifies the portion of the image object to draw. + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + // we want to put this on on here as it gives us a really go place to test/verify processor settings + base.ApplyProcessor(processor, rectangle); + foreach (ImageFrame sourceFrame in this.Frames) + { + sourceFrame.ApplyProcessor(processor, rectangle); + } + } + /// /// Saves the image to the given stream using the currently loaded image format. /// diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs new file mode 100644 index 000000000..967cd1970 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs @@ -0,0 +1,168 @@ + +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 DrawBeziersTests : IDisposable + { + float thickness = 7.2f; + GraphicsOptions noneDefault = new GraphicsOptions(); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Pen pen = new Pen(Color.Firebrick, 99.9f); + Vector2[] points = new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + }; + private ProcessorWatchingImage img; + + public DrawBeziersTests() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_Thickness_points() + { + img.DrawBeziers(brush, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_points_options() + { + img.DrawBeziers(brush, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_points() + { + img.DrawBeziers(color, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_points_options() + { + img.DrawBeziers(color, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_points() + { + img.DrawBeziers(pen, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_points_options() + { + img.DrawBeziers(pen, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var 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 new file mode 100644 index 000000000..3b203cdd8 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs @@ -0,0 +1,168 @@ + +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 DrawLinesTests : 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); + Vector2[] points = new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + }; + private ProcessorWatchingImage img; + + public DrawLinesTests() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_Thickness_points() + { + img.DrawLines(brush, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_points_options() + { + img.DrawLines(brush, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_points() + { + img.DrawLines(color, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_points_options() + { + img.DrawLines(color, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_points() + { + img.DrawLines(pen, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var segment = Assert.IsType(vector.LineSegments[0]); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_points_options() + { + img.DrawLines(pen, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0]); + var 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 new file mode 100644 index 000000000..8ce7dcba2 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs @@ -0,0 +1,156 @@ + +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 DrawPath : 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); + IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + })); + private ProcessorWatchingImage img; + + public DrawPath() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_Thickness_path() + { + img.Draw(brush, thickness, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_path_options() + { + img.Draw(brush, thickness, path, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_path() + { + img.Draw(color, thickness, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_path_options() + { + img.Draw(color, thickness, path, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_path() + { + img.Draw(pen, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_path_options() + { + img.Draw(pen, path, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(path, shapepath.Paths[0]); + + Assert.Equal(pen, processor.Pen); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs new file mode 100644 index 000000000..9a931470d --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs @@ -0,0 +1,168 @@ + +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 DrawPolygon : 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); + Vector2[] points = new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + }; + private ProcessorWatchingImage img; + + public DrawPolygon() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_Thickness_points() + { + img.DrawPolygon(brush, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_points_options() + { + img.DrawPolygon(brush, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_points() + { + img.DrawPolygon(color, thickness, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_points_options() + { + img.DrawPolygon(color, thickness, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var segment = Assert.IsType(vector.LineSegments[0]); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_points() + { + img.DrawPolygon(pen, points); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var segment = Assert.IsType(vector.LineSegments[0]); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_points_options() + { + img.DrawPolygon(pen, points, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var path = Assert.IsType(processor.Path); + Assert.NotEmpty(path.Paths); + + var vector = Assert.IsType(path.Paths[0].AsShape()); + var 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 new file mode 100644 index 000000000..f6680bc9c --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs @@ -0,0 +1,187 @@ + +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 DrawRectangle : 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); + ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 98, 324); + + private ProcessorWatchingImage img; + + public DrawRectangle() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_Thickness_rectangle() + { + img.Draw(brush, thickness, rectangle); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_rectangle_options() + { + img.Draw(brush, thickness, rectangle, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_rectangle() + { + img.Draw(color, thickness, rectangle); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_rectangle_options() + { + img.Draw(color, thickness, rectangle, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_rectangle() + { + img.Draw(pen, rectangle); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_rectangle_options() + { + img.Draw(pen, rectangle, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + + var rect = Assert.IsType(shapepath.Paths[0].AsShape()); + + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + Assert.Equal(pen, processor.Pen); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs b/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs new file mode 100644 index 000000000..8572099db --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs @@ -0,0 +1,156 @@ + +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 Brush_Thickness_shape() + { + img.Draw(brush, thickness, shape); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(shape, shapepath.Paths[0].AsShape()); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void Brush_Thickness_shape_options() + { + img.Draw(brush, thickness, shape, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(shape, shapepath.Paths[0].AsShape()); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(brush, pen.Brush); + Assert.Equal(thickness, pen.Width); + } + + [Fact] + public void color_Thickness_shape() + { + img.Draw(color, thickness, shape); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(shape, shapepath.Paths[0].AsShape()); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_Thickness_shape_options() + { + img.Draw(color, thickness, shape, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(shape, shapepath.Paths[0].AsShape()); + + var pen = Assert.IsType>(processor.Pen); + Assert.Equal(thickness, pen.Width); + + var brush = Assert.IsType>(pen.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void pen_shape() + { + img.Draw(pen, shape); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var shapepath = Assert.IsType(processor.Path); + Assert.NotEmpty(shapepath.Paths); + Assert.Equal(shape, shapepath.Paths[0].AsShape()); + + Assert.Equal(pen, processor.Pen); + } + + [Fact] + public void pen_path_options() + { + img.Draw(pen, shape, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var 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/Extensions.cs b/tests/ImageSharp.Tests/Drawing/Paths/Extensions.cs new file mode 100644 index 000000000..37720253d --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/Extensions.cs @@ -0,0 +1,49 @@ + +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 Extensions + { + [Fact] + public void ConvertPointInfo() + { + SixLabors.Shapes.PointInfo src = new SixLabors.Shapes.PointInfo + { + ClosestPointOnPath = Vector2.UnitX, + SearchPoint = Vector2.UnitY, + DistanceAlongPath = 99f, + DistanceFromPath = 82f + }; + ImageSharp.Drawing.PointInfo info = src.Convert(); + + Assert.Equal(src.DistanceAlongPath, info.DistanceAlongPath); + Assert.Equal(src.DistanceFromPath, info.DistanceFromPath); + } + + [Theory] + [InlineData(0.5, 0.5, 5, 5, 0,0,6,6)] + [InlineData(1, 1, 5, 5, 1,1,5,5)] + public void ConvertRectangle(float x, float y, float width, float height, int expectedX, int expectedY, int expectedWidth, int expectedHeight) + { + SixLabors.Shapes.Rectangle src = new SixLabors.Shapes.Rectangle(x, y, width, height); + ImageSharp.Rectangle actual = src.Convert(); + + Assert.Equal(expectedX, actual.X); + Assert.Equal(expectedY, actual.Y); + Assert.Equal(expectedWidth, actual.Width); + Assert.Equal(expectedHeight, actual.Height); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs new file mode 100644 index 000000000..04a2a82ab --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -0,0 +1,112 @@ + +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 FillPath : IDisposable + { + GraphicsOptions noneDefault = new GraphicsOptions(); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + IPath path = new SixLabors.Shapes.Path(new LinearLineSegment(new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + })); + private ProcessorWatchingImage img; + + public FillPath() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_path() + { + img.Fill(brush, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segments = Assert.IsType(polygon.LineSegments[0]); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void Brush_path_options() + { + img.Fill(brush, path, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segments = Assert.IsType(polygon.LineSegments[0]); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void color_path() + { + img.Fill(color, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segments = Assert.IsType(polygon.LineSegments[0]); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_path_options() + { + img.Fill(color, path, noneDefault); + + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segments = Assert.IsType(polygon.LineSegments[0]); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs new file mode 100644 index 000000000..2c95eb209 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -0,0 +1,111 @@ + +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 FillPolygon : IDisposable + { + GraphicsOptions noneDefault = new GraphicsOptions(); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + Vector2[] path = new Vector2[] { + new Vector2(10,10), + new Vector2(20,10), + new Vector2(20,10), + new Vector2(30,10), + }; + private ProcessorWatchingImage img; + + public FillPolygon() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_path() + { + img.FillPolygon(brush, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segemnt = Assert.IsType(polygon.LineSegments[0]); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void Brush_path_options() + { + img.FillPolygon(brush, path, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segemnt = Assert.IsType(polygon.LineSegments[0]); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void color_path() + { + img.FillPolygon(color, path); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segemnt = Assert.IsType(polygon.LineSegments[0]); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_path_options() + { + img.FillPolygon(color, path, noneDefault); + + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var polygon = Assert.IsType(region.Shape); + var segemnt = Assert.IsType(polygon.LineSegments[0]); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs new file mode 100644 index 000000000..520b107b9 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -0,0 +1,119 @@ + +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 FillRectangle : IDisposable + { + GraphicsOptions noneDefault = new GraphicsOptions(); + Color color = Color.HotPink; + SolidBrush brush = Brushes.Solid(Color.HotPink); + ImageSharp.Rectangle rectangle = new ImageSharp.Rectangle(10, 10, 77, 76); + + private ProcessorWatchingImage img; + + public FillRectangle() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_path() + { + img.Fill(brush, rectangle); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void Brush_path_options() + { + img.Fill(brush, rectangle, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void color_path() + { + img.Fill(color, rectangle); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + var rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_path_options() + { + img.Fill(color, rectangle, noneDefault); + + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + var rect = Assert.IsType(region.Shape); + Assert.Equal(rect.Location.X, rectangle.X); + Assert.Equal(rect.Location.Y, rectangle.Y); + Assert.Equal(rect.Size.Width, rectangle.Width); + Assert.Equal(rect.Size.Height, rectangle.Height); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs new file mode 100644 index 000000000..26bf61b5c --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs @@ -0,0 +1,108 @@ + +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 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 FillShape() + { + this.img = new Paths.ProcessorWatchingImage(10, 10); + } + + public void Dispose() + { + img.Dispose(); + } + + [Fact] + public void Brush_shape() + { + img.Fill(brush, shape); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + Assert.Equal(shape, region.Shape); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void Brush_shape_options() + { + img.Fill(brush, shape, noneDefault); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + Assert.Equal(shape, region.Shape); + + Assert.Equal(brush, processor.Brush); + } + + [Fact] + public void color_shape() + { + img.Fill(color, shape); + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(GraphicsOptions.Default, processor.Options); + + var region = Assert.IsType(processor.Region); + Assert.Equal(shape, region.Shape); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + } + + [Fact] + public void color_shape_options() + { + img.Fill(color, shape, noneDefault); + + + Assert.NotEmpty(img.ProcessorApplications); + var processor = Assert.IsType>(img.ProcessorApplications[0].processor); + + Assert.Equal(noneDefault, processor.Options); + + var region = Assert.IsType(processor.Region); + Assert.Equal(shape, region.Shape); + + var brush = Assert.IsType>(processor.Brush); + Assert.Equal(color, brush.Color); + + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs new file mode 100644 index 000000000..ad3d41bc6 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs @@ -0,0 +1,38 @@ + +namespace ImageSharp.Tests.Drawing.Paths +{ + using System; + using System.IO; + using ImageSharp; + using Processing; + using System.Collections.Generic; + + /// + /// Watches but does not actually run the processors against the image. + /// + /// + public class ProcessorWatchingImage : Image + { + public List ProcessorApplications { get; } = new List(); + + public ProcessorWatchingImage(int width, int height) + : base(width, height, Configuration.CreateDefaultInstance()) + { + } + + public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + ProcessorApplications.Add(new ProcessorDetails + { + processor = processor, + rectangle = rectangle + }); + } + + public struct ProcessorDetails + { + public IImageProcessor processor; + public Rectangle rectangle; + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs new file mode 100644 index 000000000..24e921ccb --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs @@ -0,0 +1,188 @@ + +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; + using Moq; + using System.Collections.Immutable; + + public class ShapePathTests + { + 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 ShapePathWithPath_CallsAsShape() + { + new ShapePath(pathMock1.Object); + + pathMock1.Verify(x => x.AsShape()); + } + + [Fact] + public void ShapePathFromPathConvertsBoundsDoesNotProxyToShape() + { + ShapePath region = new ShapePath(pathMock1.Object); + + Assert.Equal(Math.Floor(bounds1.Left), region.Bounds.Left); + Assert.Equal(Math.Ceiling(bounds1.Right), region.Bounds.Right); + + pathMock1.Verify(x => x.Bounds); + } + + [Fact] + public void ShapePathFromPathMaxIntersectionsProxyToShape() + { + ShapePath region = new ShapePath(pathMock1.Object); + + int i = region.MaxIntersections; + shapeMock1.Verify(x => x.MaxIntersections); + } + + [Fact] + public void ShapePathFromPathScanXProxyToShape() + { + int xToScan = 10; + ShapePath region = new ShapePath(pathMock1.Object); + + shapeMock1.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); + Assert.True(s.Y < bounds1.Top); + Assert.True(e.Y > bounds1.Bottom); + }).Returns(0); + + 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); + } + + [Fact] + public void ShapePathFromPathScanYProxyToShape() + { + int yToScan = 10; + ShapePath region = new ShapePath(pathMock1.Object); + + shapeMock1.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((s, e, b, c, o) => { + Assert.Equal(yToScan, s.Y); + Assert.Equal(yToScan, e.Y); + Assert.True(s.X < bounds1.Left); + Assert.True(e.X > bounds1.Right); + }).Returns(0); + + int i = region.ScanY(yToScan, new float[0], 0, 0); + + shapeMock1.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + + [Fact] + public void ShapePathFromShapeScanXProxyToShape() + { + int xToScan = 10; + ShapePath region = new ShapePath(shapeMock1.Object); + + shapeMock1.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); + Assert.True(s.Y < bounds1.Top); + Assert.True(e.Y > bounds1.Bottom); + }).Returns(0); + + 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); + } + + [Fact] + public void ShapePathFromShapeScanYProxyToShape() + { + int yToScan = 10; + ShapePath region = new ShapePath(shapeMock1.Object); + + shapeMock1.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((s, e, b, c, o) => { + Assert.Equal(yToScan, s.Y); + Assert.Equal(yToScan, e.Y); + Assert.True(s.X < bounds1.Left); + Assert.True(e.X > bounds1.Right); + }).Returns(0); + + int i = region.ScanY(yToScan, new float[0], 0, 0); + + shapeMock1.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Fact] + public void ShapePathFromShapeConvertsBoundsProxyToShape() + { + ShapePath region = new ShapePath(shapeMock1.Object); + + Assert.Equal(Math.Floor(bounds1.Left), region.Bounds.Left); + Assert.Equal(Math.Ceiling(bounds1.Right), region.Bounds.Right); + + shapeMock1.Verify(x => x.Bounds); + } + + [Fact] + public void ShapePathFromShapeMaxIntersectionsProxyToShape() + { + ShapePath region = new ShapePath(shapeMock1.Object); + + int i = region.MaxIntersections; + shapeMock1.Verify(x => x.MaxIntersections); + } + + [Fact] + public void GetPointInfoCallAllPathsForShape() + { + ShapePath region = new ShapePath(shapeMock1.Object); + + ImageSharp.Drawing.PointInfo info = region.GetPointInfo(10, 1); + + pathMock1.Verify(x => x.Distance(new Vector2(10, 1)), Times.Once); + pathMock2.Verify(x => x.Distance(new Vector2(10, 1)), Times.Once); + } + + [Fact] + public void GetPointInfoCallSinglePathForPath() + { + ShapePath region = new ShapePath(pathMock1.Object); + + ImageSharp.Drawing.PointInfo info = region.GetPointInfo(10, 1); + + pathMock1.Verify(x => x.Distance(new Vector2(10, 1)), Times.Once); + pathMock2.Verify(x => x.Distance(new Vector2(10, 1)), Times.Never); + } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs new file mode 100644 index 000000000..e983dce66 --- /dev/null +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -0,0 +1,170 @@ + +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; + using Moq; + using System.Collections.Immutable; + + public class ShapeRegionTests + { + private readonly Mock pathMock; + private readonly Mock shapeMock; + private readonly SixLabors.Shapes.Rectangle bounds; + + public ShapeRegionTests() + { + this.shapeMock = new Mock(); + this.pathMock = new Mock(); + + this.bounds = new SixLabors.Shapes.Rectangle(10.5f, 10, 10, 10); + shapeMock.Setup(x => x.Bounds).Returns(this.bounds); + // wire up the 2 mocks to reference eachother + pathMock.Setup(x => x.AsShape()).Returns(() => shapeMock.Object); + shapeMock.Setup(x => x.Paths).Returns(() => ImmutableArray.Create(pathMock.Object)); + } + + [Fact] + public void ShapeRegionWithPath_CallsAsShape() + { + new ShapeRegion(pathMock.Object); + + pathMock.Verify(x => x.AsShape()); + } + + [Fact] + public void ShapeRegionWithPath_RetainsShape() + { + ShapeRegion region = new ShapeRegion(pathMock.Object); + + Assert.Equal(shapeMock.Object, region.Shape); + } + + [Fact] + public void ShapeRegionFromPathConvertsBoundsProxyToShape() + { + ShapeRegion region = new ShapeRegion(pathMock.Object); + + Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left); + Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right); + + shapeMock.Verify(x => x.Bounds); + } + + [Fact] + public void ShapeRegionFromPathMaxIntersectionsProxyToShape() + { + ShapeRegion region = new ShapeRegion(pathMock.Object); + + int i = region.MaxIntersections; + shapeMock.Verify(x => x.MaxIntersections); + } + + [Fact] + public void ShapeRegionFromPathScanXProxyToShape() + { + int xToScan = 10; + ShapeRegion region = new ShapeRegion(pathMock.Object); + + shapeMock.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); + Assert.True(s.Y < bounds.Top); + Assert.True(e.Y > bounds.Bottom); + }).Returns(0); + + int i = region.ScanX(xToScan, new float[0], 0, 0); + + shapeMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Fact] + public void ShapeRegionFromPathScanYProxyToShape() + { + int yToScan = 10; + ShapeRegion region = new ShapeRegion(pathMock.Object); + + shapeMock.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((s, e, b, c, o) => { + Assert.Equal(yToScan, s.Y); + Assert.Equal(yToScan, e.Y); + Assert.True(s.X < bounds.Left); + Assert.True(e.X > bounds.Right); + }).Returns(0); + + int i = region.ScanY(yToScan, new float[0], 0, 0); + + shapeMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + + [Fact] + public void ShapeRegionFromShapeScanXProxyToShape() + { + int xToScan = 10; + ShapeRegion region = new ShapeRegion(shapeMock.Object); + + shapeMock.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); + Assert.True(s.Y < bounds.Top); + Assert.True(e.Y > bounds.Bottom); + }).Returns(0); + + int i = region.ScanX(xToScan, new float[0], 0, 0); + + shapeMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Fact] + public void ShapeRegionFromShapeScanYProxyToShape() + { + int yToScan = 10; + ShapeRegion region = new ShapeRegion(shapeMock.Object); + + shapeMock.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) + .Callback((s, e, b, c, o) => { + Assert.Equal(yToScan, s.Y); + Assert.Equal(yToScan, e.Y); + Assert.True(s.X < bounds.Left); + Assert.True(e.X > bounds.Right); + }).Returns(0); + + int i = region.ScanY(yToScan, new float[0], 0, 0); + + shapeMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Fact] + public void ShapeRegionFromShapeConvertsBoundsProxyToShape() + { + ShapeRegion region = new ShapeRegion(shapeMock.Object); + + Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left); + Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right); + + shapeMock.Verify(x => x.Bounds); + } + + [Fact] + public void ShapeRegionFromShapeMaxIntersectionsProxyToShape() + { + ShapeRegion region = new ShapeRegion(shapeMock.Object); + + int i = region.MaxIntersections; + shapeMock.Verify(x => x.MaxIntersections); + } + } +} diff --git a/tests/ImageSharp.Tests/project.json b/tests/ImageSharp.Tests/project.json index 2a01aff84..3761bb385 100644 --- a/tests/ImageSharp.Tests/project.json +++ b/tests/ImageSharp.Tests/project.json @@ -45,7 +45,9 @@ }, "ImageSharp.Processing": { "target": "project" - } + }, + //alpha supports netstandard + "Moq": "4.6.38-alpha" }, "frameworks": { "netcoreapp1.1": {