mirror of https://github.com/SixLabors/ImageSharp
4 changed files with 181 additions and 42 deletions
@ -0,0 +1,79 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using SixLabors.ImageSharp.Processing; |
||||
|
using SixLabors.Primitives; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Transforms |
||||
|
{ |
||||
|
public class AffineTransformBuilderTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void ConstructorAssignsProperties() |
||||
|
{ |
||||
|
var s = new Size(1, 1); |
||||
|
var builder = new AffineTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
Assert.Equal(s, builder.Size); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void ConstructorThrowsInvalid() |
||||
|
{ |
||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => |
||||
|
{ |
||||
|
var s = new Size(0, 1); |
||||
|
var builder = new AffineTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
}); |
||||
|
|
||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => |
||||
|
{ |
||||
|
var s = new Size(1, 0); |
||||
|
var builder = new AffineTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void AppendPrependOpposite() |
||||
|
{ |
||||
|
var rectangle = new Rectangle(-1, -1, 3, 3); |
||||
|
var b1 = new AffineTransformBuilder(rectangle); |
||||
|
var b2 = new AffineTransformBuilder(rectangle); |
||||
|
|
||||
|
const float pi = (float)Math.PI; |
||||
|
|
||||
|
// Forwards
|
||||
|
b1.AppendRotateMatrixDegrees(pi) |
||||
|
.AppendSkewMatrixDegrees(pi, pi) |
||||
|
.AppendScaleMatrix(new SizeF(pi, pi)) |
||||
|
.AppendTranslationMatrix(new PointF(pi, pi)); |
||||
|
|
||||
|
// Backwards
|
||||
|
b2.PrependTranslationMatrix(new PointF(pi, pi)) |
||||
|
.PrependScaleMatrix(new SizeF(pi, pi)) |
||||
|
.PrependSkewMatrixDegrees(pi, pi) |
||||
|
.PrependRotateMatrixDegrees(pi); |
||||
|
|
||||
|
Assert.Equal(b1.BuildMatrix(), b2.BuildMatrix()); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void BuilderCanClear() |
||||
|
{ |
||||
|
var rectangle = new Rectangle(0, 0, 3, 3); |
||||
|
var builder = new AffineTransformBuilder(rectangle); |
||||
|
Matrix3x2 matrix = Matrix3x2.Identity; |
||||
|
matrix.M31 = (float)Math.PI; |
||||
|
|
||||
|
Assert.Equal(Matrix3x2.Identity, builder.BuildMatrix()); |
||||
|
|
||||
|
builder.AppendMatrix(matrix); |
||||
|
Assert.NotEqual(Matrix3x2.Identity, builder.BuildMatrix()); |
||||
|
|
||||
|
builder.Clear(); |
||||
|
Assert.Equal(Matrix3x2.Identity, builder.BuildMatrix()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
using SixLabors.ImageSharp.Processing; |
||||
|
using SixLabors.Primitives; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Tests.Processing.Transforms |
||||
|
{ |
||||
|
public class ProjectiveTransformBuilderTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void ConstructorAssignsProperties() |
||||
|
{ |
||||
|
var s = new Size(1, 1); |
||||
|
var builder = new ProjectiveTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
Assert.Equal(s, builder.Size); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void ConstructorThrowsInvalid() |
||||
|
{ |
||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => |
||||
|
{ |
||||
|
var s = new Size(0, 1); |
||||
|
var builder = new ProjectiveTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
}); |
||||
|
|
||||
|
Assert.Throws<ArgumentOutOfRangeException>(() => |
||||
|
{ |
||||
|
var s = new Size(1, 0); |
||||
|
var builder = new ProjectiveTransformBuilder(new Rectangle(Point.Empty, s)); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void AppendPrependOpposite() |
||||
|
{ |
||||
|
var rectangle = new Rectangle(-1, -1, 3, 3); |
||||
|
var b1 = new ProjectiveTransformBuilder(rectangle); |
||||
|
var b2 = new ProjectiveTransformBuilder(rectangle); |
||||
|
|
||||
|
const float pi = (float)Math.PI; |
||||
|
|
||||
|
Matrix4x4 m4 = Matrix4x4.Identity; |
||||
|
m4.M31 = pi; |
||||
|
|
||||
|
// Forwards
|
||||
|
b1.AppendMatrix(m4) |
||||
|
.AppendTaperMatrix(TaperSide.Left, TaperCorner.LeftOrTop, pi); |
||||
|
|
||||
|
// Backwards
|
||||
|
b2.PrependTaperMatrix(TaperSide.Left, TaperCorner.LeftOrTop, pi) |
||||
|
.PrependMatrix(m4); |
||||
|
|
||||
|
Assert.Equal(b1.BuildMatrix(), b2.BuildMatrix()); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void BuilderCanClear() |
||||
|
{ |
||||
|
var rectangle = new Rectangle(0, 0, 3, 3); |
||||
|
var builder = new ProjectiveTransformBuilder(rectangle); |
||||
|
Matrix4x4 matrix = Matrix4x4.Identity; |
||||
|
matrix.M31 = (float)Math.PI; |
||||
|
|
||||
|
Assert.Equal(Matrix4x4.Identity, builder.BuildMatrix()); |
||||
|
|
||||
|
builder.AppendMatrix(matrix); |
||||
|
Assert.NotEqual(Matrix4x4.Identity, builder.BuildMatrix()); |
||||
|
|
||||
|
builder.Clear(); |
||||
|
Assert.Equal(Matrix4x4.Identity, builder.BuildMatrix()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue