Skip to content

Commit 8255a60

Browse files
committed
Merge branch 'main' into develop
2 parents dc6dee9 + 173c1e8 commit 8255a60

File tree

6 files changed

+356
-16
lines changed

6 files changed

+356
-16
lines changed

src/FixedMathSharp/Numerics/Fixed3x3.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,62 @@ public struct Fixed3x3 : IEquatable<Fixed3x3>
3737
/// </summary>
3838
public static readonly Fixed3x3 Zero = new Fixed3x3(new Vector3d(0f, 0f, 0f), new Vector3d(0f, 0f, 0f), new Vector3d(0f, 0f, 0f));
3939

40+
public Fixed64 this[int index]
41+
{
42+
get
43+
{
44+
return index switch
45+
{
46+
0 => m00,
47+
1 => m10,
48+
2 => m20,
49+
4 => m01,
50+
5 => m11,
51+
6 => m21,
52+
8 => m02,
53+
9 => m12,
54+
10 => m22,
55+
_ => throw new IndexOutOfRangeException("Invalid matrix index!"),
56+
};
57+
}
58+
set
59+
{
60+
switch (index)
61+
{
62+
case 0:
63+
m00 = value;
64+
break;
65+
case 1:
66+
m10 = value;
67+
break;
68+
case 2:
69+
m20 = value;
70+
break;
71+
case 4:
72+
m01 = value;
73+
break;
74+
case 5:
75+
m11 = value;
76+
break;
77+
case 6:
78+
m21 = value;
79+
break;
80+
case 8:
81+
m02 = value;
82+
break;
83+
case 9:
84+
m12 = value;
85+
break;
86+
case 10:
87+
m22 = value;
88+
break;
89+
default:
90+
throw new IndexOutOfRangeException("Invalid matrix index!");
91+
}
92+
}
93+
}
94+
95+
4096
#endregion
4197

4298
#region Constructors

src/FixedMathSharp/Numerics/Fixed4x4.cs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,98 @@ public struct Fixed4x4 : IEquatable<Fixed4x4>
3636
Fixed64.Zero, Fixed64.Zero, Fixed64.One, Fixed64.Zero,
3737
Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.One);
3838

39+
/// <summary>
40+
/// Returns a matrix with all elements set to zero.
41+
/// </summary>
42+
public static readonly Fixed4x4 Zero = new Fixed4x4(
43+
Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.Zero,
44+
Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.Zero,
45+
Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.Zero,
46+
Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.Zero);
47+
48+
public Fixed64 this[int index]
49+
{
50+
get
51+
{
52+
return index switch
53+
{
54+
0 => m00,
55+
1 => m10,
56+
2 => m20,
57+
3 => m30,
58+
4 => m01,
59+
5 => m11,
60+
6 => m21,
61+
7 => m31,
62+
8 => m02,
63+
9 => m12,
64+
10 => m22,
65+
11 => m32,
66+
12 => m03,
67+
13 => m13,
68+
14 => m23,
69+
15 => m33,
70+
_ => throw new IndexOutOfRangeException("Invalid matrix index!"),
71+
};
72+
}
73+
set
74+
{
75+
switch (index)
76+
{
77+
case 0:
78+
m00 = value;
79+
break;
80+
case 1:
81+
m10 = value;
82+
break;
83+
case 2:
84+
m20 = value;
85+
break;
86+
case 3:
87+
m30 = value;
88+
break;
89+
case 4:
90+
m01 = value;
91+
break;
92+
case 5:
93+
m11 = value;
94+
break;
95+
case 6:
96+
m21 = value;
97+
break;
98+
case 7:
99+
m31 = value;
100+
break;
101+
case 8:
102+
m02 = value;
103+
break;
104+
case 9:
105+
m12 = value;
106+
break;
107+
case 10:
108+
m22 = value;
109+
break;
110+
case 11:
111+
m32 = value;
112+
break;
113+
case 12:
114+
m03 = value;
115+
break;
116+
case 13:
117+
m13 = value;
118+
break;
119+
case 14:
120+
m23 = value;
121+
break;
122+
case 15:
123+
m33 = value;
124+
break;
125+
default:
126+
throw new IndexOutOfRangeException("Invalid matrix index!");
127+
}
128+
}
129+
}
130+
39131
#endregion
40132

41133
#region Constructors

src/FixedMathSharp/Numerics/Fixed64.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,30 @@ public static explicit operator decimal(Fixed64 value)
252252
}
253253

254254
/// <summary>
255-
/// Adds an int to y
255+
/// Adds an Fixed64 to x
256256
/// </summary>
257257
[MethodImpl(MethodImplOptions.AggressiveInlining)]
258258
public static Fixed64 operator +(int x, Fixed64 y)
259259
{
260260
return y + x;
261261
}
262262

263+
/// <summary>
264+
/// Adds a float to x
265+
/// </summary>
266+
public static Fixed64 operator +(Fixed64 x, float y)
267+
{
268+
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y);
269+
}
270+
271+
/// <summary>
272+
/// Adds a Fixed64 to x
273+
/// </summary>
274+
public static Fixed64 operator +(float x, Fixed64 y)
275+
{
276+
return y + x;
277+
}
278+
263279
/// <summary>
264280
/// Subtracts one Fixed64 number from another, with saturating behavior in case of overflow.
265281
/// </summary>
@@ -284,12 +300,30 @@ public static explicit operator decimal(Fixed64 value)
284300
}
285301

