Add TransformationMatrix.Transform(double, double)

This commit is contained in:
BobLd
2023-11-03 19:24:02 +00:00
parent 3a96af3dcd
commit 4537ec3f02

View File

@@ -28,7 +28,8 @@
/// <summary>
/// Create a new <see cref="TransformationMatrix"/> with the X and Y scaling values set.
/// </summary>
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.
/// </summary>
public readonly double A;
/// <summary>
/// The value at (0, 1).
/// </summary>
public readonly double B;
/// <summary>
/// The value at (1, 0).
/// </summary>
public readonly double C;
/// <summary>
/// The value at (1, 1) - The scale for the Y dimension.
/// </summary>
public readonly double D;
/// <summary>
/// The value at (2, 0) - translation in X.
/// </summary>
public readonly double E;
/// <summary>
/// The value at (2, 1) - translation in Y.
/// </summary>
@@ -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);
/// <summary>
/// Transform a point using this transformation matrix.
/// </summary>
/// <param name="x">The original point X coordinate.</param>
/// <param name="y">The original point Y coordinate.</param>
/// <returns>A new point which is the result of applying this transformation matrix.</returns>
[Pure]
public (double x, double y) Transform(double x, double y)
{
return (A * x + C * y + E, B * x + D * y + F);
}
/// <summary>
@@ -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);
}