Skip to content

Commit 0345ba5

Browse files
committed
Code-gen multiply operators.
1 parent f71206c commit 0345ba5

32 files changed

Lines changed: 1162 additions & 908 deletions

sources/Maths/Maths/Matrix2X2.Ops.cs

Lines changed: 0 additions & 81 deletions
This file was deleted.

sources/Maths/Maths/Matrix2X2.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ public Matrix2X2(Matrix4X2<T> value)
5454
Row2 = new(value.M21, value.M22);
5555
}
5656

57-
/// <summary>Multiplies a vector by a matrix.</summary>
58-
/// <param name="value1">The vector.</param>
59-
/// <param name="value2">The matrix.</param>
60-
/// <returns>The result of the multiplication.</returns>
61-
public static unsafe Vector2D<T> operator *(Vector2D<T> value1, Matrix2X2<T> value2)
62-
{
63-
return value1 * value2.Row1 + value1 * value2.Row2;
64-
}
65-
6657
/// <summary>Calculates the determinant of the matrix.</summary>
6758
/// <returns>The determinant of the matrix.</returns>
6859
public readonly T GetDeterminant()

sources/Maths/Maths/Matrix2X2.gen.cs

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public override string ToString() =>
109109
Row2.X, Row2.Y);
110110

111111
/// <inheridoc/>
112-
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
113112
public override bool Equals(object? obj) => obj is Matrix2X2<T> other && Equals(other);
114113

115114
/// <inheridoc/>
@@ -197,6 +196,20 @@ public Matrix2X2<T> Transpose() =>
197196
new(left.Row1 * right,
198197
left.Row2 * right);
199198

199+
/// <summary>Multiplies a matrix by another matrix.</summary>
200+
/// <param name="rowVector">The first source matrix, expressed as a row vector.</param>
201+
/// <param name="matrix">The second source matrix.</param>
202+
/// <returns>The result of the multiplication as a column vector.</returns>
203+
public static Vector2D<T> operator *(Vector2D<T> rowVector, Matrix2X2<T> matrix) =>
204+
rowVector.X * matrix.Row1 + rowVector.Y * matrix.Row2;
205+
206+
/// <summary>Multiplies a matrix by another matrix.</summary>
207+
/// <param name="matrix">The first source matrix.</param>
208+
/// <param name="columnVector">The second source matrix, expressed as a column vector.</param>
209+
/// <returns>The result of the multiplication as a row vector.</returns>
210+
public static Vector2D<T> operator *(Matrix2X2<T> matrix, Vector2D<T> columnVector) =>
211+
matrix.Column1 * columnVector.X + matrix.Column2 * columnVector.Y;
212+
200213
/// <summary>Multiplies a matrix by another matrix.</summary>
201214
/// <param name="left">The first source matrix.</param>
202215
/// <param name="right">The second source matrix.</param>
@@ -422,6 +435,9 @@ public static explicit operator checked Matrix2X2<ulong>(Matrix2X2<T> from) =>
422435
Vector2D<ulong>.CreateChecked(from.Row2));
423436
}
424437

