mirror of https://github.com/SixLabors/ImageSharp
25 changed files with 2036 additions and 55 deletions
@ -1,4 +1,4 @@ |
|||
// <copyright file="FillShapes.cs" company="James Jackson-South">
|
|||
// <copyright file="FillShape.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_points() |
|||
{ |
|||
img.DrawBeziers(pen, points); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<BezierLineSegment>(vector.LineSegments[0]); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_points() |
|||
{ |
|||
img.DrawLines(pen, points); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Path>(path.Paths[0]); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(path, shapepath.Paths[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(path, shapepath.Paths[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(path, shapepath.Paths[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(path, shapepath.Paths[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_path() |
|||
{ |
|||
img.Draw(pen, path); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(path, shapepath.Paths[0]); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_points() |
|||
{ |
|||
img.DrawPolygon(pen, points); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var path = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(path.Paths); |
|||
|
|||
var vector = Assert.IsType<SixLabors.Shapes.Polygon>(path.Paths[0].AsShape()); |
|||
var segment = Assert.IsType<LinearLineSegment>(vector.LineSegments[0]); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
|
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
|
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
|
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_rectangle() |
|||
{ |
|||
img.Draw(pen, rectangle); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
|
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
|
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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); |
|||
} |
|||
} |
|||
} |
|||
@ -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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|||
|
|||
var pen = Assert.IsType<Pen<Color>>(processor.Pen); |
|||
Assert.Equal(thickness, pen.Width); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(pen.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
|
|||
[Fact] |
|||
public void pen_shape() |
|||
{ |
|||
img.Draw(pen, shape); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var 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 pen_path_options() |
|||
{ |
|||
img.Draw(pen, shape, noneDefault); |
|||
|
|||
Assert.NotEmpty(img.ProcessorApplications); |
|||
var processor = Assert.IsType<DrawPathProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var shapepath = Assert.IsType<ShapePath>(processor.Path); |
|||
Assert.NotEmpty(shapepath.Paths); |
|||
Assert.Equal(shape, shapepath.Paths[0].AsShape()); |
|||
|
|||
Assert.Equal(pen, processor.Pen); |
|||
} |
|||
} |
|||
} |
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segments = Assert.IsType<LinearLineSegment>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segments = Assert.IsType<LinearLineSegment>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(processor.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segemnt = Assert.IsType<LinearLineSegment>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segemnt = Assert.IsType<LinearLineSegment>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var polygon = Assert.IsType<Polygon>(region.Shape); |
|||
var segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(processor.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
} |
|||
} |
|||
@ -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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<SolidBrush<Color>>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
var rect = Assert.IsType<SixLabors.Shapes.Rectangle>(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<SolidBrush<Color>>(processor.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
} |
|||
} |
|||
} |
|||
@ -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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(GraphicsOptions.Default, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
Assert.Equal(shape, region.Shape); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(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<FillRegionProcessor<Color>>(img.ProcessorApplications[0].processor); |
|||
|
|||
Assert.Equal(noneDefault, processor.Options); |
|||
|
|||
var region = Assert.IsType<ShapeRegion>(processor.Region); |
|||
Assert.Equal(shape, region.Shape); |
|||
|
|||
var brush = Assert.IsType<SolidBrush<Color>>(processor.Brush); |
|||
Assert.Equal(color, brush.Color); |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
|
|||
namespace ImageSharp.Tests.Drawing.Paths |
|||
{ |
|||
using System; |
|||
using System.IO; |
|||
using ImageSharp; |
|||
using Processing; |
|||
using System.Collections.Generic; |
|||
|
|||
/// <summary>
|
|||
/// Watches but does not actually run the processors against the image.
|
|||
/// </summary>
|
|||
/// <seealso cref="ImageSharp.Image{ImageSharp.Color}" />
|
|||
public class ProcessorWatchingImage : Image<Color> |
|||
{ |
|||
public List<ProcessorDetails> ProcessorApplications { get; } = new List<ProcessorDetails>(); |
|||
|
|||
public ProcessorWatchingImage(int width, int height) |
|||
: base(width, height, Configuration.CreateDefaultInstance()) |
|||
{ |
|||
} |
|||
|
|||
public override void ApplyProcessor(IImageProcessor<Color> processor, Rectangle rectangle) |
|||
{ |
|||
ProcessorApplications.Add(new ProcessorDetails |
|||
{ |
|||
processor = processor, |
|||
rectangle = rectangle |
|||
}); |
|||
} |
|||
|
|||
public struct ProcessorDetails |
|||
{ |
|||
public IImageProcessor<Color> processor; |
|||
public Rectangle rectangle; |
|||
} |
|||
} |
|||
} |
|||
@ -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<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 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<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); |
|||
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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ShapePathFromPathScanYProxyToShape() |
|||
{ |
|||
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>())) |
|||
.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 ShapePathFromShapeScanXProxyToShape() |
|||
{ |
|||
int xToScan = 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(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<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); |
|||
} |
|||
|
|||
[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); |
|||
} |
|||
} |
|||
} |
|||
@ -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<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); |
|||
// 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<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); |
|||
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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once); |
|||
} |
|||
|
|||
[Fact] |
|||
public void ShapeRegionFromPathScanYProxyToShape() |
|||
{ |
|||
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>())) |
|||
.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 < 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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once); |
|||
} |
|||
|
|||
|
|||
[Fact] |
|||
public void ShapeRegionFromShapeScanXProxyToShape() |
|||
{ |
|||
int xToScan = 10; |
|||
ShapeRegion region = new ShapeRegion(shapeMock.Object); |
|||
|
|||
shapeMock.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); |
|||
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<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); |
|||
|
|||
shapeMock.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 < 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<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); |
|||
|
|||
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); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue