diff --git a/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs b/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs index 1824bd38d3255..80f1d13355d80 100644 --- a/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs +++ b/src/libraries/System.Numerics.Vectors/ref/System.Numerics.Vectors.cs @@ -153,7 +153,9 @@ public partial struct Quaternion : System.IEquatable public float Z; public Quaternion(System.Numerics.Vector3 vectorPart, float scalarPart) { throw null; } public Quaternion(float x, float y, float z, float w) { throw null; } + public static System.Numerics.Quaternion Zero { get { throw null; } } public static System.Numerics.Quaternion Identity { get { throw null; } } + public readonly bool IsZero { get { throw null; } } public readonly bool IsIdentity { get { throw null; } } public static System.Numerics.Quaternion Add(System.Numerics.Quaternion value1, System.Numerics.Quaternion value2) { throw null; } public static System.Numerics.Quaternion Concatenate(System.Numerics.Quaternion value1, System.Numerics.Quaternion value2) { throw null; } diff --git a/src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs b/src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs index a7e27420c09fd..472a2040e33a8 100644 --- a/src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs @@ -877,6 +877,32 @@ public void QuaternionEqualsTest1() actual = a.Equals(b); Assert.Equal(expected, actual); } + + // A test for Zero + [Fact] + public void QuaternionZeroTest() + { + Quaternion val = new(); + Assert.Equal(val, Quaternion.Zero); + + // The default value should be equal to a zero value. + val = default; + Assert.Equal(val, Quaternion.Zero); + } + + // A test for IsZero + [Fact] + public void QuaternionIsZeroTest() + { + Assert.True(Quaternion.Zero.IsZero); + Assert.True(default(Quaternion).IsZero); + Assert.True(new Quaternion().IsZero); + Assert.True(new Quaternion(0, 0, 0, 0).IsZero); + Assert.False(new Quaternion(0, 0, 0, 1).IsZero); + Assert.False(new Quaternion(1, 0, 0, 1).IsZero); + Assert.False(new Quaternion(0, 1, 0, 1).IsZero); + Assert.False(new Quaternion(0, 0, 1, 1).IsZero); + } // A test for Identity [Fact] diff --git a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs index ed863caca43be..bba2f2d61d2a2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs @@ -51,6 +51,13 @@ public Quaternion(Vector3 vectorPart, float scalarPart) W = scalarPart; } + /// Gets a quaternion that represents a zero. + /// A quaternion whose values are (0, 0, 0, 0). + public static Quaternion Zero + { + get => new(); + } + /// Gets a quaternion that represents no rotation. /// A quaternion whose values are (0, 0, 0, 1). public static Quaternion Identity @@ -58,6 +65,14 @@ public static Quaternion Identity get => new Quaternion(0, 0, 0, 1); } + /// Gets a value that indicates whether the current instance is the zero quaternion. + /// if the current instance is the zero quaternion; otherwise, . + /// + public readonly bool IsZero + { + get => this == Zero; + } + /// Gets a value that indicates whether the current instance is the identity quaternion. /// if the current instance is the identity quaternion; otherwise, . ///