Skip to content

Commit 7b7a606

Browse files
Moar Utils
1 parent d6b38c1 commit 7b7a606

8 files changed

Lines changed: 25 additions & 25 deletions

File tree

src/ImageSharp/Processing/AffineTransformBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public AffineTransformBuilder PrependRotationDegrees(float degrees)
3131
/// <param name="radians">The amount of rotation, in radians.</param>
3232
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
3333
public AffineTransformBuilder PrependRotationRadians(float radians)
34-
=> this.Prepend(size => TransformUtilities.CreateRotationMatrixRadians(radians, size));
34+
=> this.Prepend(size => TransformUtils.CreateRotationMatrixRadians(radians, size));
3535

3636
/// <summary>
3737
/// Prepends a rotation matrix using the given rotation in degrees at the given origin.
@@ -67,7 +67,7 @@ public AffineTransformBuilder AppendRotationDegrees(float degrees)
6767
/// <param name="radians">The amount of rotation, in radians.</param>
6868
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
6969
public AffineTransformBuilder AppendRotationRadians(float radians)
70-
=> this.Append(size => TransformUtilities.CreateRotationMatrixRadians(radians, size));
70+
=> this.Append(size => TransformUtils.CreateRotationMatrixRadians(radians, size));
7171

7272
/// <summary>
7373
/// Appends a rotation matrix using the given rotation in degrees at the given origin.
@@ -142,7 +142,7 @@ public AffineTransformBuilder AppendScale(Vector2 scales)
142142
/// <param name="degreesY">The Y angle, in degrees.</param>
143143
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
144144
public AffineTransformBuilder PrependSkewDegrees(float degreesX, float degreesY)
145-
=> this.Prepend(size => TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size));
145+
=> this.Prepend(size => TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size));
146146

147147
/// <summary>
148148
/// Prepends a centered skew matrix from the give angles in radians.
@@ -151,7 +151,7 @@ public AffineTransformBuilder PrependSkewDegrees(float degreesX, float degreesY)
151151
/// <param name="radiansY">The Y angle, in radians.</param>
152152
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
153153
public AffineTransformBuilder PrependSkewRadians(float radiansX, float radiansY)
154-
=> this.Prepend(size => TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size));
154+
=> this.Prepend(size => TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size));
155155

156156
/// <summary>
157157
/// Prepends a skew matrix using the given angles in degrees at the given origin.
@@ -180,7 +180,7 @@ public AffineTransformBuilder PrependSkewRadians(float radiansX, float radiansY,
180180
/// <param name="degreesY">The Y angle, in degrees.</param>
181181
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
182182
public AffineTransformBuilder AppendSkewDegrees(float degreesX, float degreesY)
183-
=> this.Append(size => TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size));
183+
=> this.Append(size => TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size));
184184

185185
/// <summary>
186186
/// Appends a centered skew matrix from the give angles in radians.
@@ -189,7 +189,7 @@ public AffineTransformBuilder AppendSkewDegrees(float degreesX, float degreesY)
189189
/// <param name="radiansY">The Y angle, in radians.</param>
190190
/// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
191191
public AffineTransformBuilder AppendSkewRadians(float radiansX, float radiansY)
192-
=> this.Append(size => TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size));
192+
=> this.Append(size => TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size));
193193

194194
/// <summary>
195195
/// Appends a skew matrix using the given angles in degrees at the given origin.
@@ -314,7 +314,7 @@ public Matrix3x2 BuildMatrix(Rectangle sourceRectangle)
314314

315315
private static void CheckDegenerate(Matrix3x2 matrix)
316316
{
317-
if (TransformUtilities.IsDegenerate(matrix))
317+
if (TransformUtils.IsDegenerate(matrix))
318318
{
319319
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
320320
}

src/ImageSharp/Processing/Extensions/Transforms/TransformExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static IImageProcessingContext Transform(
5252
IResampler sampler)
5353
{
5454
Matrix3x2 transform = builder.BuildMatrix(sourceRectangle);
55-
Size targetDimensions = TransformUtilities.GetTransformedSize(sourceRectangle.Size, transform);
55+
Size targetDimensions = TransformUtils.GetTransformedSize(sourceRectangle.Size, transform);
5656
return ctx.Transform(sourceRectangle, transform, targetDimensions, sampler);
5757
}
5858

@@ -116,7 +116,7 @@ public static IImageProcessingContext Transform(
116116
IResampler sampler)
117117
{
118118
Matrix4x4 transform = builder.BuildMatrix(sourceRectangle);
119-
Size targetDimensions = TransformUtilities.GetTransformedSize(sourceRectangle.Size, transform);
119+
Size targetDimensions = TransformUtils.GetTransformedSize(sourceRectangle.Size, transform);
120120
return ctx.Transform(sourceRectangle, transform, targetDimensions, sampler);
121121
}
122122

src/ImageSharp/Processing/Processors/Transforms/Linear/ProjectiveTransformProcessor{TPixel}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void Invoke(int y)
139139

140140
for (int x = 0; x < this.maxX; x++)
141141
{
142-
Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix);
142+
Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, this.matrix);
143143
int px = (int)MathF.Round(point.X);
144144
int py = (int)MathF.Round(point.Y);
145145

