@@ -1339,6 +1339,24 @@ var staticMethod = `
1339
1339
})
1340
1340
` ;
1341
1341
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
+
1342
1360
var operators = [
1343
1361
// Arithmetic operators
1344
1362
[ '+' , 'add' ] ,
@@ -1356,12 +1374,15 @@ var operators = [
1356
1374
] ;
1357
1375
1358
1376
for ( 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 ] } ) ) ;
1359
1381
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 ;
1365
1386
}
1366
1387
}
1367
1388
@@ -1378,9 +1399,24 @@ var methods = [
1378
1399
} ) ;
1379
1400
1380
1401
for ( 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 ] } ) ) ;
1381
1404
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 ;
1384
1420
}
1385
1421
}
1386
1422
0 commit comments