@@ -585,7 +585,8 @@ p5.Vector = class {
585
585
* @param {p5.Vector | Number[] } value divisor vector.
586
586
* @chainable
587
587
*/
588
- rem ( x , y , z ) {
588
+ rem ( ...args ) {
589
+ let [ x , y , z ] = args ;
589
590
if ( x instanceof p5 . Vector ) {
590
591
if ( [ x . x , x . y , x . z ] . every ( Number . isFinite ) ) {
591
592
const xComponent = parseFloat ( x . x ) ;
@@ -598,41 +599,35 @@ p5.Vector = class {
598
599
) ;
599
600
}
600
601
} else if ( Array . isArray ( x ) ) {
601
- if ( x . every ( element => Number . isFinite ( element ) ) ) {
602
+ if ( x . every ( Number . isFinite ) ) {
602
603
if ( x . length === 2 ) {
603
604
return this . calculateRemainder2D ( x [ 0 ] , x [ 1 ] ) ;
604
605
}
605
606
if ( x . length === 3 ) {
606
607
return this . calculateRemainder3D ( x [ 0 ] , x [ 1 ] , x [ 2 ] ) ;
607
608
}
608
609
}
609
- } else if ( arguments . length === 1 ) {
610
- if ( Number . isFinite ( arguments [ 0 ] ) && arguments [ 0 ] !== 0 ) {
611
- this . x = this . x % arguments [ 0 ] ;
612
- this . y = this . y % arguments [ 0 ] ;
613
- this . z = this . z % arguments [ 0 ] ;
610
+ } else if ( args . length === 1 ) {
611
+ if ( Number . isFinite ( x ) && x !== 0 ) {
612
+ this . x = this . x % x ;
613
+ this . y = this . y % x ;
614
+ this . z = this . z % x ;
614
615
return this ;
615
616
}
616
- } else if ( arguments . length === 2 ) {
617
- const vectorComponents = [ ...arguments ] ;
618
- if ( vectorComponents . every ( element => Number . isFinite ( element ) ) ) {
619
- if ( vectorComponents . length === 2 ) {
620
- return this . calculateRemainder2D (
621
- vectorComponents [ 0 ] ,
622
- vectorComponents [ 1 ]
623
- ) ;
624
- }
617
+ } else if ( args . length === 2 ) {
618
+ if ( args . every ( Number . isFinite ) ) {
619
+ return this . calculateRemainder2D (
620
+ x ,
621
+ y
622
+ ) ;
625
623
}
626
- } else if ( arguments . length === 3 ) {
627
- const vectorComponents = [ ...arguments ] ;
628
- if ( vectorComponents . every ( element => Number . isFinite ( element ) ) ) {
629
- if ( vectorComponents . length === 3 ) {
630
- return this . calculateRemainder3D (
631
- vectorComponents [ 0 ] ,
632
- vectorComponents [ 1 ] ,
633
- vectorComponents [ 2 ]
634
- ) ;
635
- }
624
+ } else if ( args . length === 3 ) {
625
+ if ( args . every ( Number . isFinite ) ) {
626
+ return this . calculateRemainder3D (
627
+ x ,
628
+ y ,
629
+ z
630
+ ) ;
636
631
}
637
632
}
638
633
}
@@ -987,7 +982,8 @@ p5.Vector = class {
987
982
* @chainable
988
983
*/
989
984
990
- mult ( x , y , z ) {
985
+ mult ( ...args ) {
986
+ let [ x , y , z ] = args ;
991
987
if ( x instanceof p5 . Vector ) {
992
988
// new p5.Vector will check that values are valid upon construction but it's possible
993
989
// that someone could change the value of a component after creation, which is why we still
@@ -1037,21 +1033,21 @@ p5.Vector = class {
1037
1033
return this ;
1038
1034
}
1039
1035
1040
- const vectorComponents = [ ... arguments ] ;
1036
+ const vectorComponents = args ;
1041
1037
if (
1042
1038
vectorComponents . every ( element => Number . isFinite ( element ) ) &&
1043
1039
vectorComponents . every ( element => typeof element === 'number' )
1044
1040
) {
1045
- if ( arguments . length === 1 ) {
1041
+ if ( args . length === 1 ) {
1046
1042
this . x *= x ;
1047
1043
this . y *= x ;
1048
1044
this . z *= x ;
1049
1045
}
1050
- if ( arguments . length === 2 ) {
1046
+ if ( args . length === 2 ) {
1051
1047
this . x *= x ;
1052
1048
this . y *= y ;
1053
1049
}
1054
- if ( arguments . length === 3 ) {
1050
+ if ( args . length === 3 ) {
1055
1051
this . x *= x ;
1056
1052
this . y *= y ;
1057
1053
this . z *= z ;
@@ -1267,7 +1263,8 @@ p5.Vector = class {
1267
1263
* @param {p5.Vector } v vector to divide the components of the original vector by.
1268
1264
* @chainable
1269
1265
*/
1270
- div ( x , y , z ) {
1266
+ div ( ...args ) {
1267
+ let [ x , y , z ] = args ;
1271
1268
if ( x instanceof p5 . Vector ) {
1272
1269
// new p5.Vector will check that values are valid upon construction but it's possible
1273
1270
// that someone could change the value of a component after creation, which is why we still
@@ -1300,7 +1297,7 @@ p5.Vector = class {
1300
1297
}
1301
1298
if ( Array . isArray ( x ) ) {
1302
1299
if (
1303
- x . every ( element => Number . isFinite ( element ) ) &&
1300
+ x . every ( Number . isFinite ) &&
1304
1301
x . every ( element => typeof element === 'number' )
1305
1302
) {
1306
1303
if ( x . some ( element => element === 0 ) ) {
@@ -1330,26 +1327,25 @@ p5.Vector = class {
1330
1327
return this ;
1331
1328
}
1332
1329
1333
- const vectorComponents = [ ...arguments ] ;
1334
1330
if (
1335
- vectorComponents . every ( element => Number . isFinite ( element ) ) &&
1336
- vectorComponents . every ( element => typeof element === 'number' )
1331
+ args . every ( Number . isFinite ) &&
1332
+ args . every ( element => typeof element === 'number' )
1337
1333
) {
1338
- if ( vectorComponents . some ( element => element === 0 ) ) {
1334
+ if ( args . some ( element => element === 0 ) ) {
1339
1335
console . warn ( 'p5.Vector.prototype.div:' , 'divide by 0' ) ;
1340
1336
return this ;
1341
1337
}
1342
1338
1343
- if ( arguments . length === 1 ) {
1339
+ if ( args . length === 1 ) {
1344
1340
this . x /= x ;
1345
1341
this . y /= x ;
1346
1342
this . z /= x ;
1347
1343
}
1348
- if ( arguments . length === 2 ) {
1344
+ if ( args . length === 2 ) {
1349
1345
this . x /= x ;
1350
1346
this . y /= y ;
1351
1347
}
1352
- if ( arguments . length === 3 ) {
1348
+ if ( args . length === 3 ) {
1353
1349
this . x /= x ;
1354
1350
this . y /= y ;
1355
1351
this . z /= z ;
@@ -3171,10 +3167,7 @@ p5.Vector = class {
3171
3167
* </code>
3172
3168
* </div>
3173
3169
*/
3174
- static fromAngle ( angle , length ) {
3175
- if ( typeof length === 'undefined' ) {
3176
- length = 1 ;
3177
- }
3170
+ static fromAngle ( angle , length = 1 ) {
3178
3171
return new p5 . Vector ( length * Math . cos ( angle ) , length * Math . sin ( angle ) , 0 ) ;
3179
3172
}
3180
3173
@@ -3234,10 +3227,7 @@ p5.Vector = class {
3234
3227
* </code>
3235
3228
* </div>
3236
3229
*/
3237
- static fromAngles ( theta , phi , length ) {
3238
- if ( typeof length === 'undefined' ) {
3239
- length = 1 ;
3240
- }
3230
+ static fromAngles ( theta , phi , length = 1 ) {
3241
3231
const cosPhi = Math . cos ( phi ) ;
3242
3232
const sinPhi = Math . sin ( phi ) ;
3243
3233
const cosTheta = Math . cos ( theta ) ;
@@ -3369,10 +3359,11 @@ p5.Vector = class {
3369
3359
* @return {p5.Vector } resulting <a href="#/p5.Vector">p5.Vector</a>.
3370
3360
*/
3371
3361
3372
- static add ( v1 , v2 , target ) {
3362
+ static add ( ...args ) {
3363
+ let [ v1 , v2 , target ] = args ;
3373
3364
if ( ! target ) {
3374
3365
target = v1 . copy ( ) ;
3375
- if ( arguments . length === 3 ) {
3366
+ if ( args . length === 3 ) {
3376
3367
p5 . _friendlyError (
3377
3368
'The target parameter is undefined, it should be of type p5.Vector' ,
3378
3369
'p5.Vector.add'
@@ -3420,10 +3411,11 @@ p5.Vector = class {
3420
3411
* @return {p5.Vector } The resulting <a href="#/p5.Vector">p5.Vector</a>
3421
3412
*/
3422
3413
3423
- static sub ( v1 , v2 , target ) {
3414
+ static sub ( ...args ) {
3415
+ let [ v1 , v2 , target ] = args ;
3424
3416
if ( ! target ) {
3425
3417
target = v1 . copy ( ) ;
3426
- if ( arguments . length === 3 ) {
3418
+ if ( args . length === 3 ) {
3427
3419
p5 . _friendlyError (
3428
3420
'The target parameter is undefined, it should be of type p5.Vector' ,
3429
3421
'p5.Vector.sub'
@@ -3455,6 +3447,7 @@ p5.Vector = class {
3455
3447
* @param {p5.Vector } v
3456
3448
* @param {Number } n
3457
3449
* @param {p5.Vector } [target] vector to receive the result.
3450
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3458
3451
*/
3459
3452
3460
3453
/**
@@ -3463,6 +3456,7 @@ p5.Vector = class {
3463
3456
* @param {p5.Vector } v0
3464
3457
* @param {p5.Vector } v1
3465
3458
* @param {p5.Vector } [target]
3459
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3466
3460
*/
3467
3461
3468
3462
/**
@@ -3471,11 +3465,13 @@ p5.Vector = class {
3471
3465
* @param {p5.Vector } v0
3472
3466
* @param {Number[] } arr
3473
3467
* @param {p5.Vector } [target]
3468
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3474
3469
*/
3475
- static mult ( v , n , target ) {
3470
+ static mult ( ...args ) {
3471
+ let [ v , n , target ] = args ;
3476
3472
if ( ! target ) {
3477
3473
target = v . copy ( ) ;
3478
- if ( arguments . length === 3 ) {
3474
+ if ( args . length === 3 ) {
3479
3475
p5 . _friendlyError (
3480
3476
'The target parameter is undefined, it should be of type p5.Vector' ,
3481
3477
'p5.Vector.mult'
@@ -3498,9 +3494,11 @@ p5.Vector = class {
3498
3494
* @param {p5.Vector } v
3499
3495
* @param {Number } angle
3500
3496
* @param {p5.Vector } [target] The vector to receive the result
3497
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3501
3498
*/
3502
- static rotate ( v , a , target ) {
3503
- if ( arguments . length === 2 ) {
3499
+ static rotate ( ...args ) {
3500
+ let [ v , a , target ] = args ;
3501
+ if ( args . length === 2 ) {
3504
3502
target = v . copy ( ) ;
3505
3503
} else {
3506
3504
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -3534,6 +3532,7 @@ p5.Vector = class {
3534
3532
* @param {p5.Vector } v
3535
3533
* @param {Number } n
3536
3534
* @param {p5.Vector } [target] The vector to receive the result
3535
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3537
3536
*/
3538
3537
3539
3538
/**
@@ -3542,6 +3541,7 @@ p5.Vector = class {
3542
3541
* @param {p5.Vector } v0
3543
3542
* @param {p5.Vector } v1
3544
3543
* @param {p5.Vector } [target]
3544
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3545
3545
*/
3546
3546
3547
3547
/**
@@ -3550,12 +3550,14 @@ p5.Vector = class {
3550
3550
* @param {p5.Vector } v0
3551
3551
* @param {Number[] } arr
3552
3552
* @param {p5.Vector } [target]
3553
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
3553
3554
*/
3554
- static div ( v , n , target ) {
3555
+ static div ( ...args ) {
3556
+ let [ v , n , target ] = args ;
3555
3557
if ( ! target ) {
3556
3558
target = v . copy ( ) ;
3557
3559
3558
- if ( arguments . length === 3 ) {
3560
+ if ( args . length === 3 ) {
3559
3561
p5 . _friendlyError (
3560
3562
'The target parameter is undefined, it should be of type p5.Vector' ,
3561
3563
'p5.Vector.div'
@@ -3624,10 +3626,11 @@ p5.Vector = class {
3624
3626
* @param {p5.Vector } [target] The vector to receive the result
3625
3627
* @return {p5.Vector } The lerped value
3626
3628
*/
3627
- static lerp ( v1 , v2 , amt , target ) {
3629
+ static lerp ( ...args ) {
3630
+ let [ v1 , v2 , amt , target ] = args ;
3628
3631
if ( ! target ) {
3629
3632
target = v1 . copy ( ) ;
3630
- if ( arguments . length === 4 ) {
3633
+ if ( args . length === 4 ) {
3631
3634
p5 . _friendlyError (
3632
3635
'The target parameter is undefined, it should be of type p5.Vector' ,
3633
3636
'p5.Vector.lerp'
@@ -3655,10 +3658,11 @@ p5.Vector = class {
3655
3658
* @param {p5.Vector } [target] vector to receive the result.
3656
3659
* @return {p5.Vector } slerped vector between v1 and v2
3657
3660
*/
3658
- static slerp ( v1 , v2 , amt , target ) {
3661
+ static slerp ( ...args ) {
3662
+ let [ v1 , v2 , amt , target ] = args ;
3659
3663
if ( ! target ) {
3660
3664
target = v1 . copy ( ) ;
3661
- if ( arguments . length === 4 ) {
3665
+ if ( args . length === 4 ) {
3662
3666
p5 . _friendlyError (
3663
3667
'The target parameter is undefined, it should be of type p5.Vector' ,
3664
3668
'p5.Vector.slerp'
@@ -3711,8 +3715,9 @@ p5.Vector = class {
3711
3715
* @param {p5.Vector } [target] The vector to receive the result
3712
3716
* @return {p5.Vector } The vector v, normalized to a length of 1
3713
3717
*/
3714
- static normalize ( v , target ) {
3715
- if ( arguments . length < 2 ) {
3718
+ static normalize ( ...args ) {
3719
+ let [ v , target ] = args ;
3720
+ if ( args . length < 2 ) {
3716
3721
target = v . copy ( ) ;
3717
3722
} else {
3718
3723
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -3738,8 +3743,9 @@ p5.Vector = class {
3738
3743
* @param {p5.Vector } [target] the vector to receive the result (Optional)
3739
3744
* @return {p5.Vector } v with a magnitude limited to max
3740
3745
*/
3741
- static limit ( v , max , target ) {
3742
- if ( arguments . length < 3 ) {
3746
+ static limit ( ...args ) {
3747
+ let [ v , max , target ] = args ;
3748
+ if ( args . length < 3 ) {
3743
3749
target = v . copy ( ) ;
3744
3750
} else {
3745
3751
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -3765,8 +3771,9 @@ p5.Vector = class {
3765
3771
* @param {p5.Vector } [target] the vector to receive the result (Optional)
3766
3772
* @return {p5.Vector } v with a magnitude set to len
3767
3773
*/
3768
- static setMag ( v , len , target ) {
3769
- if ( arguments . length < 3 ) {
3774
+ static setMag ( ...args ) {
3775
+ let [ v , len , target ] = args ;
3776
+ if ( args . length < 3 ) {
3770
3777
target = v . copy ( ) ;
3771
3778
} else {
3772
3779
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -3824,8 +3831,9 @@ p5.Vector = class {
3824
3831
* @param {p5.Vector } [target] vector to receive the result.
3825
3832
* @return {p5.Vector } the reflected vector
3826
3833
*/
3827
- static reflect ( incidentVector , surfaceNormal , target ) {
3828
- if ( arguments . length < 3 ) {
3834
+ static reflect ( ...args ) {
3835
+ let [ incidentVector , surfaceNormal , target ] = args ;
3836
+ if ( args . length < 3 ) {
3829
3837
target = incidentVector . copy ( ) ;
3830
3838
} else {
3831
3839
if ( ! ( target instanceof p5 . Vector ) ) {
0 commit comments