public void Vector3ToStringTest() { string separator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; CultureInfo enUsCultureInfo = new CultureInfo("en-US"); Vector3 v1 = new Vector3(2.0f, 3.0f, 3.3f); string v1str = v1.ToString(); string expectedv1 = string.Format(CultureInfo.CurrentCulture , "<{1:G}{0} {2:G}{0} {3:G}>" , separator, 2, 3, 3.3); Assert.Equal(expectedv1, v1str); string v1strformatted = v1.ToString("c", CultureInfo.CurrentCulture); string expectedv1formatted = string.Format(CultureInfo.CurrentCulture , "<{1:c}{0} {2:c}{0} {3:c}>" , separator, 2, 3, 3.3); Assert.Equal(expectedv1formatted, v1strformatted); string v2strformatted = v1.ToString("c", enUsCultureInfo); string expectedv2formatted = string.Format(enUsCultureInfo , "<{1:c}{0} {2:c}{0} {3:c}>" , enUsCultureInfo.NumberFormat.NumberGroupSeparator, 2, 3, 3.3); Assert.Equal(expectedv2formatted, v2strformatted); string v3strformatted = v1.ToString("c"); string expectedv3formatted = string.Format(CultureInfo.CurrentCulture , "<{1:c}{0} {2:c}{0} {3:c}>" , separator, 2, 3, 3.3); Assert.Equal(expectedv3formatted, v3strformatted); }
public void Vector3GetHashCodeTest() { Vector3 v1 = new Vector3(2.0f, 3.0f, 3.3f); Vector3 v2 = new Vector3(2.0f, 3.0f, 3.3f); Vector3 v3 = new Vector3(2.0f, 3.0f, 3.3f); Vector3 v5 = new Vector3(3.0f, 2.0f, 3.3f); Assert.Equal(v1.GetHashCode(), v1.GetHashCode()); Assert.Equal(v1.GetHashCode(), v2.GetHashCode()); Assert.NotEqual(v1.GetHashCode(), v5.GetHashCode()); Assert.Equal(v1.GetHashCode(), v3.GetHashCode()); Vector3 v4 = new Vector3(0.0f, 0.0f, 0.0f); Vector3 v6 = new Vector3(1.0f, 0.0f, 0.0f); Vector3 v7 = new Vector3(0.0f, 1.0f, 0.0f); Vector3 v8 = new Vector3(1.0f, 1.0f, 1.0f); Vector3 v9 = new Vector3(1.0f, 1.0f, 0.0f); Assert.NotEqual(v4.GetHashCode(), v6.GetHashCode()); Assert.NotEqual(v4.GetHashCode(), v7.GetHashCode()); Assert.NotEqual(v4.GetHashCode(), v8.GetHashCode()); Assert.NotEqual(v7.GetHashCode(), v6.GetHashCode()); Assert.NotEqual(v8.GetHashCode(), v6.GetHashCode()); Assert.NotEqual(v8.GetHashCode(), v9.GetHashCode()); Assert.NotEqual(v7.GetHashCode(), v9.GetHashCode()); }
public void SetFieldsTest() { Vector3 v3 = new Vector3(4f, 5f, 6f); v3.X = 1.0f; v3.Y = 2.0f; v3.Z = 3.0f; Assert.Equal(1.0f, v3.X); Assert.Equal(2.0f, v3.Y); Assert.Equal(3.0f, v3.Z); Vector3 v4 = v3; v4.Y = 0.5f; v4.Z = 2.2f; Assert.Equal(1.0f, v4.X); Assert.Equal(0.5f, v4.Y); Assert.Equal(2.2f, v4.Z); Assert.Equal(2.0f, v3.Y); Vector3 before = new Vector3(1f, 2f, 3f); Vector3 after = before; after.X = 500.0f; Assert.NotEqual(before, after); }
public void Vector3EqualsTest() { Vector3 a = new Vector3(1.0f, 2.0f, 3.0f); Vector3 b = new Vector3(1.0f, 2.0f, 3.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 Quaternion(); 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); }
/// <summary> /// Constructs a Quaternion from the given vector and rotation parts. /// </summary> /// <param name="vectorPart">The vector part of the Quaternion.</param> /// <param name="scalarPart">The rotation part of the Quaternion.</param> public Fix64Quaternion(Vector3 vectorPart, Single scalarPart) { X = vectorPart.X; Y = vectorPart.Y; Z = vectorPart.Z; W = scalarPart; }
public static Vector3 Min(Vector3 value1, Vector3 value2) { return(new Vector3( (value1.X < value2.X) ? value1.X : value2.X, (value1.Y < value2.Y) ? value1.Y : value2.Y, (value1.Z < value2.Z) ? value1.Z : value2.Z)); }
public Fix64Vector4(Vector3 value, Single w) { X = value.X; Y = value.Y; Z = value.Z; W = w; }
public static Vector3 Max(Vector3 value1, Vector3 value2) { return(new Vector3( (value1.X > value2.X) ? value1.X : value2.X, (value1.Y > value2.Y) ? value1.Y : value2.Y, (value1.Z > value2.Z) ? value1.Z : value2.Z)); }
public void Vector3ConstructorTest3() { Vector3 a = new Vector3(); Assert.Equal(0.0f, a.X); Assert.Equal(0.0f, a.Y); Assert.Equal(0.0f, a.Z); }
public void Vector3ConstructorTest4() { Vector3 target = new Vector3(Single.NaN, Single.MaxValue, Single.PositiveInfinity); Assert.True(Single.IsNaN(target.X), "Vector3f.constructor (Vector3f) did not return the expected value."); Assert.True(Single.Equals(Single.MaxValue, target.Y), "Vector3f.constructor (Vector3f) did not return the expected value."); Assert.True(Single.IsPositiveInfinity(target.Z), "Vector3f.constructor (Vector3f) did not return the expected value."); }
public static Vector4 Transform(Vector3 position, Matrix4x4 matrix) { return(new Vector4( position.X * matrix.M11 + position.Y * matrix.M21 + position.Z * matrix.M31 + matrix.M41, position.X * matrix.M12 + position.Y * matrix.M22 + position.Z * matrix.M32 + matrix.M42, position.X * matrix.M13 + position.Y * matrix.M23 + position.Z * matrix.M33 + matrix.M43, position.X * matrix.M14 + position.Y * matrix.M24 + position.Z * matrix.M34 + matrix.M44)); }
public void Vector3NormalizeTest1() { Vector3 a = new Vector3(1.0f, 0.0f, 0.0f); Vector3 expected = new Vector3(1.0f, 0.0f, 0.0f); Vector3 actual = Vector3.Normalize(a); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Normalize did not return the expected value."); }
public void Vector3LengthTest1() { Vector3 target = new Vector3(); Single expected = 0.0f; Single actual = target.Length(); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Length did not return the expected value."); }
public static void Vector3MultiplyTest2() { Vector3 a = new Vector3(1.0f, 2.0f, 3.0f); Single factor = 2.0f; Vector3 expected = new Vector3(2.0f, 4.0f, 6.0f); Vector3 actual = Vector3.Multiply(factor, a); Assert.Equal(expected, actual); }
public static void AssertEqual(Vector3 expectedResult, Vector3 actualResult) { if (!SingleAreEqual(expectedResult.X, actualResult.X) || !SingleAreEqual(expectedResult.Y, actualResult.Y) || !SingleAreEqual(expectedResult.Z, actualResult.Z)) { throw new Exception($"Expected Result: {expectedResult:g9}; Actual Result: {actualResult:g9}"); } }
public void Vector3NormalizeTest2() { Vector3 a = new Vector3(0.0f, 0.0f, 0.0f); Vector3 expected = new Vector3(0.0f, 0.0f, 0.0f); Vector3 actual = Vector3.Normalize(a); Assert.True(Single.IsNaN(actual.X) && Single.IsNaN(actual.Y) && Single.IsNaN(actual.Z), "Vector3f.Normalize did not return the expected value."); }
public void QuaternionConstructorTest1() { Vector3 v = new Vector3(1.0f, 2.0f, 3.0f); Single w = 4.0f; Quaternion target = new Quaternion(v, w); Assert.True(MathHelper.Equal(target.X, v.X) && MathHelper.Equal(target.Y, v.Y) && MathHelper.Equal(target.Z, v.Z) && MathHelper.Equal(target.W, w), "Quaternion.constructor (Vector3f,w) did not return the expected value."); }
public void Vector3DivideTest() { Vector3 a = new Vector3(1.0f, 2.0f, 3.0f); Single div = 2.0f; Vector3 expected = new Vector3(0.5f, 1.0f, 1.5f); Vector3 actual; actual = Vector3.Divide(a, div); Assert.Equal(expected, actual); }
public void Vector3NegateTest() { Vector3 a = new Vector3(1.0f, 2.0f, 3.0f); Vector3 expected = new Vector3(-1.0f, -2.0f, -3.0f); Vector3 actual; actual = Vector3.Negate(a); Assert.Equal(expected, actual); }
public void PlaneDotNormalTest() { Plane target = new Plane(2, 3, 4, 5); Vector3 value = new Vector3(5, 4, 3); Single expected = 10 + 12 + 12; Single actual = Plane.DotNormal(target, value); Assert.True(MathHelper.Equal(expected, actual), "Plane.DotCoordinate returns unexpected value."); }
public void Vector3SqrtTest() { Vector3 a = new Vector3(-2.5f, 2.0f, 0.5f); Vector3 b = new Vector3(5.5f, 4.5f, 16.5f); Assert.Equal(2, (int)Vector3.SquareRoot(b).X); Assert.Equal(2, (int)Vector3.SquareRoot(b).Y); Assert.Equal(4, (int)Vector3.SquareRoot(b).Z); Assert.Equal(Single.NaN, Vector3.SquareRoot(a).X); }
public void Vector3CrossTest1() { Vector3 a = new Vector3(0.0f, 1.0f, 0.0f); Vector3 b = new Vector3(0.0f, 1.0f, 0.0f); Vector3 expected = new Vector3(0.0f, 0.0f, 0.0f); Vector3 actual = Vector3.Cross(a, b); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Cross did not return the expected value."); }
public void Vector3ConstructorTest1() { Vector2 a = new Vector2(1.0f, 2.0f); Single z = 3.0f; Vector3 target = new Vector3(a, z); Assert.True(MathHelper.Equal(target.X, a.X) && MathHelper.Equal(target.Y, a.Y) && MathHelper.Equal(target.Z, z), "Vector3f.constructor (Vector2f,z) did not return the expected value."); }
public void Vector3ConstructorTest() { Single x = 1.0f; Single y = 2.0f; Single z = 3.0f; Vector3 target = new Vector3(x, y, z); Assert.True(MathHelper.Equal(target.X, x) && MathHelper.Equal(target.Y, y) && MathHelper.Equal(target.Z, z), "Vector3f.constructor (x,y,z) did not return the expected value."); }
public void Vector3TransformByQuaternionTest2() { Vector3 v = new Vector3(1.0f, 2.0f, 3.0f); Quaternion q = Quaternion.Identity; Vector3 expected = v; Vector3 actual = Vector3.Transform(v, q); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value."); }
//[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)] public void Vector3ClampTestFX() { Vector3 a = new Vector3(0.5f, 0.3f, 0.33f); Vector3 min = new Vector3(0.0f, 0.1f, 0.13f); Vector3 max = new Vector3(1.0f, 1.1f, 1.13f); // Normal case. // Case N1: specified value is in the range. Vector3 expected = new Vector3(0.5f, 0.3f, 0.33f); Vector3 actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // Normal case. // Case N2: specified value is bigger than max value. a = new Vector3(2.0f, 3.0f, 4.0f); expected = max; actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // Case N3: specified value is smaller than max value. a = new Vector3(-2.0f, -3.0f, -4.0f); expected = min; actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // Case N4: combination case. a = new Vector3(-2.0f, 0.5f, 4.0f); expected = new Vector3(min.X, a.Y, max.Z); actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // User specified min value is bigger than max value. max = new Vector3(0.0f, 0.1f, 0.13f); min = new Vector3(1.0f, 1.1f, 1.13f); // Case W1: specified value is in the range. a = new Vector3(0.5f, 0.3f, 0.33f); expected = min; actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // Normal case. // Case W2: specified value is bigger than max and min value. a = new Vector3(2.0f, 3.0f, 4.0f); expected = min; actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); // Case W3: specified value is smaller than min and max value. a = new Vector3(-2.0f, -3.0f, -4.0f); expected = min; actual = Vector3.Clamp(a, min, max); Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Clamp did not return the expected value."); }
public static Vector3 NormalizeJitOptimizeCanaryTest() { var result = VectorTests.Vector3Value; for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++) { result += Vector3.Normalize(result); } return(result); }
public static Vector3 AddFunctionTest() { var result = VectorTests.Vector3Value; for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++) { result = Vector3.Add(result, VectorTests.Vector3Delta); } return(result); }
public static Vector3 CrossTest() { var result = VectorTests.Vector3Value; for (var iteration = 0; iteration < Benchmark.InnerIterationCount; iteration++) { result = Vector3.Cross(result, VectorTests.Vector3ValueInverted); } return(result); }
public void PlaneConstructorTest3() { Vector3 normal = new Vector3(1, 2, 3); Single d = 4; Plane target = new Plane(normal, d); Assert.True( target.Normal == normal && target.D == d, "Plane.cstor did not return the expected value."); }