286302
/// <summary>
287-
/// Subtracts an int from y
303+
/// Subtracts a Fixed64 from x
288304
/// </summary>
289305
[MethodImpl(MethodImplOptions.AggressiveInlining)]
290306
public static Fixed64 operator -(int x, Fixed64 y)
291307
{
292-
return y - x;
308+
return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D));
309+
}
310+
311+
/// <summary>
312+
/// Subtracts a float from x
313+
/// </summary>
314+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
315+
public static Fixed64 operator -(Fixed64 x, float y)
316+
{
317+
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) - y);
318+
}
319+
320+
/// <summary>
321+
/// Subtracts a Fixed64 from x
322+
/// </summary>
323+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
324+
public static Fixed64 operator -(float x, Fixed64 y)
325+
{
326+
return new Fixed64(x - (y.m_rawValue * FixedMath.SCALE_FACTOR_D));
293327
}
294328

295329
/// <summary>

src/FixedMathSharp/Numerics/FixedQuaternion.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public struct FixedQuaternion : IEquatable<FixedQuaternion>
2020
/// </summary>
2121
public static readonly FixedQuaternion Identity = new FixedQuaternion(Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.One);
2222

23+
/// <summary>
24+
/// Empty quaternion (0, 0, 0, 0).
25+
/// </summary>
26+
public static readonly FixedQuaternion Zero = new FixedQuaternion(Fixed64.Zero, Fixed64.Zero, Fixed64.Zero, Fixed64.Zero);
27+
2328
#endregion
2429

2530
#region Constructors

src/FixedMathSharp/Numerics/Vector2d.cs

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,11 +782,25 @@ public override string ToString()
782782
/// become (X, Z) in the resulting vector, with the provided Z parameter assigned to Y.
783783
/// </returns>
784784
[MethodImpl(MethodImplOptions.AggressiveInlining)]
785-
public Vector3d ToVector3d(Fixed64 z)
785+
public readonly Vector3d ToVector3d(Fixed64 z)
786786
{
787787
return new Vector3d(x, z, y);
788788
}
789789

790+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
791+
public readonly void Deconstruct(out float x, out float y)
792+
{
793+
x = this.x.ToPreciseFloat();
794+
y = this.y.ToPreciseFloat();
795+
}
796+
797+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
798+
public readonly void Deconstruct(out int x, out int y)
799+
{
800+
x = this.x.RoundToInt();
801+
y = this.y.RoundToInt();
802+
}
803+
790804
/// <summary>
791805
/// Converts each component of the vector from radians to degrees.
792806
/// </summary>
@@ -831,6 +845,36 @@ public static Vector2d ToRadians(Vector2d degrees)
831845
return new Vector2d(v1.x + mag, v1.y + mag);
832846
}
833847

848+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
849+
public static Vector2d operator +(Fixed64 mag, Vector2d v1)
850+
{
851+
return v1 + mag;
852+
}
853+
854+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
855+
public static Vector2d operator +(Vector2d v1, (int x, int y) v2)
856+
{
857+
return new Vector2d(v1.x + v2.x, v1.y + v2.y);
858+
}
859+
860+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
861+
public static Vector2d operator +((int x, int y) v2, Vector2d v1)
862+
{
863+
return v1 + v2;
864+
}
865+
866+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
867+
public static Vector2d operator +(Vector2d v1, (float x, float y) v2)
868+
{
869+
return new Vector2d(v1.x + v2.x, v1.y + v2.y);
870+
}
871+
872+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
873+
public static Vector2d operator +((float x, float y) v1, Vector2d v2)
874+
{
875+
return v2 + v1;
876+
}
877+
834878
[MethodImpl(MethodImplOptions.AggressiveInlining)]
835879
public static Vector2d operator -(Vector2d v1, Vector2d v2)
836880
{
@@ -843,6 +887,36 @@ public static Vector2d ToRadians(Vector2d degrees)
843887
return new Vector2d(v1.x - mag, v1.y - mag);
844888
}
845889

890+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
891+
public static Vector2d operator -(Fixed64 mag, Vector2d v1)
892+
{
893+
return new Vector2d(mag - v1.x, mag - v1.y);
894+
}
895+
896+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
897+
public static Vector2d operator -(Vector2d v1, (int x, int y) v2)
898+
{
899+
return new Vector2d(v1.x - v2.x, v1.y - v2.y);
900+
}
901+
902+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
903+
public static Vector2d operator -((int x, int y) v1, Vector2d v2)
904+
{
905+
return new Vector2d(v1.x - v2.x, v1.y - v2.y);
906+
}
907+
908+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
909+
public static Vector2d operator -(Vector2d v1, (float x, float y) v2)
910+
{
911+
return new Vector2d(v1.x - v2.x, v1.y - v2.y);
912+
}
913+
914+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
915+
public static Vector2d operator -((float x, float y) v1, Vector2d v2)
916+
{
917+
return new Vector2d(v1.x - v2.x, v1.y - v2.y);
918+
}
919+
846920
[MethodImpl(MethodImplOptions.AggressiveInlining)]
847921
public static Vector2d operator -(Vector2d v1)
848922
{
@@ -900,7 +974,7 @@ public bool NotZero()
900974
}
901975

902976
[MethodImpl(MethodImplOptions.AggressiveInlining)]
903-
public override bool Equals(object obj)
977+
public override bool Equals(object? obj)
904978
{
905979
return obj is Vector2d other && Equals(other);
906980
}

0 commit comments

Comments
 (0)