@@ -206,7 +206,7 @@ public void Invoke(int y, Span<Vector4> span)
206206
{
207207
// Use the single precision position to calculate correct bounding pixels
208208
// otherwise we get rogue pixels outside of the bounds.
209-
Vector2 point = TransformUtilities.ProjectiveTransform2D(x, y, this.matrix);
209+
Vector2 point = TransformUtils.ProjectiveTransform2D(x, y, this.matrix);
210210
LinearTransformUtils.Convolve(
211211
in this.sampler,
212212
point,

src/ImageSharp/Processing/Processors/Transforms/Linear/RotateProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public RotateProcessor(float degrees, Size sourceSize)
2828
/// <param name="sourceSize">The source image size</param>
2929
public RotateProcessor(float degrees, IResampler sampler, Size sourceSize)
3030
: this(
31-
TransformUtilities.CreateRotationMatrixDegrees(degrees, sourceSize),
31+
TransformUtils.CreateRotationMatrixDegrees(degrees, sourceSize),
3232
sampler,
3333
sourceSize)
3434
=> this.Degrees = degrees;
3535

3636
// Helper constructor
3737
private RotateProcessor(Matrix3x2 rotationMatrix, IResampler sampler, Size sourceSize)
38-
: base(rotationMatrix, sampler, TransformUtilities.GetTransformedSize(sourceSize, rotationMatrix))
38+
: base(rotationMatrix, sampler, TransformUtils.GetTransformedSize(sourceSize, rotationMatrix))
3939
{
4040
}
4141

src/ImageSharp/Processing/Processors/Transforms/Linear/SkewProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public SkewProcessor(float degreesX, float degreesY, Size sourceSize)
3030
/// <param name="sourceSize">The source image size</param>
3131
public SkewProcessor(float degreesX, float degreesY, IResampler sampler, Size sourceSize)
3232
: this(
33-
TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize),
33+
TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, sourceSize),
3434
sampler,
3535
sourceSize)
3636
{
@@ -40,7 +40,7 @@ public SkewProcessor(float degreesX, float degreesY, IResampler sampler, Size so
4040

4141
// Helper constructor:
4242
private SkewProcessor(Matrix3x2 skewMatrix, IResampler sampler, Size sourceSize)
43-
: base(skewMatrix, sampler, TransformUtilities.GetTransformedSize(sourceSize, skewMatrix))
43+
: base(skewMatrix, sampler, TransformUtils.GetTransformedSize(sourceSize, skewMatrix))
4444
{
4545
}
4646

src/ImageSharp/Processing/Processors/Transforms/TransformUtilities.cs renamed to src/ImageSharp/Processing/Processors/Transforms/TransformUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
1010
/// <summary>
1111
/// Contains utility methods for working with transforms.
1212
/// </summary>
13-
internal static class TransformUtilities
13+
internal static class TransformUtils
1414
{
1515
/// <summary>
1616
/// Returns a value that indicates whether the specified matrix is degenerate

src/ImageSharp/Processing/ProjectiveTransformBuilder.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ProjectiveTransformBuilder
2424
/// <param name="fraction">The amount to taper.</param>
2525
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
2626
public ProjectiveTransformBuilder PrependTaper(TaperSide side, TaperCorner corner, float fraction)
27-
=> this.Prepend(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction));
27+
=> this.Prepend(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction));
2828

2929
/// <summary>
3030
/// Appends a matrix that performs a tapering projective transform.
@@ -34,7 +34,7 @@ public ProjectiveTransformBuilder PrependTaper(TaperSide side, TaperCorner corne
3434
/// <param name="fraction">The amount to taper.</param>
3535
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
3636
public ProjectiveTransformBuilder AppendTaper(TaperSide side, TaperCorner corner, float fraction)
37-
=> this.Append(size => TransformUtilities.CreateTaperMatrix(size, side, corner, fraction));
37+
=> this.Append(size => TransformUtils.CreateTaperMatrix(size, side, corner, fraction));
3838

3939
/// <summary>
4040
/// Prepends a centered rotation matrix using the given rotation in degrees.
@@ -50,7 +50,7 @@ public ProjectiveTransformBuilder PrependRotationDegrees(float degrees)
5050
/// <param name="radians">The amount of rotation, in radians.</param>
5151
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
5252
public ProjectiveTransformBuilder PrependRotationRadians(float radians)
53-
=> this.Prepend(size => new Matrix4x4(TransformUtilities.CreateRotationMatrixRadians(radians, size)));
53+
=> this.Prepend(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size)));
5454

