Browse Source

Add Rotate(degrees, origin)

pull/775/head
James Jackson-South 7 years ago
parent
commit
35ff16d5a6
  1. 22
      src/ImageSharp/Processing/AffineTransformBuilder.cs
  2. 34
      src/ImageSharp/Processing/ProjectiveTransformBuilder.cs
  3. 7
      tests/ImageSharp.Tests/Processing/Transforms/AffineTransformBuilderTests.cs
  4. 7
      tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformBuilderTests.cs
  5. 8
      tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs

22
src/ImageSharp/Processing/AffineTransformBuilder.cs

@ -35,7 +35,16 @@ namespace SixLabors.ImageSharp.Processing
=> this.Prepend(size => TransformUtils.CreateRotationMatrixRadians(radians, size));
/// <summary>
/// Prepends a centered rotation matrix using the given rotation in radians.
/// Prepends a rotation matrix using the given rotation in degrees at the given origin.
/// </summary>
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder PrependRotationDegrees(float degrees, Vector2 origin)
=> this.PrependRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
/// <summary>
/// Prepends a rotation matrix using the given rotation in radians at the given origin.
/// </summary>
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="origin">The rotation origin point.</param>
@ -62,7 +71,16 @@ namespace SixLabors.ImageSharp.Processing
=> this.Append(size => TransformUtils.CreateRotationMatrixRadians(radians, size));
/// <summary>
/// Appends a centered rotation matrix using the given rotation in radians.
/// Appends a rotation matrix using the given rotation in degrees at the given origin.
/// </summary>
/// <param name="degrees">The amount of rotation, in degrees.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
public AffineTransformBuilder AppendRotationDegrees(float degrees, Vector2 origin)
=> this.AppendRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
/// <summary>
/// Appends a rotation matrix using the given rotation in radians at the given origin.
/// </summary>
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="origin">The rotation origin point.</param>

34
src/ImageSharp/Processing/ProjectiveTransformBuilder.cs

@ -53,13 +53,22 @@ namespace SixLabors.ImageSharp.Processing
=> this.Prepend(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size)));
/// <summary>
/// Appends a centered rotation matrix using the given rotation in radians.
/// Prepends a centered rotation matrix using the given rotation in degrees at the given origin.
/// </summary>
/// <param name="degrees">The amount of rotation, in radians.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
internal ProjectiveTransformBuilder PrependRotationDegrees(float degrees, Vector2 origin)
=> this.PrependRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
/// <summary>
/// Prepends a centered rotation matrix using the given rotation in radians at the given origin.
/// </summary>
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="centerPoint">The rotation center.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
internal ProjectiveTransformBuilder PrependRotationRadians(float radians, Vector2 centerPoint)
=> this.PrependMatrix(Matrix4x4.CreateRotationZ(radians, new Vector3(centerPoint, 0)));
internal ProjectiveTransformBuilder PrependRotationRadians(float radians, Vector2 origin)
=> this.PrependMatrix(Matrix4x4.CreateRotationZ(radians, new Vector3(origin, 0)));
/// <summary>
/// Appends a centered rotation matrix using the given rotation in degrees.
@ -78,13 +87,22 @@ namespace SixLabors.ImageSharp.Processing
=> this.Append(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size)));
/// <summary>
/// Appends a centered rotation matrix using the given rotation in radians.
/// Appends a centered rotation matrix using the given rotation in degrees at the given origin.
/// </summary>
/// <param name="degrees">The amount of rotation, in radians.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
internal ProjectiveTransformBuilder AppendRotationDegrees(float degrees, Vector2 origin)
=> this.AppendRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
/// <summary>
/// Appends a centered rotation matrix using the given rotation in radians at the given origin.
/// </summary>
/// <param name="radians">The amount of rotation, in radians.</param>
/// <param name="centerPoint">The rotation center.</param>
/// <param name="origin">The rotation origin point.</param>
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
internal ProjectiveTransformBuilder AppendRotationRadians(float radians, Vector2 centerPoint)
=> this.AppendMatrix(Matrix4x4.CreateRotationZ(radians, new Vector3(centerPoint, 0)));
internal ProjectiveTransformBuilder AppendRotationRadians(float radians, Vector2 origin)
=> this.AppendMatrix(Matrix4x4.CreateRotationZ(radians, new Vector3(origin, 0)));
/// <summary>
/// Prepends a scale matrix from the given uniform scale.

7
tests/ImageSharp.Tests/Processing/Transforms/AffineTransformBuilderTests.cs

@ -15,8 +15,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
protected override void AppendRotationRadians(AffineTransformBuilder builder, float radians) => builder.AppendRotationRadians(radians);
protected override void AppendRotationRadians(AffineTransformBuilder builder, float radians, Vector2 center) =>
builder.AppendRotationRadians(radians, center);
protected override void AppendRotationRadians(AffineTransformBuilder builder, float radians, Vector2 origin) => builder.AppendRotationRadians(radians, origin);
protected override void AppendRotationDegrees(AffineTransformBuilder builder, float degrees) => builder.AppendRotationDegrees(degrees);
protected override void AppendRotationDegrees(AffineTransformBuilder builder, float degrees, Vector2 origin) => builder.AppendRotationDegrees(degrees, origin);
protected override void PrependTranslation(AffineTransformBuilder builder, PointF translate) => builder.PrependTranslation(translate);

7
tests/ImageSharp.Tests/Processing/Transforms/ProjectiveTransformBuilderTests.cs

@ -17,8 +17,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
protected override void AppendRotationRadians(ProjectiveTransformBuilder builder, float radians) => builder.AppendRotationRadians(radians);
protected override void AppendRotationRadians(ProjectiveTransformBuilder builder, float radians, Vector2 center) =>
builder.AppendRotationRadians(radians, center);
protected override void AppendRotationRadians(ProjectiveTransformBuilder builder, float radians, Vector2 origin) => builder.AppendRotationRadians(radians, origin);
protected override void AppendRotationDegrees(ProjectiveTransformBuilder builder, float degrees) => builder.AppendRotationDegrees(degrees);
protected override void AppendRotationDegrees(ProjectiveTransformBuilder builder, float degrees, Vector2 origin) => builder.AppendRotationDegrees(degrees, origin);
protected override void PrependTranslation(ProjectiveTransformBuilder builder, PointF translate) => builder.PrependTranslation(translate);

8
tests/ImageSharp.Tests/Processing/Transforms/TransformBuilderTestBase.cs

@ -186,7 +186,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
protected abstract void AppendRotationRadians(TBuilder builder, float radians);
protected abstract void AppendRotationRadians(TBuilder builder, float radians, Vector2 center);
protected abstract void AppendRotationRadians(TBuilder builder, float radians, Vector2 origin);
protected abstract void PrependTranslation(TBuilder builder, PointF translate);
@ -196,11 +196,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Transforms
protected abstract void PrependRotationRadians(TBuilder builder, float radians, Vector2 origin);
protected virtual void AppendRotationDegrees(TBuilder builder, float degrees) =>
this.AppendRotationRadians(builder, GeometryUtilities.DegreeToRadian(degrees));
protected abstract void AppendRotationDegrees(TBuilder builder, float degrees);
protected virtual void AppendRotationDegrees(TBuilder builder, float degrees, Vector2 center) =>
this.AppendRotationRadians(builder, GeometryUtilities.DegreeToRadian(degrees), center);
protected abstract void AppendRotationDegrees(TBuilder builder, float degrees, Vector2 origin);
protected abstract Vector2 Execute(TBuilder builder, Rectangle rectangle, Vector2 sourcePoint);
}

Loading…
Cancel
Save