Abacus.DoublePrecision.Vector2Tests.TestStaticFn_TransformNormal_i C# (CSharp) Method

TestStaticFn_TransformNormal_i() private method

private TestStaticFn_TransformNormal_i ( ) : void
return void
        public void TestStaticFn_TransformNormal_i ()
        {
            Double one = 1;
            Double six = 6;
            Double eight = 8;
            Double ten = 10;
            Double root2; Maths.Root2 (out root2);
            Double pi; Maths.Pi (out pi);
            Double minusPi = -pi;
            Double piOver2 = pi / (Double) 2;
            Double oneOverRoot2 = one / root2;
            Double sixTenths = six / ten;
            Double 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);
            }
        }
Vector2Tests