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); }
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); }
public bool Equals(Vector4 other) { return(this.X == other.X && this.Y == other.Y && this.Z == other.Z && this.W == other.W); }
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); }
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); }
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)); }
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)); }
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."); }
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."); }
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}"); } }
public static Vector4 SquareRootJitOptimizeCanaryTest() { var result = VectorTests.Vector4Value; for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++) { result += Vector4.SquareRoot(result); } return(result); }
public static Vector4 AddFunctionTest() { var result = VectorTests.Vector4Value; for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++) { result = Vector4.Add(result, VectorTests.Vector4Delta); } return(result); }
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); }
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); }
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); } }
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); } }
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); } }
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); } }
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))); }
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)); }
/// <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; }
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))); }