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

Add Zero and IsZero properties to Quaternion. #57354

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ public partial struct Quaternion : System.IEquatable<System.Numerics.Quaternion>
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; }
Expand Down
26 changes: 26 additions & 0 deletions src/libraries/System.Numerics.Vectors/tests/QuaternionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,28 @@ public Quaternion(Vector3 vectorPart, float scalarPart)
W = scalarPart;
}

/// <summary>Gets a quaternion that represents a zero.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 0)</c>.</value>
public static Quaternion Zero
{
get => new();
}

/// <summary>Gets a quaternion that represents no rotation.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 1)</c>.</value>
public static Quaternion Identity
{
get => new Quaternion(0, 0, 0, 1);
}

/// <summary>Gets a value that indicates whether the current instance is the zero quaternion.</summary>
/// <value><see langword="true" /> if the current instance is the zero quaternion; otherwise, <see langword="false" />.</value>
/// <altmember cref="System.Numerics.Quaternion.Zero"/>
public readonly bool IsZero
{
get => this == Zero;
}

/// <summary>Gets a value that indicates whether the current instance is the identity quaternion.</summary>
/// <value><see langword="true" /> if the current instance is the identity quaternion; otherwise, <see langword="false" />.</value>
/// <altmember cref="System.Numerics.Quaternion.Identity"/>
Expand Down