-
-
Notifications
You must be signed in to change notification settings - Fork 962
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
Deprecate stride math for numerics alternatives #2579
base: master
Are you sure you want to change the base?
Deprecate stride math for numerics alternatives #2579
Conversation
…into add-math-extensions
…into add-math-extensions
added quaternion implicit moved to BitCast
first hurdle:
same with
So it seems like 0 values in System.Numerics arent handled in these methods? |
/// Casts from System.Numerics to Stride.Maths vectors | ||
/// </summary> | ||
/// <param name="v">Value to cast</param> | ||
public static implicit operator Double2(System.Numerics.Vector2 v) => new(v.X,v.Y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a space here?
/// Casts from System.Numerics to Stride.Maths vectors | ||
/// </summary> | ||
/// <param name="v">Value to cast</param> | ||
public static explicit operator Int2(System.Numerics.Vector2 v) => new((int)v.X,(int)v.Y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here.
{ | ||
var result = matrix; | ||
|
||
var row1 = new System.Numerics.Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit unfortunate that Matrix4x4
can't be read as 4 vectors, but it should be and you can do it from M11
, M21
, etc. There are several ways of doing that, e.g.:
var rows = MemoryMarshal.Cast<Matrix4x4, Vector4>(MemoryMarshal.CreateSpan(ref m, 1));
var row4 = rows[3]; // get the bounds check out of the way asap
var row3 = rows[2];
...
Or, even faster:
var row1 = Unsafe.As<float, Vector4>(ref m.M11);
var row2 = Unsafe.As<float, Vector4>(ref m.M21);
var row3 = Unsafe.As<float, Vector4>(ref m.M31);
var row4 = Unsafe.As<float, Vector4>(ref m.M41);
Could also use Bitcast, but since it is by value and the sizes don't match, I'd have to try. And either way not entirely sure the above code will be optimal.
Below you should do the reverse, since certainly 16 float assignments is a bad idea that you'd want to prevent everywhere you see them.
return result; | ||
} | ||
|
||
public static Matrix4x4 Invert(Matrix4x4 matrix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking, not sure whether it is a good idea to add public API for System.Numerics
to a type that may get scrapped when all deprecations and substitutions are done. Basically what you're doing by having these public is hinting at future work to get Stride.Core.Mathematics surface area on par between System.Numerics
types and Stride types. Those two things are sort of in competition with each other.
Before that decision is made, I would keep these internal.
@@ -506,6 +528,7 @@ public float Determinant() | |||
/// Inverts the matrix. | |||
/// If the matrix cannot be inverted (eg. Determinant was zero), then the matrix will be set equivalent to <see cref="Zero"/>. | |||
/// </summary> | |||
[Obsolete("Use MathUtil.Invert instead. This method will be removed in future versions.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an attribute constructor that takes DiagnosticId
.
[Obsolete("Use MathUtil.Invert instead.", DiagnosticId = "STRIDE2100")]
public void Invert();
or
[Obsolete("Use MathUtil.Invert instead.", DiagnosticId = "STRIDE2100", UrlFormat = "https://doc.stride3d.net/latest/en/whatever/{0}")]
public void Invert();
The diagnostic STRIDE2000
was used previously, so just reserve the range 2100-2199. Use as few diagnostics codes as possible, but do use a different one if the situation is different - if people would need to supress them in different situations, for example. For example use STRIDE2101
for deprecations of overloads that take in
, ref
or ref ro
but which are otherwise operations that shouldn't be deprecated such as Add
. STRDIAG
is a bad prefix imho. STR
is string, not Stride, at least that is the automatic context free association. And yeah its a diagnostic, why even bother saying that. Talk to the docs team on Discord (@VaclavElias) to figure out how much effort it is and what the URL format should be. There should be basically only one format for all of Stride.
My misplaced comment from the now merged PR #2238, slightly clarified. I wouldn't add any surface area to Stride's math in terms of parameters it accepts. It accepts Stride types and returns Stride types now. Whatever how it is implemented is a private detail and that can use Don't deprecate math that is perfectly fine and which can be optimized by changing private implementation. Deprecate performance smells such as by-ref and in-place modification (i.e.
One goal is to get Stride's math DRY. It is so freaking silly to have a handful of implementations for one operation! So if any Stride math is touched, for the purpose of deprecations or otherwise, have them all delegate to the most performant implementation. This will be the by-value one, which would work for |
PR Details
Doing some benchmarks and discussing with @Eideren and @ericwj there are some major speed benefits using System.Numerics instead of Stride math.
This PR is meant to deprecate the math functions that are available with the System.Numerics equivalents.
Related Issue
#2238
#2576
Types of changes
Checklist
IMPORTANT
#2238 must be merged first for the implicit conversions