Skip to content

Commit 5d73712

Browse files
committed
Use aggressive inlining for static properties. Use T.One and T.Zero for identity matrices.
1 parent 43a8130 commit 5d73712

6 files changed

Lines changed: 87 additions & 24 deletions

File tree

sources/Maths/Maths/Matrix2X2.gen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public partial struct Matrix2X2<T> :
1717
{
1818
/// <summary>Gets the multiplicative identity matrix of size 2x2.</summary>
1919
public static Matrix2X2<T> Identity { get; } = new(
20-
new(T.MultiplicativeIdentity, T.Zero),
21-
new(T.Zero, T.MultiplicativeIdentity));
20+
new(T.One, T.Zero),
21+
new(T.Zero, T.One));
2222

2323
/// <summary>Returns whether the matrix is the identity matrix.</summary>
2424
[IgnoreDataMember]

sources/Maths/Maths/Matrix3X3.gen.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public partial struct Matrix3X3<T> :
1717
{
1818
/// <summary>Gets the multiplicative identity matrix of size 3x3.</summary>
1919
public static Matrix3X3<T> Identity { get; } = new(
20-
new(T.MultiplicativeIdentity, T.Zero, T.Zero),
21-
new(T.Zero, T.MultiplicativeIdentity, T.Zero),
22-
new(T.Zero, T.Zero, T.MultiplicativeIdentity));
20+
new(T.One, T.Zero, T.Zero),
21+
new(T.Zero, T.One, T.Zero),
22+
new(T.Zero, T.Zero, T.One));
2323

2424
/// <summary>Returns whether the matrix is the identity matrix.</summary>
2525
[IgnoreDataMember]

sources/Maths/Maths/Matrix4X4.gen.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public partial struct Matrix4X4<T> :
1717
{
1818
/// <summary>Gets the multiplicative identity matrix of size 4x4.</summary>
1919
public static Matrix4X4<T> Identity { get; } = new(
20-
new(T.MultiplicativeIdentity, T.Zero, T.Zero, T.Zero),
21-
new(T.Zero, T.MultiplicativeIdentity, T.Zero, T.Zero),
22-
new(T.Zero, T.Zero, T.MultiplicativeIdentity, T.Zero),
23-
new(T.Zero, T.Zero, T.Zero, T.MultiplicativeIdentity));
20+
new(T.One, T.Zero, T.Zero, T.Zero),
21+
new(T.Zero, T.One, T.Zero, T.Zero),
22+
new(T.Zero, T.Zero, T.One, T.Zero),
23+
new(T.Zero, T.Zero, T.Zero, T.One));
2424

2525
/// <summary>Returns whether the matrix is the identity matrix.</summary>
2626
[IgnoreDataMember]

sources/Maths/Maths/Vector2D.gen.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Silk.NET.Maths
66
using System.Collections;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Numerics;
9+
using System.Runtime.CompilerServices;
910
using System.Runtime.InteropServices;
1011
using System.Text;
1112

