mirror of https://github.com/SixLabors/ImageSharp
20 changed files with 131 additions and 142 deletions
@ -1,131 +1,144 @@ |
|||||
// Copyright (c) Six Labors and contributors.
|
// Copyright (c) Six Labors and contributors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Collections.Immutable; |
|
||||
using System.IO; |
|
||||
using System.Numerics; |
|
||||
using SixLabors.ImageSharp; |
|
||||
using SixLabors.ImageSharp.Drawing; |
|
||||
using SixLabors.ImageSharp.Drawing.Brushes; |
|
||||
using SixLabors.ImageSharp.Drawing.Pens; |
|
||||
using SixLabors.ImageSharp.Drawing.Processors; |
|
||||
using SixLabors.ImageSharp.Processing; |
|
||||
using Moq; |
|
||||
using SixLabors.Primitives; |
|
||||
using SixLabors.Shapes; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Tests.Drawing.Paths |
namespace SixLabors.ImageSharp.Tests.Drawing.Paths |
||||
{ |
{ |
||||
public class ShapeRegionTests |
using System; |
||||
|
|
||||
|
using Moq; |
||||
|
|
||||
|
using SixLabors.ImageSharp.Drawing; |
||||
|
using SixLabors.Primitives; |
||||
|
using SixLabors.Shapes; |
||||
|
|
||||
|
using Xunit; |
||||
|
|
||||
|
public class ShapeRegionTests |
||||
{ |
{ |
||||
private readonly Mock<IPath> pathMock; |
private readonly Mock<IPath> pathMock; |
||||
private readonly SixLabors.Primitives.RectangleF bounds; |
|
||||
|
private readonly RectangleF bounds; |
||||
|
|
||||
public ShapeRegionTests() |
public ShapeRegionTests() |
||||
{ |
{ |
||||
this.pathMock = new Mock<IPath>(); |
this.pathMock = new Mock<IPath>(); |
||||
|
|
||||
this.bounds = new RectangleF(10.5f, 10, 10, 10); |
this.bounds = new RectangleF(10.5f, 10, 10, 10); |
||||
pathMock.Setup(x => x.Bounds).Returns(this.bounds); |
this.pathMock.Setup(x => x.Bounds).Returns(this.bounds); |
||||
// wire up the 2 mocks to reference eachother
|
// wire up the 2 mocks to reference eachother
|
||||
pathMock.Setup(x => x.AsClosedPath()).Returns(() => pathMock.Object); |
this.pathMock.Setup(x => x.AsClosedPath()).Returns(() => this.pathMock.Object); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionWithPathCallsAsShape() |
public void ShapeRegionWithPathCallsAsShape() |
||||
{ |
{ |
||||
new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
pathMock.Verify(x => x.AsClosedPath()); |
this.pathMock.Verify(x => x.AsClosedPath()); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionWithPathRetainsShape() |
public void ShapeRegionWithPathRetainsShape() |
||||
{ |
{ |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
Assert.Equal(pathMock.Object, region.Shape); |
Assert.Equal(this.pathMock.Object, region.Shape); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromPathConvertsBoundsProxyToShape() |
public void ShapeRegionFromPathConvertsBoundsProxyToShape() |
||||
{ |
{ |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left); |
Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left); |
||||
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right); |
Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right); |
||||
|
|
||||
pathMock.Verify(x => x.Bounds); |
this.pathMock.Verify(x => x.Bounds); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromPathMaxIntersectionsProxyToShape() |
public void ShapeRegionFromPathMaxIntersectionsProxyToShape() |
||||
{ |
{ |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
int i = region.MaxIntersections; |
int i = region.MaxIntersections; |
||||
pathMock.Verify(x => x.MaxIntersections); |
this.pathMock.Verify(x => x.MaxIntersections); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromPathScanYProxyToShape() |
public void ShapeRegionFromPathScanYProxyToShape() |
||||
{ |
{ |
||||
int yToScan = 10; |
int yToScan = 10; |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
pathMock.Setup(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>())) |
this.pathMock |
||||
.Callback<PointF, PointF, PointF[], int>((s, e, b, o) => { |
.Setup( |
||||
Assert.Equal(yToScan, s.Y); |
x => x.FindIntersections( |
||||
Assert.Equal(yToScan, e.Y); |
It.IsAny<PointF>(), |
||||
Assert.True(s.X < bounds.Left); |
It.IsAny<PointF>(), |
||||
Assert.True(e.X > bounds.Right); |
It.IsAny<PointF[]>(), |
||||
}).Returns(0); |
It.IsAny<int>())).Callback<PointF, PointF, PointF[], int>( |
||||
|
(s, e, b, o) => |
||||
|
{ |
||||
|
Assert.Equal(yToScan, s.Y); |
||||
|
Assert.Equal(yToScan, e.Y); |
||||
|
Assert.True(s.X < this.bounds.Left); |
||||
|
Assert.True(e.X > this.bounds.Right); |
||||
|
}).Returns(0); |
||||
|
|
||||
int i = region.Scan(yToScan, new float[0], 0); |
int i = region.Scan(yToScan, new float[0], 0); |
||||
|
|
||||
pathMock.Verify(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), Times.Once); |
this.pathMock.Verify( |
||||
|
x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), |
||||
|
Times.Once); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromShapeScanYProxyToShape() |
public void ShapeRegionFromShapeScanYProxyToShape() |
||||
{ |
{ |
||||
int yToScan = 10; |
int yToScan = 10; |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
pathMock.Setup(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>())) |
this.pathMock |
||||
.Callback<PointF, PointF, PointF[], int>((s, e, b, o) => { |
.Setup( |
||||
Assert.Equal(yToScan, s.Y); |
x => x.FindIntersections( |
||||
Assert.Equal(yToScan, e.Y); |
It.IsAny<PointF>(), |
||||
Assert.True(s.X < bounds.Left); |
It.IsAny<PointF>(), |
||||
Assert.True(e.X > bounds.Right); |
It.IsAny<PointF[]>(), |
||||
}).Returns(0); |
It.IsAny<int>())).Callback<PointF, PointF, PointF[], int>( |
||||
|
(s, e, b, o) => |
||||
|
{ |
||||
|
Assert.Equal(yToScan, s.Y); |
||||
|
Assert.Equal(yToScan, e.Y); |
||||
|
Assert.True(s.X < this.bounds.Left); |
||||
|
Assert.True(e.X > this.bounds.Right); |
||||
|
}).Returns(0); |
||||
|
|
||||
int i = region.Scan(yToScan, new float[0], 0); |
int i = region.Scan(yToScan, new float[0], 0); |
||||
|
|
||||
pathMock.Verify(x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), Times.Once); |
this.pathMock.Verify( |
||||
|
x => x.FindIntersections(It.IsAny<PointF>(), It.IsAny<PointF>(), It.IsAny<PointF[]>(), It.IsAny<int>()), |
||||
|
Times.Once); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromShapeConvertsBoundsProxyToShape() |
public void ShapeRegionFromShapeConvertsBoundsProxyToShape() |
||||
{ |
{ |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
Assert.Equal(Math.Floor(bounds.Left), region.Bounds.Left); |
Assert.Equal(Math.Floor(this.bounds.Left), region.Bounds.Left); |
||||
Assert.Equal(Math.Ceiling(bounds.Right), region.Bounds.Right); |
Assert.Equal(Math.Ceiling(this.bounds.Right), region.Bounds.Right); |
||||
|
|
||||
pathMock.Verify(x => x.Bounds); |
this.pathMock.Verify(x => x.Bounds); |
||||
} |
} |
||||
|
|
||||
[Fact] |
[Fact] |
||||
public void ShapeRegionFromShapeMaxIntersectionsProxyToShape() |
public void ShapeRegionFromShapeMaxIntersectionsProxyToShape() |
||||
{ |
{ |
||||
ShapeRegion region = new ShapeRegion(Configuration.Default.MemoryManager, pathMock.Object); |
ShapeRegion region = new ShapeRegion(this.pathMock.Object); |
||||
|
|
||||
int i = region.MaxIntersections; |
int i = region.MaxIntersections; |
||||
pathMock.Verify(x => x.MaxIntersections); |
this.pathMock.Verify(x => x.MaxIntersections); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
Loading…
Reference in new issue