Browse Source

Update SixLabors.Shapes

pull/107/head
Scott Williams 9 years ago
parent
commit
b432e33ea8
  1. 112
      src/ImageSharp.Drawing.Paths/DrawShape.cs
  2. 78
      src/ImageSharp.Drawing.Paths/FillShape.cs
  3. 63
      src/ImageSharp.Drawing.Paths/ShapePath.cs
  4. 17
      src/ImageSharp.Drawing.Paths/ShapeRegion.cs
  5. 2
      src/ImageSharp.Drawing.Paths/project.json
  6. 20
      tests/ImageSharp.Tests/Drawing/Paths/DrawBeziersTests.cs
  7. 18
      tests/ImageSharp.Tests/Drawing/Paths/DrawLinesTests.cs
  8. 18
      tests/ImageSharp.Tests/Drawing/Paths/DrawPath.cs
  9. 18
      tests/ImageSharp.Tests/Drawing/Paths/DrawPolygon.cs
  10. 18
      tests/ImageSharp.Tests/Drawing/Paths/DrawRectangle.cs
  11. 156
      tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs
  12. 107
      tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs
  13. 82
      tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs
  14. 43
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

112
src/ImageSharp.Drawing.Paths/DrawShape.cs

@ -1,112 +0,0 @@
// <copyright file="DrawShape.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new ShapePath(shape), options);
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, shape, GraphicsOptions.Default);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, shape);
}
}
}

78
src/ImageSharp.Drawing.Paths/FillShape.cs

@ -1,78 +0,0 @@
// <copyright file="FillShape.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using Drawing;
using Drawing.Brushes;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(shape), options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TColor}"/>.</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape);
}
}
}

63
src/ImageSharp.Drawing.Paths/ShapePath.cs

@ -14,53 +14,27 @@ namespace ImageSharp.Drawing
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// A drawable mapping between a <see cref="IShape"/>/<see cref="IPath"/> and a drawable/fillable region.
/// A drawable mapping between a <see cref="IPath"/> and a drawable region.
/// </summary>
internal class ShapePath : Drawable
{
/// <summary>
/// The fillable shape
/// </summary>
private readonly IShape shape;
/// <summary>
/// Initializes a new instance of the <see cref="ShapePath"/> class.
/// </summary>
/// <param name="path">The path.</param>
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();
}
/// <summary>
/// Initializes a new instance of the <see cref="ShapePath"/> class.
/// Gets the fillable shape
/// </summary>
/// <param name="shape">The shape.</param>
public ShapePath(IShape shape)
: this(shape.Paths)
{
this.shape = shape;
this.Bounds = RectangleF.Ceiling(shape.Bounds.Convert());
}
/// <summary>
/// Initializes a new instance of the <see cref="ShapePath" /> class.
/// </summary>
/// <param name="paths">The paths.</param>
private ShapePath(ImmutableArray<IPath> paths)
{
this.Paths = paths;
}
/// <summary>
/// Gets the drawable paths
/// </summary>
public ImmutableArray<IPath> Paths { get; }
public IPath Path { get; }
/// <inheritdoc/>
public override int MaxIntersections => this.shape.MaxIntersections;
public override int MaxIntersections => this.Path.MaxIntersections;
/// <inheritdoc/>
public override Rectangle Bounds { get; }
@ -73,7 +47,7 @@ namespace ImageSharp.Drawing
Vector2[] innerbuffer = ArrayPool<Vector2>.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<Vector2>.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
};
}
}

17
src/ImageSharp.Drawing.Paths/ShapeRegion.cs

@ -13,33 +13,24 @@ namespace ImageSharp.Drawing
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// A drawable mapping between a <see cref="IShape"/>/<see cref="IPath"/> and a drawable/fillable region.
/// A mapping between a <see cref="IPath"/> and a region.
/// </summary>
internal class ShapeRegion : Region
{
/// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
/// </summary>
/// <param name="path">The path.</param>
public ShapeRegion(IPath path)
: this(path.AsShape())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
/// </summary>
/// <param name="shape">The shape.</param>
public ShapeRegion(IShape shape)
public ShapeRegion(IPath shape)
{
this.Shape = shape;
this.Shape = shape.AsClosedPath();
this.Bounds = shape.Bounds.Convert();
}
/// <summary>
/// Gets the fillable shape
/// </summary>
public IShape Shape { get; }
public IPath Shape { get; }
/// <inheritdoc/>
public override int MaxIntersections => this.Shape.MaxIntersections;

2
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"

20
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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Assert.NotNull(path.Path);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -71,9 +72,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -92,9 +92,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -115,9 +114,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -138,9 +136,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
BezierLineSegment segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);

18
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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -71,9 +70,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -92,9 +90,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -115,9 +112,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -138,9 +134,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]);
SixLabors.Shapes.Path vector = Assert.IsType<SixLabors.Shapes.Path>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);

18
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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(path, shapepath.Paths[0]);
Assert.Equal(path, shapepath.Path);
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(path, shapepath.Paths[0]);
Assert.Equal(path, shapepath.Path);
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(path, shapepath.Paths[0]);
Assert.Equal(path, shapepath.Path);
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(path, shapepath.Paths[0]);
Assert.Equal(path, shapepath.Path);
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<ShapePath>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(path, shapepath.Paths[0]);
Assert.Equal(path, shapepath.Path);
Assert.Equal(pen, processor.Pen);
}

18
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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -71,9 +70,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -92,9 +90,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -115,9 +112,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(noneDefault, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
@ -138,9 +134,8 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath path = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(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<ShapePath>(processor.Path);
Assert.NotEmpty(path.Paths);
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape());
Polygon vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Path);
LinearLineSegment segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]);
Assert.Equal(pen, processor.Pen);

18
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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());
SixLabors.Shapes.Rectangle rect = Assert.IsType<SixLabors.Shapes.Rectangle>(shapepath.Path);
Assert.Equal(rect.Location.X, rectangle.X);
Assert.Equal(rect.Location.Y, rectangle.Y);

156
tests/ImageSharp.Tests/Drawing/Paths/DrawShape.cs

@ -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<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(shape, shapepath.Paths[0].AsShape());
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(shape, shapepath.Paths[0].AsShape());
Pen<Color> pen = Assert.IsType<Pen<Color>>(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<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(shape, shapepath.Paths[0].AsShape());
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
Assert.Equal(thickness, pen.Width);
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(pen.Brush);
Assert.Equal(color, brush.Color);
}
[Fact]
public void CorrectlySetsColorThicknessShapeAndOptions()
{
img.Draw(color, thickness, shape, noneDefault);
Assert.NotEmpty(img.ProcessorApplications);
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(shape, shapepath.Paths[0].AsShape());
Pen<Color> pen = Assert.IsType<Pen<Color>>(processor.Pen);
Assert.Equal(thickness, pen.Width);
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(pen.Brush);
Assert.Equal(color, brush.Color);
}
[Fact]
public void CorrectlySetsPenAndShape()
{
img.Draw(pen, shape);
Assert.NotEmpty(img.ProcessorApplications);
DrawPathProcessor<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(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<Color> processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
ShapePath shapepath = Assert.IsType<ShapePath>(processor.Path);
Assert.NotEmpty(shapepath.Paths);
Assert.Equal(shape, shapepath.Paths[0].AsShape());
Assert.Equal(pen, processor.Pen);
}
}
}

107
tests/ImageSharp.Tests/Drawing/Paths/FillShape.cs

@ -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<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(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<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(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<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Assert.Equal(shape, region.Shape);
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(processor.Brush);
Assert.Equal(color, brush.Color);
}
[Fact]
public void CorrectlySetsColorShapeAndOptions()
{
img.Fill(color, shape, noneDefault);
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Color> processor = Assert.IsType<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Assert.Equal(shape, region.Shape);
SolidBrush<Color> brush = Assert.IsType<SolidBrush<Color>>(processor.Brush);
Assert.Equal(color, brush.Color);
}
}
}

82
tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs

@ -20,30 +20,18 @@ namespace ImageSharp.Tests.Drawing.Paths
{
private readonly Mock<IPath> pathMock1;
private readonly Mock<IPath> pathMock2;
private readonly Mock<IShape> shapeMock1;
private readonly SixLabors.Shapes.Rectangle bounds1;
public ShapePathTests()
{
this.shapeMock1 = new Mock<IShape>();
this.pathMock2 = new Mock<IPath>();
this.pathMock1 = new Mock<IPath>();
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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock1.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
@ -91,7 +79,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int yToScan = 10;
ShapePath region = new ShapePath(pathMock1.Object);
shapeMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
@ -101,7 +89,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanY(yToScan, new float[0], 0, 0);
shapeMock1.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock1.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
@ -109,9 +97,9 @@ namespace ImageSharp.Tests.Drawing.Paths
public void ShapePathFromShapeScanXProxyToShape()
{
int xToScan = 10;
ShapePath region = new ShapePath(shapeMock1.Object);
ShapePath region = new ShapePath(pathMock1.Object);
shapeMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(xToScan, s.X);
Assert.Equal(xToScan, e.X);
@ -121,59 +109,9 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanX(xToScan, new float[0], 0, 0);
shapeMock1.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
public void ShapePathFromShapeScanYProxyToShape()
{
int yToScan = 10;
ShapePath region = new ShapePath(shapeMock1.Object);
shapeMock1.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), 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);
pathMock1.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[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()
{

43
tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

@ -19,19 +19,16 @@ namespace ImageSharp.Tests.Drawing.Paths
public class ShapeRegionTests
{
private readonly Mock<IPath> pathMock;
private readonly Mock<IShape> shapeMock;
private readonly SixLabors.Shapes.Rectangle bounds;
public ShapeRegionTests()
{
this.shapeMock = new Mock<IShape>();
this.pathMock = new Mock<IPath>();
this.bounds = new SixLabors.Shapes.Rectangle(10.5f, 10, 10, 10);
shapeMock.Setup(x => x.Bounds).Returns(this.bounds);
pathMock.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));
pathMock.Setup(x => x.AsClosedPath()).Returns(() => pathMock.Object);
}
[Fact]
@ -39,7 +36,7 @@ namespace ImageSharp.Tests.Drawing.Paths
{
new ShapeRegion(pathMock.Object);
pathMock.Verify(x => x.AsShape());
pathMock.Verify(x => x.AsClosedPath());
}
[Fact]
@ -47,7 +44,7 @@ namespace ImageSharp.Tests.Drawing.Paths
{
ShapeRegion region = new ShapeRegion(pathMock.Object);
Assert.Equal(shapeMock.Object, region.Shape);
Assert.Equal(pathMock.Object, region.Shape);
}
[Fact]
@ -58,7 +55,7 @@ namespace ImageSharp.Tests.Drawing.Paths
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left);
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right);
shapeMock.Verify(x => x.Bounds);
pathMock.Verify(x => x.Bounds);
}
[Fact]
@ -67,7 +64,7 @@ namespace ImageSharp.Tests.Drawing.Paths
ShapeRegion region = new ShapeRegion(pathMock.Object);
int i = region.MaxIntersections;
shapeMock.Verify(x => x.MaxIntersections);
pathMock.Verify(x => x.MaxIntersections);
}
[Fact]
@ -76,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int xToScan = 10;
ShapeRegion region = new ShapeRegion(pathMock.Object);
shapeMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(xToScan, s.X);
Assert.Equal(xToScan, e.X);
@ -86,7 +83,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanX(xToScan, new float[0], 0, 0);
shapeMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
@ -95,7 +92,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int yToScan = 10;
ShapeRegion region = new ShapeRegion(pathMock.Object);
shapeMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
@ -105,7 +102,7 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanY(yToScan, new float[0], 0, 0);
shapeMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
@ -113,9 +110,9 @@ namespace ImageSharp.Tests.Drawing.Paths
public void ShapeRegionFromShapeScanXProxyToShape()
{
int xToScan = 10;
ShapeRegion region = new ShapeRegion(shapeMock.Object);
ShapeRegion region = new ShapeRegion(pathMock.Object);
shapeMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(xToScan, s.X);
Assert.Equal(xToScan, e.X);
@ -125,16 +122,16 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanX(xToScan, new float[0], 0, 0);
shapeMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
public void ShapeRegionFromShapeScanYProxyToShape()
{
int yToScan = 10;
ShapeRegion region = new ShapeRegion(shapeMock.Object);
ShapeRegion region = new ShapeRegion(pathMock.Object);
shapeMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
pathMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((s, e, b, c, o) => {
Assert.Equal(yToScan, s.Y);
Assert.Equal(yToScan, e.Y);
@ -144,27 +141,27 @@ namespace ImageSharp.Tests.Drawing.Paths
int i = region.ScanY(yToScan, new float[0], 0, 0);
shapeMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
pathMock.Verify(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
public void ShapeRegionFromShapeConvertsBoundsProxyToShape()
{
ShapeRegion region = new ShapeRegion(shapeMock.Object);
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);
pathMock.Verify(x => x.Bounds);
}
[Fact]
public void ShapeRegionFromShapeMaxIntersectionsProxyToShape()
{
ShapeRegion region = new ShapeRegion(shapeMock.Object);
ShapeRegion region = new ShapeRegion(pathMock.Object);
int i = region.MaxIntersections;
shapeMock.Verify(x => x.MaxIntersections);
pathMock.Verify(x => x.MaxIntersections);
}
}
}

Loading…
Cancel
Save