Skip to content

[3.0] Generic Maths Implementation. #2459

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

Draft
wants to merge 58 commits into
base: develop/3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
3c95d6d
start of 3.0 Silk.Net.Maths rewrite
Tweety-Lab May 28, 2025
04846e7
Start work on Vector2I.
Tweety-Lab May 28, 2025
7afd57f
Finish implementing Vector2I Interfaces.
Tweety-Lab May 28, 2025
249be1f
Add Vector2I Unit properties.
Tweety-Lab May 28, 2025
709c142
Add Vector3I Maths methods.
Tweety-Lab May 28, 2025
94a912d
Add more missing Vector2I requirements.
Tweety-Lab May 28, 2025
051785d
Add `Vector3I`.
Tweety-Lab May 28, 2025
88b8405
Change VectorI XML comments.
Tweety-Lab May 28, 2025
d1eade9
Add `Vector4I`.
Tweety-Lab May 28, 2025
9b68e35
Improve VectorI equality checks.
Tweety-Lab May 28, 2025
6a3cf88
Start work on new `Quaternion`.
Tweety-Lab May 28, 2025
cc7ebb6
Clarify current state of new Math type's indexers.
Tweety-Lab May 28, 2025
6af8612
Add lower-dimensional VectorI constructors.
Tweety-Lab May 30, 2025
737b5a8
Add `Vector2F`.
Tweety-Lab May 30, 2025
191de4e
Include generated code.
otac0n May 30, 2025
1cecebe
Merge pull request #1 from otac0n/feature/math-3.0
Tweety-Lab May 30, 2025
291ec1e
Generated constructors, operators, and indexers.
otac0n May 30, 2025
cfee012
Whitespace and comments.
otac0n May 31, 2025
91c7982
Added transpose, negate, and identity.
otac0n May 31, 2025
650f30b
Added some necessary vector bits for testing.
otac0n May 31, 2025
8ebcfb9
Merge pull request #2 from otac0n/feature/math-3.0
Tweety-Lab May 31, 2025
9bd27fe
Add Lerp and a couple of bugfixes.
otac0n May 31, 2025
a617eb8
Remove `IBinaryFloatingPointIeee754` reference.
Tweety-Lab May 31, 2025
d57f94d
Make `VectorNI` Vectors use a `ref` indexer.
Tweety-Lab May 31, 2025
d5a8b54
Use partial implementations from code gen.
otac0n May 31, 2025
3c538bd
Make `Vector2F` Vector use a `ref` indexer.
Tweety-Lab May 31, 2025
4f74ab3
Fix vector `ref` indexer exception messages.
Tweety-Lab May 31, 2025
c9e57f2
Merge branch 'feature/math-3.0' of https://github.com/Tweety-Lab/Silk…
otac0n May 31, 2025
a4b8a6c
Move constructors & existing interfaces.
otac0n May 31, 2025
5a82141
IReadOnlyList<T> code gen.
otac0n May 31, 2025
16e68e2
Fix errors with Quaternion accessibility.
otac0n May 31, 2025
7efc1eb
Merge pull request #3 from otac0n/feature/math-3.0
Tweety-Lab May 31, 2025
0cb1569
Move common operators and interfaces into templates.
otac0n May 31, 2025
c9ce628
Use Legacy namespace qualifications for lecacy Quaternion.
otac0n May 31, 2025
aac298a
Generate constructors to extend smaller vectors.
otac0n May 31, 2025
25f6994
Removed AllBitsSet from Vector2F.
otac0n May 31, 2025
41aa58d
Generate vector specific methods in templates.
otac0n May 31, 2025
0f2d43c
Merge pull request #4 from otac0n/feature/math-3.0
Tweety-Lab Jun 1, 2025
09e674c
Snapshot.
otac0n Jun 30, 2025
070c6f5
Replace generated I/F types with D types.
otac0n Jun 30, 2025
aefd7ea
Merge matrix types.
otac0n Jul 1, 2025
acaf6b4
Update existing types to use INumberBase.
otac0n Jul 1, 2025
ffb7f58
Fix errors.
otac0n Jul 1, 2025
d07c355
Code-gen more matrix implememtations.
otac0n Jul 2, 2025
80fbbfc
Types that need Min/Max (e.g. Box) use INumber instead of INumberBase…
otac0n Jul 2, 2025
2a79fd8
Added explicit casts for vectors.
otac0n Jul 2, 2025
5e0e7d9
Use extension properties for LengthSquared and Length. Use these for…
otac0n Jul 2, 2025
5973151
Generate more vector functions and reorganize.
otac0n Jul 2, 2025
69be9de
Fix type constraints.
otac0n Jul 2, 2025
75b1c5d
Overloads for casts, As, CreateChecked, CreateSaturating, and CreateT…
otac0n Jul 2, 2025
ac8e94e
Handle IsIdentity and GetDeterminant errors.
otac0n Jul 2, 2025
f71206c
Use T.Zero instead of default to avoid NRE.
otac0n Jul 2, 2025
0345ba5
Code-gen multiply operators.
otac0n Jul 3, 2025
9497be8
Recovered Old Quaternion implementation.
otac0n Jul 3, 2025
9aa76de
Fix Obsolete warnings.
otac0n Jul 3, 2025
2d6c95b
XML Doc Comments.
otac0n Jul 3, 2025
1c2b6f8
Reset APIs.
otac0n Jul 3, 2025
bfe143c
Merge pull request #5 from otac0n/feature/math-3.0
Tweety-Lab Jul 3, 2025
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
46 changes: 41 additions & 5 deletions sources/Maths/Maths/Box2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

