@@ -85,7 +85,7 @@ Matrix.addable = function (x: Matrix, y: Matrix): boolean {
8585 */
8686function Add ( x : Matrix1D , y : Matrix1D ) : Matrix1D ;
8787function Add ( x : Matrix2D , y : Matrix2D ) : Matrix2D ;
88- function Add < T extends Matrix1D & Matrix2D > ( x : T , y : T ) : Matrix1D | Matrix2D {
88+ function Add < T extends Matrix1D | Matrix2D > ( x : T , y : T ) : Matrix1D | Matrix2D {
8989 if ( ! Matrix . addable ( x , y ) ) throw new TypeError ( "Matrices are not addable" ) ;
9090 return x . map ( ( row : number [ ] , i : number ) : number [ ] =>
9191 row . map ( ( column : number , j : number ) : number => {
@@ -134,7 +134,12 @@ function innerproduct(x: Matrix1D, y: Matrix, i: number): number {
134134 * @param {Matrix } y - Matrix to multiply
135135 * @return {Matrix } New matrix with the dot product
136136 */
137- Matrix . multiply = function ( x : Matrix , y : Matrix ) : Matrix {
137+ function Multiply ( x : Matrix1D , y : Matrix ) : Matrix1D ;
138+ function Multiply ( x : Matrix2D , y : Matrix ) : Matrix2D ;
139+ function Multiply < T extends Matrix1D | Matrix2D > (
140+ x : T ,
141+ y : Matrix
142+ ) : Matrix1D | Matrix2D {
138143 if ( ! Matrix . multipliable ( x , y ) ) {
139144 throw new TypeError ( "Matrices are not multipliable" ) ;
140145 }
@@ -154,7 +159,8 @@ Matrix.multiply = function (x: Matrix, y: Matrix): Matrix {
154159 }
155160 } ) ;
156161 }
157- } ;
162+ }
163+ Matrix . multiply = Multiply ;
158164
159165/**
160166 * Inverts a matrix. Matrix must be a square (e.g. 1x1 or 2x2)
@@ -164,7 +170,7 @@ Matrix.multiply = function (x: Matrix, y: Matrix): Matrix {
164170 */
165171function Invert ( x : Matrix1D ) : Matrix1D ;
166172function Invert ( x : Matrix2D ) : Matrix2D ;
167- function Invert < T extends Matrix1D & Matrix2D > ( x : T ) : Matrix1D | Matrix2D {
173+ function Invert < T extends Matrix1D | Matrix2D > ( x : T ) : Matrix1D | Matrix2D {
168174 return Matrix ( inv < any > ( x . __value ) ) ;
169175}
170176Matrix . invert = Invert ;
@@ -231,9 +237,15 @@ Matrix.prototype.multipliable = function (this: Matrix, y: Matrix): boolean {
231237 * @param {Matrix } y - Matrix to multiply
232238 * @return {Matrix } New matrix with the dot product
233239 */
234- Matrix . prototype . multiply = function ( this : Matrix , y : Matrix ) : Matrix {
240+ function multiply ( this : Matrix1D , y : Matrix ) : Matrix1D ;
241+ function multiply ( this : Matrix2D , y : Matrix ) : Matrix2D ;
242+ function multiply < T extends Matrix1D & Matrix2D > (
243+ this : T ,
244+ y : Matrix
245+ ) : Matrix1D | Matrix2D {
235246 return Matrix . multiply ( this , y ) ;
236- } ;
247+ }
248+ Matrix . prototype . multiply = multiply ;
237249
238250/**
239251 * Calculates the transpose of this matrix
0 commit comments