@@ -22,16 +23,32 @@ public partial struct Vector2D<T> :
2223
where T : INumberBase<T>
2324
{
2425
/// <summary>Gets a vector whose 2 elements are equal to one.</summary>
25-
public static Vector2D<T> One => new(T.One);
26+
public static Vector2D<T> One
27+
{
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
get => new(T.One);
30+
}
2631

2732
/// <summary>Returns a vector whose 2 elements are equal to zero.</summary>
28-
public static Vector2D<T> Zero => default;
33+
public static Vector2D<T> Zero
34+
{
35+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36+
get => new(T.Zero);
37+
}
2938

3039
/// <summary>Gets the vector (1, 0).</summary>
31-
public static Vector2D<T> UnitX => new(T.One, T.Zero);
40+
public static Vector2D<T> UnitX
41+
{
42+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43+
get => new(T.One, T.Zero);
44+
}
3245

3346
/// <summary>Gets the vector (0, 1).</summary>
34-
public static Vector2D<T> UnitY => new(T.Zero, T.One);
47+
public static Vector2D<T> UnitY
48+
{
49+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
50+
get => new(T.Zero, T.One);
51+
}
3552

3653
/// <summary>The X component of the vector.</summary>
3754
public T X;

sources/Maths/Maths/Vector3D.gen.cs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Silk.NET.Maths
66
using System.Collections;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Numerics;
9+
using System.Runtime.CompilerServices;
910
using System.Runtime.InteropServices;
1011
using System.Text;
1112

@@ -22,19 +23,39 @@ public partial struct Vector3D<T> :
2223
where T : INumberBase<T>
2324
{
2425
/// <summary>Gets a vector whose 3 elements are equal to one.</summary>
25-
public static Vector3D<T> One => new(T.One);
26+
public static Vector3D<T> One
27+
{
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
get => new(T.One);
30+
}
2631

2732
/// <summary>Returns a vector whose 3 elements are equal to zero.</summary>
28-
public static Vector3D<T> Zero => default;
33+
public static Vector3D<T> Zero
34+
{
35+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36+
get => new(T.Zero);
37+
}
2938

3039
/// <summary>Gets the vector (1, 0, 0).</summary>
31-
public static Vector3D<T> UnitX => new(T.One, T.Zero, T.Zero);
40+
public static Vector3D<T> UnitX
41+
{
42+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43+
get => new(T.One, T.Zero, T.Zero);
44+
}
3245

3346
/// <summary>Gets the vector (0, 1, 0).</summary>
34-
public static Vector3D<T> UnitY => new(T.Zero, T.One, T.Zero);
47+
public static Vector3D<T> UnitY
48+
{
49+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
50+
get => new(T.Zero, T.One, T.Zero);
51+
}
3552

3653
/// <summary>Gets the vector (0, 0, 1).</summary>
37-
public static Vector3D<T> UnitZ => new(T.Zero, T.Zero, T.One);
54+
public static Vector3D<T> UnitZ
55+
{
56+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57+
get => new(T.Zero, T.Zero, T.One);
58+
}
3859

3960
/// <summary>The X component of the vector.</summary>
4061
public T X;

sources/Maths/Maths/Vector4D.gen.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Silk.NET.Maths
66
using System.Collections;
77
using System.Diagnostics.CodeAnalysis;
88
using System.Numerics;
9+
using System.Runtime.CompilerServices;
910
using System.Runtime.InteropServices;
1011
using System.Text;
1112

@@ -22,22 +23,46 @@ public partial struct Vector4D<T> :
2223
where T : INumberBase<T>
2324
{
2425
/// <summary>Gets a vector whose 4 elements are equal to one.</summary>
25-
public static Vector4D<T> One => new(T.One);
26+
public static Vector4D<T> One
27+
{
28+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29+
get => new(T.One);
30+
}
2631

2732
/// <summary>Returns a vector whose 4 elements are equal to zero.</summary>
28-
public static Vector4D<T> Zero => default;
33+
public static Vector4D<T> Zero
34+
{
35+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
36+
get => new(T.Zero);
37+
}
2938

3039
/// <summary>Gets the vector (1, 0, 0, 0).</summary>
31-
public static Vector4D<T> UnitX => new(T.One, T.Zero, T.Zero, T.Zero);
40+
public static Vector4D<T> UnitX
41+
{
42+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
43+
get => new(T.One, T.Zero, T.Zero, T.Zero);
44+
}
3245

3346
/// <summary>Gets the vector (0, 1, 0, 0).</summary>
34-
public static Vector4D<T> UnitY => new(T.Zero, T.One, T.Zero, T.Zero);
47+
public static Vector4D<T> UnitY
48+
{
49+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
50+
get => new(T.Zero, T.One, T.Zero, T.Zero);
51+
}
3552

3653
/// <summary>Gets the vector (0, 0, 1, 0).</summary>
37-
public static Vector4D<T> UnitZ => new(T.Zero, T.Zero, T.One, T.Zero);
54+
public static Vector4D<T> UnitZ
55+
{
56+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57+
get => new(T.Zero, T.Zero, T.One, T.Zero);
58+
}
3859

3960
/// <summary>Gets the vector (0, 0, 0, 1).</summary>
40-
public static Vector4D<T> UnitW => new(T.Zero, T.Zero, T.Zero, T.One);
61+
public static Vector4D<T> UnitW
62+
{
63+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64+
get => new(T.Zero, T.Zero, T.Zero, T.One);
65+
}
4166

4267
/// <summary>The X component of the vector.</summary>
4368
public T X;

0 commit comments

Comments
 (0)