Expand All @@ -14,7 +15,7 @@ namespace Silk.NET.Maths
[DataContract]
public struct Box2D<T>
: IEquatable<Box2D<T>>
where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
where T : INumber<T>
{
/// <summary>
/// The min.
Expand Down Expand Up @@ -148,9 +149,9 @@ public Box2D<T> GetScaled(Vector2D<T> scale, Vector2D<T> anchor)
/// <typeparam name="TScale">The type of the scale.</typeparam>
/// <returns>The calculated box.</returns>
public Box2D<T> GetScaled<TScale>(Vector2D<TScale> scale, Vector2D<T> anchor)
where TScale : unmanaged, IFormattable, IEquatable<TScale>, IComparable<TScale>
where TScale : INumber<TScale>
{
return this.As<TScale>().GetScaled(scale, anchor.As<TScale>()).As<T>();
return this.AsTruncating<TScale>().GetScaled(scale, anchor.AsTruncating<TScale>()).AsTruncating<T>();
}

/// <summary>
Expand Down Expand Up @@ -209,9 +210,44 @@ public override int GetHashCode()
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted box</returns>
public Box2D<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
[Obsolete("Use AsChecked, AsSaturating, or AsTruncating instead.", error: false)]
public Box2D<TOther> As<TOther>()
where TOther : INumber<TOther>
{
return new(Min.As<TOther>(), Max.As<TOther>());
}

/// <summary>
/// Returns this box casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted box</returns>
public Box2D<TOther> AsChecked<TOther>()
where TOther : INumber<TOther>
{
return new(Min.AsChecked<TOther>(), Max.AsChecked<TOther>());
}

/// <summary>
/// Returns this box casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted box</returns>
public Box2D<TOther> AsSaturating<TOther>()
where TOther : INumber<TOther>
{
return new(Min.AsSaturating<TOther>(), Max.AsSaturating<TOther>());
}

/// <summary>
/// Returns this box casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted box</returns>
public Box2D<TOther> AsTruncating<TOther>()
where TOther : INumber<TOther>
{
return new(Min.AsTruncating<TOther>(), Max.AsTruncating<TOther>());
}
}
}
}
19 changes: 11 additions & 8 deletions sources/Maths/Maths/Box3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

