Abacus.DoublePrecision.Vector3Tests.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 root3; Maths.Root3 (out root3);
            Double pi; Maths.Pi (out pi);
            Double minusPi = -pi;
            Double piOver2 = pi / (Double) 2;
            Double oneOverRoot3 = one / root3;
            Double sixTenths = six / ten;
            Double eightTenths = eight / ten;

            // todo: find a set of 3 fraction that make up a 3D unit vector
            //       for now just use the 2D one
            Vector3 v1 = new Vector3 (sixTenths, 0, eightTenths);
            Vector3 v2 = new Vector3 (oneOverRoot3, oneOverRoot3, oneOverRoot3);

            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<Vector3, Matrix44, Vector3>[]
            {
                //normal -> transform -> expected
                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmati, v1),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat1, new Vector3 (sixTenths, 0, -eightTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat2, new Vector3 (eightTenths, 0, -sixTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat3, new Vector3 (-sixTenths, 0, eightTenths)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v1, rotmat4, new Vector3 (eightTenths, 0, -sixTenths)),

                //normal -> transform -> expected
                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmati, v2),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat1, new Vector3 (oneOverRoot3, -oneOverRoot3, -oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat2, new Vector3 (oneOverRoot3, oneOverRoot3, -oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat3, new Vector3 (-oneOverRoot3, -oneOverRoot3, oneOverRoot3)),

                new Tuple<Vector3, Matrix44, Vector3>(
                    v2, rotmat4, new Vector3 (oneOverRoot3, oneOverRoot3, -oneOverRoot3)),
            };

            for (Int32 i = 0; i < tests.Length; ++i)
            {
                var test = tests [i];
                Vector3 normalVec = test.Item1;
                Matrix44 trans = test.Item2;
                Vector3 expected = test.Item3;

                Vector3 result;

                Vector3.TransformNormal (ref normalVec, ref trans, out result);
                AssertEqualWithinReason(result, expected);

                // should also work with the standard transform fn
                Vector3.Transform (ref normalVec, ref trans, out result);
                AssertEqualWithinReason(result, expected);
            }
        }
Vector3Tests