public void TestStaticFn_TransformNormal_i ()
{
Single one = 1;
Single six = 6;
Single eight = 8;
Single ten = 10;
Single root2; Maths.Root2 (out root2);
Single pi; Maths.Pi (out pi);
Single minusPi = -pi;
Single piOver2 = pi / (Single) 2;
Single oneOverRoot2 = one / root2;
Single sixTenths = six / ten;
Single eightTenths = eight / ten;
Vector2 v1 = new Vector2 (sixTenths, eightTenths);
Vector2 v2 = new Vector2 (oneOverRoot2, oneOverRoot2);
Matrix44 rotmati = Matrix44.Identity;
Matrix44 rotmat1; Matrix44.CreateRotationX(ref pi, out rotmat1);
Matrix44 rotmat2; Matrix44.CreateRotationY(ref piOver2, out rotmat2);
Matrix44 rotmat3; Matrix44.CreateRotationZ(ref minusPi, out rotmat3);
Matrix44 rotmat4 = rotmat1 * rotmat2 * rotmat3;
var tests = new Tuple<Vector2, Matrix44, Vector2>[]
{
//normal -> transform -> expected
new Tuple<Vector2, Matrix44, Vector2>(
v1, rotmati, v1),
new Tuple<Vector2, Matrix44, Vector2>(
v1, rotmat1, new Vector2 (sixTenths, -eightTenths)),
new Tuple<Vector2, Matrix44, Vector2>(
v1, rotmat2, new Vector2 (0, eightTenths)),
new Tuple<Vector2, Matrix44, Vector2>(
v1, rotmat3, new Vector2 (-sixTenths, -eightTenths)),
new Tuple<Vector2, Matrix44, Vector2>(
v1, rotmat4, new Vector2 (0, eightTenths)),
//normal -> transform -> expected
new Tuple<Vector2, Matrix44, Vector2>(
v2, rotmati, v2),
new Tuple<Vector2, Matrix44, Vector2>(
v2, rotmat1, new Vector2 (oneOverRoot2, -oneOverRoot2)),
new Tuple<Vector2, Matrix44, Vector2>(
v2, rotmat2, new Vector2 (0, oneOverRoot2)),
new Tuple<Vector2, Matrix44, Vector2>(
v2, rotmat3, new Vector2 (-oneOverRoot2, -oneOverRoot2)),
new Tuple<Vector2, Matrix44, Vector2>(
v2, rotmat4, new Vector2 (0, oneOverRoot2)),
};
foreach (var test in tests)
{
Vector2 normalVec = test.Item1;
Matrix44 trans = test.Item2;
Vector2 expected = test.Item3;
Vector2 result;
Vector2.TransformNormal (ref normalVec, ref trans, out result);
AssertEqualWithinReason(result, expected);
// should also work with the standard transform fn
Vector2.Transform (ref normalVec, ref trans, out result);
AssertEqualWithinReason(result, expected);
}
}