5555
/// <summary>
5656
/// Prepends a centered rotation matrix using the given rotation in degrees at the given origin.
@@ -84,7 +84,7 @@ public ProjectiveTransformBuilder AppendRotationDegrees(float degrees)
8484
/// <param name="radians">The amount of rotation, in radians.</param>
8585
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
8686
public ProjectiveTransformBuilder AppendRotationRadians(float radians)
87-
=> this.Append(size => new Matrix4x4(TransformUtilities.CreateRotationMatrixRadians(radians, size)));
87+
=> this.Append(size => new Matrix4x4(TransformUtils.CreateRotationMatrixRadians(radians, size)));
8888

8989
/// <summary>
9090
/// Appends a centered rotation matrix using the given rotation in degrees at the given origin.
@@ -168,7 +168,7 @@ internal ProjectiveTransformBuilder PrependSkewDegrees(float degreesX, float deg
168168
/// <param name="radiansY">The Y angle, in radians.</param>
169169
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
170170
public ProjectiveTransformBuilder PrependSkewRadians(float radiansX, float radiansY)
171-
=> this.Prepend(size => new Matrix4x4(TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size)));
171+
=> this.Prepend(size => new Matrix4x4(TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size)));
172172

173173
/// <summary>
174174
/// Prepends a skew matrix using the given angles in degrees at the given origin.
@@ -206,7 +206,7 @@ internal ProjectiveTransformBuilder AppendSkewDegrees(float degreesX, float degr
206206
/// <param name="radiansY">The Y angle, in radians.</param>
207207
/// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
208208
public ProjectiveTransformBuilder AppendSkewRadians(float radiansX, float radiansY)
209-
=> this.Append(size => new Matrix4x4(TransformUtilities.CreateSkewMatrixRadians(radiansX, radiansY, size)));
209+
=> this.Append(size => new Matrix4x4(TransformUtils.CreateSkewMatrixRadians(radiansX, radiansY, size)));
210210

211211
/// <summary>
212212
/// Appends a skew matrix using the given angles in degrees at the given origin.
@@ -332,7 +332,7 @@ public Matrix4x4 BuildMatrix(Rectangle sourceRectangle)
332332

333333
private static void CheckDegenerate(Matrix4x4 matrix)
334334
{
335-
if (TransformUtilities.IsDegenerate(matrix))
335+
if (TransformUtils.IsDegenerate(matrix))
336336
{
337337
throw new DegenerateTransformException("Matrix is degenerate. Check input values.");
338338
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void AppendRotationDegrees_WithoutSpecificRotationCenter_RotationIsCenter
9999
this.AppendRotationDegrees(builder, degrees);
100100

101101
// TODO: We should also test CreateRotationMatrixDegrees() (and all TransformUtils stuff!) for correctness
102-
Matrix3x2 matrix = TransformUtilities.CreateRotationMatrixDegrees(degrees, size);
102+
Matrix3x2 matrix = TransformUtils.CreateRotationMatrixDegrees(degrees, size);
103103

104104
var position = new Vector2(x, y);
105105
var expected = Vector2.Transform(position, matrix);
@@ -153,7 +153,7 @@ public void AppendSkewDegrees_WithoutSpecificSkewCenter_SkewIsCenteredAroundImag
153153

154154
this.AppendSkewDegrees(builder, degreesX, degreesY);
155155

156-
Matrix3x2 matrix = TransformUtilities.CreateSkewMatrixDegrees(degreesX, degreesY, size);
156+
Matrix3x2 matrix = TransformUtils.CreateSkewMatrixDegrees(degreesX, degreesY, size);
157157

158158
var position = new Vector2(x, y);
159159
var expected = Vector2.Transform(position, matrix);

0 commit comments

Comments
 (0)