-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[API Proposal]: Quaternion.Zero is missing #57253
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsBackground and motivationVector2, Vector3, and Vector4 when created with new() are all zeroed out and have corresponding API Proposalnamespace System.Numerics
{
public class Quaternion
{
/// <summary>Gets a newly initialized quaternion.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 0)</c>.</value>
public static Quaternion Zero
{
get => new();
}
}
} API Usage// New Quaternion
var q = Quaternion.Zero;
q.X = 0.5;
// Checking
if (q == Quaternion.Zero)
{
// Was uninitialized
} RisksNo breaking changes, adds value to matching base struct types in the System.Numerics package for base initialization state.
|
|
That's a great question, would it make sense to have |
@GrabYourPitchforks @tannergooding Is there any reason why runtime/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs Lines 14 to 27 in 57bfe47
There are no public usages with mutations, so it's easy to make whole struct readonly, just need to rewrite code like that runtime/src/libraries/System.Private.CoreLib/src/System/Numerics/Quaternion.cs Lines 76 to 81 in 57bfe47
|
@hrrrrustic I suspect it's mostly that there wasn't a whole lot of consistency when these types were first introduced all those years ago. Maybe partly that the original designers believed that updating individual values would be a common operation and that apps didn't want to incur the cost of updating the entire struct? (Keep in mind - this was originally designed for a much older JIT / platform.) |
Well, I'd like to propose to make the whole struct readonly at least for consistency with other numbers/numerics-like types |
@hrrrrustic That would be a breaking change, so I don't see that happening. |
Yep, its a breaking change since the fields are Ideally these would be |
I think exposing |
Looks good as proposed. namespace System.Numerics
{
partial struct Quaternion
{
/// <summary>Gets a newly initialized quaternion.</summary>
/// <value>A quaternion whose values are <c>(0, 0, 0, 0)</c>.</value>
public static Quaternion Zero
{
get => new();
}
}
} |
Marked this as |
Background and motivation
Vector2, Vector3, and Vector4 when created with new() are all zeroed out and have corresponding
.Zero
static properties.Quaternion
on the otherhand only has theIdentity
static property and doesn't have the correspondingZero
one to represent its base state when created withnew()
.API Proposal
API Usage
Risks
No breaking changes, adds value to matching base struct types in the System.Numerics package for base initialization state.
The text was updated successfully, but these errors were encountered: