Example #1
0
 public static Single Dot(Vector4 vector1, Vector4 vector2)
 {
     return(vector1.X * vector2.X +
            vector1.Y * vector2.Y +
            vector1.Z * vector2.Z +
            vector1.W * vector2.W);
 }
Example #2
0
 public static Single Dot(Plane plane, Vector4 value)
 {
     return(plane.Normal.X * value.X +
            plane.Normal.Y * value.Y +
            plane.Normal.Z * value.Z +
            plane.D * value.W);
 }
Example #3
0
 public bool Equals(Vector4 other)
 {
     return(this.X == other.X &&
            this.Y == other.Y &&
            this.Z == other.Z &&
            this.W == other.W);
 }
Example #4
0
        public void Matrix3x2EqualsTest()
        {
            Matrix3x2 a = GenerateMatrixNumberFrom1To6();
            Matrix3x2 b = GenerateMatrixNumberFrom1To6();

            // case 1: compare between same values
            object obj = b;

            bool expected = true;
            bool actual   = a.Equals(obj);

            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.M11    = 11.0f;
            obj      = b;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare between different types.
            obj      = new Vector4();
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare against null.
            obj      = null;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);
        }
Example #5
0
        public void QuaternionEqualsTest()
        {
            Quaternion a = new Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
            Quaternion b = new Quaternion(1.0f, 2.0f, 3.0f, 4.0f);

            // case 1: compare between same values
            object obj = b;

            bool expected = true;
            bool actual   = a.Equals(obj);

            Assert.Equal(expected, actual);

            // case 2: compare between different values
            b.X      = 10.0f;
            obj      = b;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare between different types.
            obj      = new Vector4();
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);

            // case 3: compare against null.
            obj      = null;
            expected = false;
            actual   = a.Equals(obj);
            Assert.Equal(expected, actual);
        }
Example #6
0
 public static Vector4 Max(Vector4 value1, Vector4 value2)
 {
     return(new Vector4(
                (value1.X > value2.X) ? value1.X : value2.X,
                (value1.Y > value2.Y) ? value1.Y : value2.Y,
                (value1.Z > value2.Z) ? value1.Z : value2.Z,
                (value1.W > value2.W) ? value1.W : value2.W));
 }
Example #7
0
 public static Vector4 Min(Vector4 value1, Vector4 value2)
 {
     return(new Vector4(
                (value1.X < value2.X) ? value1.X : value2.X,
                (value1.Y < value2.Y) ? value1.Y : value2.Y,
                (value1.Z < value2.Z) ? value1.Z : value2.Z,
                (value1.W < value2.W) ? value1.W : value2.W));
 }
Example #8
0
        public void PlaneConstructorTest()
        {
            Vector4 value  = new Vector4(1.0f, 2.0f, 3.0f, 4.0f);
            Plane   target = new Plane(value);

            Assert.True(
                target.Normal.X == value.X && target.Normal.Y == value.Y && target.Normal.Z == value.Z && target.D == value.W,
                "Plane.cstor did not return the expected value.");
        }
Example #9
0
        public void PlaneDotTest()
        {
            Plane   target = new Plane(2, 3, 4, 5);
            Vector4 value  = new Vector4(5, 4, 3, 2);

            Single expected = 10 + 12 + 12 + 10;
            Single actual   = Plane.Dot(target, value);

            Assert.True(MathHelper.Equal(expected, actual), "Plane.Dot returns unexpected value.");
        }
Example #10
0
 public static void AssertEqual(Vector4 expectedResult, Vector4 actualResult)
 {
     if (!SingleAreEqual(expectedResult.X, actualResult.X) ||
         !SingleAreEqual(expectedResult.Y, actualResult.Y) ||
         !SingleAreEqual(expectedResult.Z, actualResult.Z) ||
         !SingleAreEqual(expectedResult.W, actualResult.W))
     {
         throw new Exception($"Expected Result: {expectedResult:g9}; Actual Result: {actualResult:g9}");
     }
 }
Example #11
0
        public static Vector4 SquareRootJitOptimizeCanaryTest()
        {
            var result = VectorTests.Vector4Value;

            for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++)
            {
                result += Vector4.SquareRoot(result);
            }

            return(result);
        }
Example #12
0
        public static Vector4 AddFunctionTest()
        {
            var result = VectorTests.Vector4Value;

            for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++)
            {
                result = Vector4.Add(result, VectorTests.Vector4Delta);
            }

            return(result);
        }
Example #13
0
        public static Single DistanceSquaredJitOptimizeCanaryTest()
        {
            Single result = 0.0f;
            var    value  = VectorTests.Vector4Value;

            for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++)
            {
                value  += VectorTests.Vector4Delta;
                result += Vector4.DistanceSquared(value, VectorTests.Vector4ValueInverted);
            }

            return(result);
        }
Example #14
0
        public static Single DistanceSquaredTest()
        {
            Single result = 0.0f;

            for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++)
            {
                // The inputs aren't being changed and the output is being reset with each iteration, so a future
                // optimization could potentially throw away everything except for the final call. This would break
                // the perf test. The JitOptimizeCanary code below does modify the inputs and consume each output.
                result = Vector4.DistanceSquared(VectorTests.Vector4Value, VectorTests.Vector4ValueInverted);
            }

            return(result);
        }
Example #15
0
        public static void SquareRootBenchmark()
        {
            var expectedResult = new Vector4(Single.NaN, 1.0f, Single.NaN, 1.0f);

            foreach (var iteration in Benchmark.Iterations)
            {
                Vector4 actualResult;

                using (iteration.StartMeasurement())
                {
                    actualResult = SquareRootTest();
                }

                VectorTests.AssertEqual(expectedResult, actualResult);
            }
        }
Example #16
0
        public static void NormalizeJitOptimizeCanaryBenchmark()
        {
            var expectedResult = new Vector4(-8388608.0f, 8388608.0f, -8388608.0f, 8388608.0f);

            foreach (var iteration in Benchmark.Iterations)
            {
                Vector4 actualResult;

                using (iteration.StartMeasurement())
                {
                    actualResult = NormalizeJitOptimizeCanaryTest();
                }

                VectorTests.AssertEqual(expectedResult, actualResult);
            }
        }
Example #17
0
        public static void SquareRootJitOptimizeCanaryBenchmark()
        {
            var expectedResult = new Vector4(Single.NaN, 2.81474977e+14f, Single.NaN, 2.81474977e+14f);

            foreach (var iteration in Benchmark.Iterations)
            {
                Vector4 actualResult;

                using (iteration.StartMeasurement())
                {
                    actualResult = SquareRootJitOptimizeCanaryTest();
                }

                VectorTests.AssertEqual(expectedResult, actualResult);
            }
        }
Example #18
0
        public static void NormalizeBenchmark()
        {
            var expectedResult = new Vector4(-0.5f, 0.5f, -0.5f, 0.5f);

            foreach (var iteration in Benchmark.Iterations)
            {
                Vector4 actualResult;

                using (iteration.StartMeasurement())
                {
                    actualResult = NormalizeTest();
                }

                VectorTests.AssertEqual(expectedResult, actualResult);
            }
        }
Example #19
0
 public static Vector4 SquareRoot(Vector4 value)
 {
     return(new Vector4(MathF.Sqrt(value.X), MathF.Sqrt(value.Y), MathF.Sqrt(value.Z), MathF.Sqrt(value.W)));
 }
Example #20
0
 public static bool Equal(Vector4 a, Vector4 b)
 {
     return(Equal(a.X, b.X) && Equal(a.Y, b.Y) && Equal(a.Z, b.Z) && Equal(a.W, b.W));
 }
Example #21
0
 /// <summary>
 /// Constructs a Plane from the given Vector4.
 /// </summary>
 /// <param name="value">A vector whose first 3 elements describe the normal vector,
 /// and whose W component defines the distance along that normal from the origin.</param>
 public Fix64Plane(Vector4 value)
 {
     Normal = new Vector3(value.X, value.Y, value.Z);
     D      = value.W;
 }
Example #22
0
 public static Vector4 Abs(Vector4 value)
 {
     return(new Vector4(MathF.Abs(value.X), MathF.Abs(value.Y), MathF.Abs(value.Z), MathF.Abs(value.W)));
 }