@@ -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}
0 commit comments