Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional cleanup and acceleration of the System.Numerics vector and related types #103527

Merged
merged 10 commits into from
Jun 20, 2024
11 changes: 6 additions & 5 deletions src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public void QuaternionCreateFromAxisAngleTest()
Vector3 axis = Vector3.Normalize(new Vector3(1.0f, 2.0f, 3.0f));
float angle = MathHelper.ToRadians(30.0f);

Quaternion expected = new Quaternion(0.0691723f, 0.1383446f, 0.207516879f, 0.9659258f);
Quaternion expected = new Quaternion(0.06917231f, 0.13834462f, 0.2075169f, 0.9659258f);
Quaternion actual;

actual = Quaternion.CreateFromAxisAngle(axis, angle);
Expand Down Expand Up @@ -545,10 +545,11 @@ public void QuaternionInverseTest()
public void QuaternionInverseTest1()
{
Quaternion a = new Quaternion();

Quaternion expected = Quaternion.Zero;
Quaternion actual = Quaternion.Inverse(a);

Assert.True(float.IsNaN(actual.X) && float.IsNaN(actual.Y) && float.IsNaN(actual.Z) && float.IsNaN(actual.W)
, $"Quaternion.Inverse - did not return the expected value: expected {new Quaternion(float.NaN, float.NaN, float.NaN, float.NaN)} actual {actual}");
Assert.Equal(expected, actual);
}

// A test for ToString ()
Expand Down Expand Up @@ -919,10 +920,10 @@ public void QuaternionZeroTest()
{
// A default value should be equal to a zero value.
Assert.Equal(default(Quaternion), Quaternion.Zero);

// A newly constructed value should be equal to a zero value.
Assert.Equal(new Quaternion(), Quaternion.Zero);

// A newly constructed value with (0, 0, 0, 0) should be equal to a zero value.
Assert.Equal(new Quaternion(0, 0, 0, 0), Quaternion.Zero);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public void Vector2TransformByQuaternionTest1()
{
Vector2 v = new Vector2(1.0f, 2.0f);
Quaternion q = new Quaternion();
Vector2 expected = v;
Vector2 expected = Vector2.Zero;

Vector2 actual = Vector2.Transform(v, q);
Assert.True(MathHelper.Equal(expected, actual), "Vector2f.Transform did not return the expected value.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ public void Vector3TransformByQuaternionTest1()
{
Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
Quaternion q = new Quaternion();
Vector3 expected = v;
Vector3 expected = Vector3.Zero;

Vector3 actual = Vector3.Transform(v, q);
Assert.True(MathHelper.Equal(expected, actual), "Vector3f.Transform did not return the expected value.");
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ public void Vector4TransformVector4QuaternionTest1()
{
Vector4 v = new Vector4(1.0f, 2.0f, 3.0f, 0.0f);
Quaternion q = new Quaternion();
Vector4 expected = v;
Vector4 expected = Vector4.Zero;

Vector4 actual = Vector4.Transform(v, q);
Assert.True(MathHelper.Equal(expected, actual), "Vector4f.Transform did not return the expected value.");
Expand Down Expand Up @@ -844,7 +844,7 @@ public void Vector4TransformVector3QuaternionTest1()
{
Vector3 v = new Vector3(1.0f, 2.0f, 3.0f);
Quaternion q = new Quaternion();
Vector4 expected = new Vector4(v, 1.0f);
Vector4 expected = Vector4.Zero;

Vector4 actual = Vector4.Transform(v, q);
Assert.True(MathHelper.Equal(expected, actual), "Vector4f.Transform did not return the expected value.");
Expand Down Expand Up @@ -888,7 +888,7 @@ public void Vector4TransformVector2QuaternionTest1()
{
Vector2 v = new Vector2(1.0f, 2.0f);
Quaternion q = new Quaternion();
Vector4 expected = new Vector4(1.0f, 2.0f, 0, 1.0f);
Vector4 expected = Vector4.Zero;

Vector4 actual = Vector4.Transform(v, q);
Assert.True(MathHelper.Equal(expected, actual), "Vector4f.Transform did not return the expected value.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ readonly get
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}

return Unsafe.Add(ref Unsafe.AsRef(in this.X), row)[column];
return Unsafe.Add(ref Unsafe.AsRef(in X), row)[column];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -83,7 +82,7 @@ readonly get
{
ThrowHelper.ThrowArgumentOutOfRangeException();
}
Unsafe.Add(ref this.X, row)[column] = value;
Unsafe.Add(ref X, row)[column] = value;
}
}

Expand Down Expand Up @@ -514,7 +513,7 @@ public readonly float GetDeterminant()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override readonly int GetHashCode() => HashCode.Combine(X, Y, Z);

bool IEquatable<Impl>.Equals(Impl other) => Equals(in other);
readonly bool IEquatable<Impl>.Equals(Impl other) => Equals(in other);
}
}
}
Loading
Loading