Expand All @@ -14,7 +15,7 @@ namespace Silk.NET.Maths
[DataContract]
public struct Box3D<T>
: IEquatable<Box3D<T>>
where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
where T : INumber<T>
{
/// <summary>
/// The min.
Expand Down Expand Up @@ -157,12 +158,12 @@ public Box3D<T> GetScaled(Vector3D<T> scale, Vector3D<T> anchor)
/// <param name="anchor">The anchor.</param>
/// <returns>The calculated box.</returns>
public Box3D<T> GetScaled<TScale>(Vector3D<TScale> scale, Vector3D<T> anchor)
where TScale : unmanaged, IFormattable, IEquatable<TScale>, IComparable<TScale>
where TScale : INumberBase<TScale>
{
var convertedAnchor = anchor.As<TScale>();
var min = (scale * (Min.As<TScale>() - convertedAnchor)) + convertedAnchor;
var max = (scale * (Max.As<TScale>() - convertedAnchor)) + convertedAnchor;
return new Box3D<T>(min.As<T>(), max.As<T>());
var convertedAnchor = anchor.AsTruncating<TScale>();
var min = (scale * (Min.AsTruncating<TScale>() - convertedAnchor)) + convertedAnchor;
var max = (scale * (Max.AsTruncating<TScale>() - convertedAnchor)) + convertedAnchor;
return new Box3D<T>(min.AsTruncating<T>(), max.AsTruncating<T>());
}

/// <summary>
Expand Down Expand Up @@ -221,9 +222,11 @@ public override int GetHashCode()
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted box</returns>
public Box3D<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
[Obsolete("Use AsChecked, AsSaturating, or AsTruncating instead.", error: false)]
public Box3D<TOther> As<TOther>()
where TOther : INumber<TOther>
{
return new(Min.As<TOther>(), Max.As<TOther>());
}
}
}
}
11 changes: 7 additions & 4 deletions sources/Maths/Maths/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Runtime.Serialization;

namespace Silk.NET.Maths
Expand All @@ -12,7 +13,8 @@ namespace Silk.NET.Maths
[Serializable]
[DataContract]
public struct Circle<T>
: IEquatable<Circle<T>> where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
: IEquatable<Circle<T>>
where T : IRootFunctions<T>
{
/// <summary>
/// The center.
Expand Down Expand Up @@ -166,15 +168,16 @@ public override int GetHashCode()
{
return !value1.Equals(value2);
}

/// <summary>
/// Returns this circle casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted circle</returns>
public Circle<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
[Obsolete("Use AsChecked, AsSaturating, or AsTruncating instead.", error: false)]
public Circle<TOther> As<TOther>() where TOther : IRootFunctions<TOther>
{
return new(Center.As<TOther>(), Scalar.As<T, TOther>(Radius));
}
}
}
}
21 changes: 12 additions & 9 deletions sources/Maths/Maths/Cube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;

Expand All @@ -14,7 +15,7 @@ namespace Silk.NET.Maths
[DataContract]
public struct Cube<T>
: IEquatable<Cube<T>>
where T : unmanaged, IFormattable, IEquatable<T>, IComparable<T>
where T : INumber<T>
{
/// <summary>
/// The origin.
Expand Down Expand Up @@ -169,12 +170,12 @@ public Cube<T> GetScaled(Vector3D<T> scale, Vector3D<T> anchor)
/// <param name="anchor">The anchor.</param>
/// <returns>The calculated cube.</returns>
public Cube<T> GetScaled<TScale>(Vector3D<TScale> scale, Vector3D<T> anchor)
where TScale : unmanaged, IFormattable, IEquatable<TScale>, IComparable<TScale>
where TScale : INumberBase<TScale>
{
var convertedAnchor = anchor.As<TScale>();
var min = (scale * (Origin.As<TScale>() - convertedAnchor)) + convertedAnchor;
var max = (scale * (Max.As<TScale>() - convertedAnchor)) + convertedAnchor;
return new(min.As<T>(), (max - min).As<T>());
var convertedAnchor = anchor.AsTruncating<TScale>();
var min = (scale * (Origin.AsTruncating<TScale>() - convertedAnchor)) + convertedAnchor;
var max = (scale * (Max.AsTruncating<TScale>() - convertedAnchor)) + convertedAnchor;
return new(min.AsTruncating<T>(), (max - min).AsTruncating<T>());
}

/// <summary>
Expand Down Expand Up @@ -229,15 +230,17 @@ public override int GetHashCode()
{
return !value1.Equals(value2);
}

/// <summary>
/// Returns this circle casted to <typeparamref name="TOther"></typeparamref>
/// </summary>
/// <typeparam name="TOther">The type to cast to</typeparam>
/// <returns>The casted cube</returns>
public Cube<TOther> As<TOther>() where TOther : unmanaged, IFormattable, IEquatable<TOther>, IComparable<TOther>
[Obsolete("Use AsChecked, AsSaturating, or AsTruncating instead.", error: false)]
public Cube<TOther> As<TOther>()
where TOther : INumber<TOther>
{
return new(Origin.As<TOther>(), Max.As<TOther>());
}
}
}
}
93 changes: 0 additions & 93 deletions sources/Maths/Maths/Matrix2X2.Ops.cs

This file was deleted.

Loading
Loading