diff --git a/src/UglyToad.PdfPig.Core/TransformationMatrix.cs b/src/UglyToad.PdfPig.Core/TransformationMatrix.cs index d77c5904..c8e1778f 100644 --- a/src/UglyToad.PdfPig.Core/TransformationMatrix.cs +++ b/src/UglyToad.PdfPig.Core/TransformationMatrix.cs @@ -28,7 +28,8 @@ /// /// Create a new with the X and Y scaling values set. /// - public static TransformationMatrix GetScaleMatrix(double scaleX, double scaleY) => new TransformationMatrix(scaleX, 0, 0, + public static TransformationMatrix GetScaleMatrix(double scaleX, double scaleY) => new TransformationMatrix( + scaleX, 0, 0, 0, scaleY, 0, 0, 0, 1); @@ -84,22 +85,27 @@ /// The value at (0, 0) - The scale for the X dimension. /// public readonly double A; + /// /// The value at (0, 1). /// public readonly double B; + /// /// The value at (1, 0). /// public readonly double C; + /// /// The value at (1, 1) - The scale for the Y dimension. /// public readonly double D; + /// /// The value at (2, 0) - translation in X. /// public readonly double E; + /// /// The value at (2, 1) - translation in Y. /// @@ -223,10 +229,20 @@ [Pure] public PdfPoint Transform(PdfPoint original) { - var x = A * original.X + C * original.Y + E; - var y = B * original.X + D * original.Y + F; + (double x, double y) xy = Transform(original.X, original.Y); + return new PdfPoint(xy.x, xy.y); + } - return new PdfPoint(x, y); + /// + /// Transform a point using this transformation matrix. + /// + /// The original point X coordinate. + /// The original point Y coordinate. + /// A new point which is the result of applying this transformation matrix. + [Pure] + public (double x, double y) Transform(double x, double y) + { + return (A * x + C * y + E, B * x + D * y + F); } /// @@ -404,7 +420,7 @@ var r3 = (E * matrix.row1) + (F * matrix.row2) + (row3 * matrix.row3); return new TransformationMatrix(a, b, r1, - c, d, r2, + c, d, r2, e, f, r3); }