438+
/// <summary>
439+
/// Methods for working with <see cref="Matrix2X2{T}"/>
440+
/// </summary>
425441
public static partial class Matrix2X2
426442
{
427443
/// <summary>Linearly interpolates between the corresponding values of two matrices.</summary>
@@ -433,5 +449,100 @@ public static Matrix2X2<T> Lerp<T>(Matrix2X2<T> value1, Matrix2X2<T> value2, T a
433449
where T : IFloatingPointIeee754<T> =>
434450
new(Vector2D.Lerp(value1.Row1, value2.Row1, amount),
435451
Vector2D.Lerp(value1.Row2, value2.Row2, amount));
452+
453+
/// <summary>Adds two matrices together.</summary>
454+
/// <param name="left">The first source matrix.</param>
455+
/// <param name="right">The second source matrix.</param>
456+
/// <returns>The result of the addition.</returns>
457+
public static Matrix2X2<T> Add<T>(Matrix2X2<T> left, Matrix2X2<T> right)
458+
where T : INumberBase<T> =>
459+
left + right;
460+
461+
/// <summary>Returns a negated copy of the specified matrix.</summary>
462+
/// <param name="value">The source matrix.</param>
463+
/// <returns>The negated matrix.</returns>
464+
public static Matrix2X2<T> Negate<T>(Matrix2X2<T> value)
465+
where T : INumberBase<T>
466+
=> -value;
467+
468+
/// <summary>Subtracts the second matrix from the first.</summary>
469+
/// <param name="left">The first source matrix.</param>
470+
/// <param name="right">The second source matrix.</param>
471+
/// <returns>The result of the subtraction.</returns>
472+
public static Matrix2X2<T> Subtract<T>(Matrix2X2<T> left, Matrix2X2<T> right)
473+
where T : INumberBase<T>
474+
=> left - right;
475+
476+
/// <summary>Multiplies a matrix by a scalar value.</summary>
477+
/// <param name="left">The source matrix.</param>
478+
/// <param name="right">The scaling factor.</param>
479+
/// <returns>The scaled matrix.</returns>
480+
public static Matrix2X2<T> Multiply<T>(Matrix2X2<T> left, T right)
481+
where T : INumberBase<T> =>
482+
left * right;
483+
484+
/// <summary>Multiplies a matrix by a scalar value.</summary>
485+
/// <param name="left">The scaling factor.</param>
486+
/// <param name="right">The source matrix.</param>
487+
/// <returns>The scaled matrix.</returns>
488+
public static Matrix2X2<T> Multiply<T>(T left, Matrix2X2<T> right)
489+
where T : INumberBase<T> =>
490+
left * right;
491+
492+
/// <summary>Multiplies a matrix by another matrix.</summary>
493+
/// <param name="rowVector">The first source matrix, expressed as a row vector.</param>
494+
/// <param name="matrix">The second source matrix.</param>
495+
/// <returns>The result of the multiplication as a column vector.</returns>
496+
public static Vector2D<T> Multiply<T>(Vector2D<T> rowVector, Matrix2X2<T> matrix)
497+
where T : INumberBase<T> =>
498+
rowVector * matrix;
499+
500+
/// <summary>Multiplies a matrix by another matrix.</summary>
501+
/// <param name="matrix">The first source matrix.</param>
502+
/// <param name="columnVector">The second source matrix, expressed as a column vector.</param>
503+
/// <returns>The result of the multiplication as a row vector.</returns>
504+
public static Vector2D<T> Multiply<T>(Matrix2X2<T> matrix, Vector2D<T> columnVector)
505+
where T : INumberBase<T> =>
506+
matrix * columnVector;
507+
508+
/// <summary>Multiplies a matrix by another matrix.</summary>
509+
/// <param name="left">The first source matrix.</param>
510+
/// <param name="right">The second source matrix.</param>
511+
/// <returns>The result of the multiplication.</returns>
512+
public static Matrix2X2<T> Multiply<T>(Matrix2X2<T> left, Matrix2X2<T> right)
513+
where T : INumberBase<T> =>
514+
left * right;
515+
516+
/// <summary>Multiplies a matrix by another matrix.</summary>
517+
/// <param name="left">The first source matrix.</param>
518+
/// <param name="right">The second source matrix.</param>
519+
/// <returns>The result of the multiplication.</returns>
520+
public static Matrix2X3<T> Multiply<T>(Matrix2X2<T> left, Matrix2X3<T> right)
521+
where T : INumberBase<T> =>
522+
left * right;
523+
524+
/// <summary>Multiplies a matrix by another matrix.</summary>
525+
/// <param name="left">The first source matrix.</param>
526+
/// <param name="right">The second source matrix.</param>
527+
/// <returns>The result of the multiplication.</returns>
528+
public static Matrix2X4<T> Multiply<T>(Matrix2X2<T> left, Matrix2X4<T> right)
529+
where T : INumberBase<T> =>
530+
left * right;
531+
532+
/// <summary>Multiplies a matrix by another matrix.</summary>
533+
/// <param name="left">The first source matrix.</param>
534+
/// <param name="right">The second source matrix.</param>
535+
/// <returns>The result of the multiplication.</returns>
536+
public static Matrix3X2<T> Multiply<T>(Matrix3X2<T> left, Matrix2X2<T> right)
537+
where T : INumberBase<T> =>
538+
left * right;
539+
540+
/// <summary>Multiplies a matrix by another matrix.</summary>
541+
/// <param name="left">The first source matrix.</param>
542+
/// <param name="right">The second source matrix.</param>
543+
/// <returns>The result of the multiplication.</returns>
544+
public static Matrix4X2<T> Multiply<T>(Matrix4X2<T> left, Matrix2X2<T> right)
545+
where T : INumberBase<T> =>
546+
left * right;
436547
}
437548
}

sources/Maths/Maths/Matrix2X3.Ops.cs

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ public static partial class Matrix2X3
1414
{
1515
private const float BillboardEpsilon = 1e-4f;
1616

17-
/// <summary>Adds two matrices together.</summary>
18-
/// <param name="value1">The first source matrix.</param>
19-
/// <param name="value2">The second source matrix.</param>
20-
/// <returns>The resulting matrix.</returns>
21-
[MethodImpl((MethodImplOptions) 768)]
22-
public static Matrix2X3<T> Add<T>(Matrix2X3<T> value1, Matrix2X3<T> value2)
23-
where T : INumberBase<T>
24-
{
25-
return value1 + value2;
26-
}
27-
2817
/// <summary>Creates a spherical billboard that rotates around a specified object position.</summary>
2918
/// <param name="objectPosition">Position of the object the billboard will rotate around.</param>
3019
/// <param name="cameraPosition">Position of the camera.</param>
@@ -145,69 +134,6 @@ public static Matrix2X3<T> CreateFromYawPitchRoll<T>(T yaw, T pitch, T roll)
145134
return CreateFromQuaternion(q);
146135
}
147136

