@@ -1339,6 +1339,24 @@ var staticMethod = `
13391339})
13401340` ;
13411341
1342+ var inplaceMethodWithArgs = `
1343+ (function %name%(...args) {
1344+ for (var i = 0; i < this.rows; i++) {
1345+ for (var j = 0; j < this.columns; j++) {
1346+ this[i][j] = %method%(this[i][j], ...args);
1347+ }
1348+ }
1349+ return this;
1350+ })
1351+ ` ;
1352+
1353+ var staticMethodWithArgs = `
1354+ (function %name%(matrix, ...args) {
1355+ var newMatrix = new Matrix(matrix);
1356+ return newMatrix.%name%(...args);
1357+ })
1358+ ` ;
1359+
13421360var operators = [
13431361 // Arithmetic operators
13441362 [ '+' , 'add' ] ,
@@ -1356,12 +1374,15 @@ var operators = [
13561374] ;
13571375
13581376for ( var operator of operators ) {
1377+ var inplaceOp = eval ( fillTemplateFunction ( inplaceOperator , { name : operator [ 1 ] , op : operator [ 0 ] } ) ) ;
1378+ var inplaceOpS = eval ( fillTemplateFunction ( inplaceOperatorScalar , { name : operator [ 1 ] + 'S' , op : operator [ 0 ] } ) ) ;
1379+ var inplaceOpM = eval ( fillTemplateFunction ( inplaceOperatorMatrix , { name : operator [ 1 ] + 'M' , op : operator [ 0 ] } ) ) ;
1380+ var staticOp = eval ( fillTemplateFunction ( staticOperator , { name : operator [ 1 ] } ) ) ;
13591381 for ( var i = 1 ; i < operator . length ; i ++ ) {
1360- Matrix . prototype [ operator [ i ] ] = eval ( fillTemplateFunction ( inplaceOperator , { name : operator [ i ] , op : operator [ 0 ] } ) ) ;
1361- Matrix . prototype [ operator [ i ] + 'S' ] = eval ( fillTemplateFunction ( inplaceOperatorScalar , { name : operator [ i ] + 'S' , op : operator [ 0 ] } ) ) ;
1362- Matrix . prototype [ operator [ i ] + 'M' ] = eval ( fillTemplateFunction ( inplaceOperatorMatrix , { name : operator [ i ] + 'M' , op : operator [ 0 ] } ) ) ;
1363-
1364- Matrix [ operator [ i ] ] = eval ( fillTemplateFunction ( staticOperator , { name : operator [ i ] } ) ) ;
1382+ Matrix . prototype [ operator [ i ] ] = inplaceOp ;
1383+ Matrix . prototype [ operator [ i ] + 'S' ] = inplaceOpS ;
1384+ Matrix . prototype [ operator [ i ] + 'M' ] = inplaceOpM ;
1385+ Matrix [ operator [ i ] ] = staticOp ;
13651386 }
13661387}
13671388
@@ -1378,9 +1399,24 @@ var methods = [
13781399} ) ;
13791400
13801401for ( var method of methods ) {
1402+ var inplaceMeth = eval ( fillTemplateFunction ( inplaceMethod , { name : method [ 1 ] , method : method [ 0 ] } ) ) ;
1403+ var staticMeth = eval ( fillTemplateFunction ( staticMethod , { name : method [ 1 ] } ) ) ;
13811404 for ( var i = 1 ; i < method . length ; i ++ ) {
1382- Matrix . prototype [ method [ i ] ] = eval ( fillTemplateFunction ( inplaceMethod , { name : method [ i ] , method : method [ 0 ] } ) ) ;
1383- Matrix [ method [ i ] ] = eval ( fillTemplateFunction ( staticMethod , { name : method [ i ] } ) ) ;
1405+ Matrix . prototype [ method [ i ] ] = inplaceMeth ;
1406+ Matrix [ method [ i ] ] = staticMeth ;
1407+ }
1408+ }
1409+
1410+ var methodsWithArgs = [
1411+ [ 'Math.pow' , 'pow' ]
1412+ ] ;
1413+
1414+ for ( var methodWithArg of methodsWithArgs ) {
1415+ var inplaceMethWithArgs = eval ( fillTemplateFunction ( inplaceMethodWithArgs , { name : methodWithArg [ 1 ] , method : methodWithArg [ 0 ] } ) ) ;
1416+ var staticMethWithArgs = eval ( fillTemplateFunction ( staticMethodWithArgs , { name : methodWithArg [ 1 ] } ) ) ;
1417+ for ( var i = 1 ; i < methodWithArg . length ; i ++ ) {
1418+ Matrix . prototype [ methodWithArg [ i ] ] = inplaceMethWithArgs ;
1419+ Matrix [ methodWithArg [ i ] ] = staticMethWithArgs ;
13841420 }
13851421}
13861422
0 commit comments