add test cases for rectangle transforms

our bounding rectangle values still seem to be wrong for rotated letters. this change adds some test cases for common transformation matrix operations on a rectangle, scale, translate and rotate.
This commit is contained in:
Eliot Jones
2020-01-22 13:28:47 +00:00
parent f29170fef8
commit 0ed4e58556
2 changed files with 137 additions and 2 deletions

View File

@@ -22,6 +22,51 @@
public static TransformationMatrix GetTranslationMatrix(double x, double y) => new TransformationMatrix(1, 0, 0,
0, 1, 0,
x, y, 1);
/// <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,
0, scaleY, 0,
0, 0, 1);
/// <summary>
/// Create a new <see cref="TransformationMatrix"/> with the X and Y scaling values set.
/// </summary>
public static TransformationMatrix GetRotationMatrix(double degreesCounterclockwise)
{
double cos;
double sin;
switch (degreesCounterclockwise)
{
case 0:
case 360:
cos = 1;
sin = 0;
break;
case 90:
cos = 0;
sin = 1;
break;
case 180:
cos = -1;
sin = 0;
break;
case 270:
cos = 0;
sin = -1;
break;
default:
cos = Math.Cos(degreesCounterclockwise * (Math.PI / 180));
sin = Math.Sin(degreesCounterclockwise * (Math.PI / 180));
break;
}
return new TransformationMatrix(cos, sin, 0,
-sin, cos, 0,
0, 0, 1);
}
private readonly double row1;
private readonly double row2;