148-
/// <summary>Multiplies a matrix by another matrix.</summary>
149-
/// <param name="value1">The first source matrix.</param>
150-
/// <param name="value2">The second source matrix.</param>
151-
/// <returns>The result of the multiplication.</returns>
152-
[MethodImpl((MethodImplOptions) 768)]
153-
public static Matrix2X3<T> Multiply<T>(Matrix2X3<T> value1, Matrix3X3<T> value2)
154-
where T : INumberBase<T>
155-
=> value1 * value2;
156-
157-
158-
/// <summary>Multiplies a matrix by another matrix.</summary>
159-
/// <param name="value1">The first source matrix.</param>
160-
/// <param name="value2">The second source matrix.</param>
161-
/// <returns>The result of the multiplication.</returns>
162-
[MethodImpl((MethodImplOptions) 768)]
163-
public static Matrix2X2<T> Multiply<T>(Matrix2X3<T> value1, Matrix3X2<T> value2)
164-
where T : INumberBase<T>
165-
=> value1 * value2;
166-
167-
/// <summary>Multiplies a matrix by another matrix.</summary>
168-
/// <param name="value1">The first source matrix.</param>
169-
/// <param name="value2">The second source matrix.</param>
170-
/// <returns>The result of the multiplication.</returns>
171-
[MethodImpl((MethodImplOptions) 768)]
172-
public static Matrix2X3<T> Multiply<T>(Matrix2X2<T> value1, Matrix2X3<T> value2)
173-
where T : INumberBase<T>
174-
=> value1 * value2;
175-
176-
/// <summary>Multiplies a matrix by a scalar value.</summary>
177-
/// <param name="value1">The source matrix.</param>
178-
/// <param name="value2">The scaling factor.</param>
179-
/// <returns>The scaled matrix.</returns>
180-
[MethodImpl((MethodImplOptions) 768)]
181-
public static Matrix2X3<T> Multiply<T>(Matrix2X3<T> value1, T value2)
182-
where T : INumberBase<T>
183-
=> value1 * value2;
184-
185-
/// <summary>Multiplies a vector by a matrix.</summary>
186-
/// <param name="value1">The vector.</param>
187-
/// <param name="value2">The matrix.</param>
188-
/// <returns>The result of the multiplication.</returns>
189-
[MethodImpl((MethodImplOptions) 768)]
190-
public static Vector3D<T> Multiply<T>(Vector2D<T> value1, Matrix2X3<T> value2)
191-
where T : INumberBase<T>
192-
=> value1 * value2;
193-
194-
/// <summary>Returns a new matrix with the negated elements of the given matrix.</summary>
195-
/// <param name="value">The source matrix.</param>
196-
/// <returns>The negated matrix.</returns>
197-
[MethodImpl((MethodImplOptions) 768)]
198-
public static Matrix2X3<T> Negate<T>(Matrix2X3<T> value)
199-
where T : INumberBase<T>
200-
=> -value;
201-
202-
/// <summary>Subtracts the second matrix from the first.</summary>
203-
/// <param name="value1">The first source matrix.</param>
204-
/// <param name="value2">The second source matrix.</param>
205-
/// <returns>The result of the subtraction.</returns>
206-
[MethodImpl((MethodImplOptions) 768)]
207-
public static Matrix2X3<T> Subtract<T>(Matrix2X3<T> value1, Matrix2X3<T> value2)
208-
where T : INumberBase<T>
209-
=> value1 - value2;
210-
211137
/// <summary>Transforms the given matrix by applying the given Quaternion rotation.</summary>
212138
/// <param name="value">The source matrix to transform.</param>
213139
/// <param name="rotation">The rotation to apply.</param>

sources/Maths/Maths/Matrix2X3.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,5 @@ public Matrix2X3(Matrix4X2<T> value)
6666
/// <summary>Returns whether the matrix is the identity matrix.</summary>
6767
[IgnoreDataMember]
6868
public readonly bool IsIdentity => this == Identity;
69-
70-
/// <summary>Multiplies a vector by a matrix.</summary>
71-
/// <param name="value1">The vector.</param>
72-
/// <param name="value2">The matrix.</param>
73-
/// <returns>The result of the multiplication.</returns>
74-
public static unsafe Vector3D<T> operator *(Vector2D<T> value1, Matrix2X3<T> value2)
75-
{
76-
return value1.X * value2.Row1 + value1.Y * value2.Row2;
77-
}
7869
}
7970
}

0 commit comments

Comments
 (0)