MoltenEngine icon indicating copy to clipboard operation
MoltenEngine copied to clipboard

.NET 7 Generic Math Operators

Open Syncaidius opened this issue 3 years ago • 2 comments

Once .NET 7 release around November, look into the use of generic math operators to clean up math type generation. Currently it uses some overly-complex text-template (.tt) files to output a large amount of codebase for vector and quaternion types.

  • Also consider using generic math types to clean up the numerous rectangle, angle, matrix and viewport types
  • Consider cleaning up multiple color types with generic math

See for details: https://devblogs.microsoft.com/dotnet/dotnet-7-generic-math/

Syncaidius avatar Aug 21 '22 19:08 Syncaidius

Any reason to not already port to .net7 then? Its unlikely this project gets released before .net7 anway?

IceReaper avatar Aug 24 '22 17:08 IceReaper

@IceReaper The main reason is stability. Previews tend to have bugs or unfinished features. Although preview 7 is the last one before release in November, other dependencies, such as Silk.NET will also need time to catch up and support it.

Since this would be a quality-of-life change, it makes more sense to prioritize critical systems such as rendering, audio and UI for now. But, if anything comes up along the way that must have generic math, then this will definitely get pushed up in priority.

Syncaidius avatar Aug 25 '22 05:08 Syncaidius

After looking into this further, generic math will not work well for Molten's vector types, as it would still need at least one generic type per vector size (Vector2, 3, and 4) and a separate set for integer and floating-point vectors, which still adds up to a not-so-small amount of types.

The lack of struct inheritance also means that, unless everyone is expected to type something like Vector2F<float> or Vector2I<int> everywhere, it would also need non-generic versions of each vector size.

For now at least, it seems better to stick with template-generated vector types.

Syncaidius avatar Nov 10 '22 07:11 Syncaidius

The first step towards generic math usage has been made by implementing IVector on all vector types. Also includes ISignedVector and IUnsignedVector.

Syncaidius avatar Nov 25 '23 08:11 Syncaidius