@@ -435,7 +435,8 @@ p5.Vector = class {
435
435
* @param {p5.Vector | Number[] } value divisor vector.
436
436
* @chainable
437
437
*/
438
- rem ( x , y , z ) {
438
+ rem ( ...args ) {
439
+ let [ x , y , z ] = args ;
439
440
if ( x instanceof p5 . Vector ) {
440
441
if ( [ x . x , x . y , x . z ] . every ( Number . isFinite ) ) {
441
442
const xComponent = parseFloat ( x . x ) ;
@@ -456,15 +457,15 @@ p5.Vector = class {
456
457
return this . calculateRemainder3D ( x [ 0 ] , x [ 1 ] , x [ 2 ] ) ;
457
458
}
458
459
}
459
- } else if ( arguments . length === 1 ) {
460
- if ( Number . isFinite ( arguments [ 0 ] ) && arguments [ 0 ] !== 0 ) {
461
- this . x = this . x % arguments [ 0 ] ;
462
- this . y = this . y % arguments [ 0 ] ;
463
- this . z = this . z % arguments [ 0 ] ;
460
+ } else if ( args . length === 1 ) {
461
+ if ( Number . isFinite ( args [ 0 ] ) && args [ 0 ] !== 0 ) {
462
+ this . x = this . x % args [ 0 ] ;
463
+ this . y = this . y % args [ 0 ] ;
464
+ this . z = this . z % args [ 0 ] ;
464
465
return this ;
465
466
}
466
- } else if ( arguments . length === 2 ) {
467
- const vectorComponents = [ ... arguments ] ;
467
+ } else if ( args . length === 2 ) {
468
+ const vectorComponents = args ;
468
469
if ( vectorComponents . every ( element => Number . isFinite ( element ) ) ) {
469
470
if ( vectorComponents . length === 2 ) {
470
471
return this . calculateRemainder2D (
@@ -473,8 +474,8 @@ p5.Vector = class {
473
474
) ;
474
475
}
475
476
}
476
- } else if ( arguments . length === 3 ) {
477
- const vectorComponents = [ ... arguments ] ;
477
+ } else if ( args . length === 3 ) {
478
+ const vectorComponents = args ;
478
479
if ( vectorComponents . every ( element => Number . isFinite ( element ) ) ) {
479
480
if ( vectorComponents . length === 3 ) {
480
481
return this . calculateRemainder3D (
@@ -745,7 +746,8 @@ p5.Vector = class {
745
746
* @chainable
746
747
*/
747
748
748
- mult ( x , y , z ) {
749
+ mult ( ...args ) {
750
+ let [ x , y , z ] = args ;
749
751
if ( x instanceof p5 . Vector ) {
750
752
// new p5.Vector will check that values are valid upon construction but it's possible
751
753
// that someone could change the value of a component after creation, which is why we still
@@ -795,21 +797,21 @@ p5.Vector = class {
795
797
return this ;
796
798
}
797
799
798
- const vectorComponents = [ ... arguments ] ;
800
+ const vectorComponents = args ;
799
801
if (
800
802
vectorComponents . every ( element => Number . isFinite ( element ) ) &&
801
803
vectorComponents . every ( element => typeof element === 'number' )
802
804
) {
803
- if ( arguments . length === 1 ) {
805
+ if ( args . length === 1 ) {
804
806
this . x *= x ;
805
807
this . y *= x ;
806
808
this . z *= x ;
807
809
}
808
- if ( arguments . length === 2 ) {
810
+ if ( args . length === 2 ) {
809
811
this . x *= x ;
810
812
this . y *= y ;
811
813
}
812
- if ( arguments . length === 3 ) {
814
+ if ( args . length === 3 ) {
813
815
this . x *= x ;
814
816
this . y *= y ;
815
817
this . z *= z ;
@@ -962,7 +964,8 @@ p5.Vector = class {
962
964
* @param {p5.Vector } v vector to divide the components of the original vector by.
963
965
* @chainable
964
966
*/
965
- div ( x , y , z ) {
967
+ div ( ...args ) {
968
+ let [ x , y , z ] = args ;
966
969
if ( x instanceof p5 . Vector ) {
967
970
// new p5.Vector will check that values are valid upon construction but it's possible
968
971
// that someone could change the value of a component after creation, which is why we still
@@ -1025,7 +1028,7 @@ p5.Vector = class {
1025
1028
return this ;
1026
1029
}
1027
1030
1028
- const vectorComponents = [ ... arguments ] ;
1031
+ const vectorComponents = args ;
1029
1032
if (
1030
1033
vectorComponents . every ( element => Number . isFinite ( element ) ) &&
1031
1034
vectorComponents . every ( element => typeof element === 'number' )
@@ -1035,16 +1038,16 @@ p5.Vector = class {
1035
1038
return this ;
1036
1039
}
1037
1040
1038
- if ( arguments . length === 1 ) {
1041
+ if ( args . length === 1 ) {
1039
1042
this . x /= x ;
1040
1043
this . y /= x ;
1041
1044
this . z /= x ;
1042
1045
}
1043
- if ( arguments . length === 2 ) {
1046
+ if ( args . length === 2 ) {
1044
1047
this . x /= x ;
1045
1048
this . y /= y ;
1046
1049
}
1047
- if ( arguments . length === 3 ) {
1050
+ if ( args . length === 3 ) {
1048
1051
this . x /= x ;
1049
1052
this . y /= y ;
1050
1053
this . z /= z ;
@@ -2400,10 +2403,7 @@ p5.Vector = class {
2400
2403
* </code>
2401
2404
* </div>
2402
2405
*/
2403
- static fromAngle ( angle , length ) {
2404
- if ( typeof length === 'undefined' ) {
2405
- length = 1 ;
2406
- }
2406
+ static fromAngle ( angle , length = 1 ) {
2407
2407
return new p5 . Vector ( length * Math . cos ( angle ) , length * Math . sin ( angle ) , 0 ) ;
2408
2408
}
2409
2409
@@ -2451,10 +2451,7 @@ p5.Vector = class {
2451
2451
* </code>
2452
2452
* </div>
2453
2453
*/
2454
- static fromAngles ( theta , phi , length ) {
2455
- if ( typeof length === 'undefined' ) {
2456
- length = 1 ;
2457
- }
2454
+ static fromAngles ( theta , phi , length = 1 ) {
2458
2455
const cosPhi = Math . cos ( phi ) ;
2459
2456
const sinPhi = Math . sin ( phi ) ;
2460
2457
const cosTheta = Math . cos ( theta ) ;
@@ -2565,10 +2562,11 @@ p5.Vector = class {
2565
2562
* @return {p5.Vector } resulting <a href="#/p5.Vector">p5.Vector</a>.
2566
2563
*/
2567
2564
2568
- static add ( v1 , v2 , target ) {
2565
+ static add ( ...args ) {
2566
+ let [ v1 , v2 , target ] = args ;
2569
2567
if ( ! target ) {
2570
2568
target = v1 . copy ( ) ;
2571
- if ( arguments . length === 3 ) {
2569
+ if ( args . length === 3 ) {
2572
2570
p5 . _friendlyError (
2573
2571
'The target parameter is undefined, it should be of type p5.Vector' ,
2574
2572
'p5.Vector.add'
@@ -2616,10 +2614,11 @@ p5.Vector = class {
2616
2614
* @return {p5.Vector } The resulting <a href="#/p5.Vector">p5.Vector</a>
2617
2615
*/
2618
2616
2619
- static sub ( v1 , v2 , target ) {
2617
+ static sub ( ...args ) {
2618
+ let [ v1 , v2 , target ] = args ;
2620
2619
if ( ! target ) {
2621
2620
target = v1 . copy ( ) ;
2622
- if ( arguments . length === 3 ) {
2621
+ if ( args . length === 3 ) {
2623
2622
p5 . _friendlyError (
2624
2623
'The target parameter is undefined, it should be of type p5.Vector' ,
2625
2624
'p5.Vector.sub'
@@ -2651,6 +2650,7 @@ p5.Vector = class {
2651
2650
* @param {p5.Vector } v
2652
2651
* @param {Number } n
2653
2652
* @param {p5.Vector } [target] vector to receive the result.
2653
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2654
2654
*/
2655
2655
2656
2656
/**
@@ -2659,6 +2659,7 @@ p5.Vector = class {
2659
2659
* @param {p5.Vector } v0
2660
2660
* @param {p5.Vector } v1
2661
2661
* @param {p5.Vector } [target]
2662
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2662
2663
*/
2663
2664
2664
2665
/**
@@ -2667,11 +2668,13 @@ p5.Vector = class {
2667
2668
* @param {p5.Vector } v0
2668
2669
* @param {Number[] } arr
2669
2670
* @param {p5.Vector } [target]
2671
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2670
2672
*/
2671
- static mult ( v , n , target ) {
2673
+ static mult ( ...args ) {
2674
+ let [ v , n , target ] = args ;
2672
2675
if ( ! target ) {
2673
2676
target = v . copy ( ) ;
2674
- if ( arguments . length === 3 ) {
2677
+ if ( args . length === 3 ) {
2675
2678
p5 . _friendlyError (
2676
2679
'The target parameter is undefined, it should be of type p5.Vector' ,
2677
2680
'p5.Vector.mult'
@@ -2694,9 +2697,11 @@ p5.Vector = class {
2694
2697
* @param {p5.Vector } v
2695
2698
* @param {Number } angle
2696
2699
* @param {p5.Vector } [target] The vector to receive the result
2700
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2697
2701
*/
2698
- static rotate ( v , a , target ) {
2699
- if ( arguments . length === 2 ) {
2702
+ static rotate ( ...args ) {
2703
+ let [ v , a , target ] = args ;
2704
+ if ( args . length === 2 ) {
2700
2705
target = v . copy ( ) ;
2701
2706
} else {
2702
2707
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -2730,6 +2735,7 @@ p5.Vector = class {
2730
2735
* @param {p5.Vector } v
2731
2736
* @param {Number } n
2732
2737
* @param {p5.Vector } [target] The vector to receive the result
2738
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2733
2739
*/
2734
2740
2735
2741
/**
@@ -2738,6 +2744,7 @@ p5.Vector = class {
2738
2744
* @param {p5.Vector } v0
2739
2745
* @param {p5.Vector } v1
2740
2746
* @param {p5.Vector } [target]
2747
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2741
2748
*/
2742
2749
2743
2750
/**
@@ -2746,12 +2753,14 @@ p5.Vector = class {
2746
2753
* @param {p5.Vector } v0
2747
2754
* @param {Number[] } arr
2748
2755
* @param {p5.Vector } [target]
2756
+ * @return {p5.Vector } The resulting new <a href="#/p5.Vector">p5.Vector</a>
2749
2757
*/
2750
- static div ( v , n , target ) {
2758
+ static div ( ...args ) {
2759
+ let [ v , n , target ] = args ;
2751
2760
if ( ! target ) {
2752
2761
target = v . copy ( ) ;
2753
2762
2754
- if ( arguments . length === 3 ) {
2763
+ if ( args . length === 3 ) {
2755
2764
p5 . _friendlyError (
2756
2765
'The target parameter is undefined, it should be of type p5.Vector' ,
2757
2766
'p5.Vector.div'
@@ -2820,10 +2829,11 @@ p5.Vector = class {
2820
2829
* @param {p5.Vector } [target] The vector to receive the result
2821
2830
* @return {p5.Vector } The lerped value
2822
2831
*/
2823
- static lerp ( v1 , v2 , amt , target ) {
2832
+ static lerp ( ...args ) {
2833
+ let [ v1 , v2 , amt , target ] = args ;
2824
2834
if ( ! target ) {
2825
2835
target = v1 . copy ( ) ;
2826
- if ( arguments . length === 4 ) {
2836
+ if ( args . length === 4 ) {
2827
2837
p5 . _friendlyError (
2828
2838
'The target parameter is undefined, it should be of type p5.Vector' ,
2829
2839
'p5.Vector.lerp'
@@ -2851,10 +2861,11 @@ p5.Vector = class {
2851
2861
* @param {p5.Vector } [target] vector to receive the result.
2852
2862
* @return {p5.Vector } slerped vector between v1 and v2
2853
2863
*/
2854
- static slerp ( v1 , v2 , amt , target ) {
2864
+ static slerp ( ...args ) {
2865
+ let [ v1 , v2 , amt , target ] = args ;
2855
2866
if ( ! target ) {
2856
2867
target = v1 . copy ( ) ;
2857
- if ( arguments . length === 4 ) {
2868
+ if ( args . length === 4 ) {
2858
2869
p5 . _friendlyError (
2859
2870
'The target parameter is undefined, it should be of type p5.Vector' ,
2860
2871
'p5.Vector.slerp'
@@ -2907,8 +2918,9 @@ p5.Vector = class {
2907
2918
* @param {p5.Vector } [target] The vector to receive the result
2908
2919
* @return {p5.Vector } The vector v, normalized to a length of 1
2909
2920
*/
2910
- static normalize ( v , target ) {
2911
- if ( arguments . length < 2 ) {
2921
+ static normalize ( ...args ) {
2922
+ let [ v , target ] = args ;
2923
+ if ( args . length < 2 ) {
2912
2924
target = v . copy ( ) ;
2913
2925
} else {
2914
2926
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -2934,8 +2946,9 @@ p5.Vector = class {
2934
2946
* @param {p5.Vector } [target] the vector to receive the result (Optional)
2935
2947
* @return {p5.Vector } v with a magnitude limited to max
2936
2948
*/
2937
- static limit ( v , max , target ) {
2938
- if ( arguments . length < 3 ) {
2949
+ static limit ( ...args ) {
2950
+ let [ v , max , target ] = args ;
2951
+ if ( args . length < 3 ) {
2939
2952
target = v . copy ( ) ;
2940
2953
} else {
2941
2954
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -2961,8 +2974,9 @@ p5.Vector = class {
2961
2974
* @param {p5.Vector } [target] the vector to receive the result (Optional)
2962
2975
* @return {p5.Vector } v with a magnitude set to len
2963
2976
*/
2964
- static setMag ( v , len , target ) {
2965
- if ( arguments . length < 3 ) {
2977
+ static setMag ( ...args ) {
2978
+ let [ v , len , target ] = args ;
2979
+ if ( args . length < 3 ) {
2966
2980
target = v . copy ( ) ;
2967
2981
} else {
2968
2982
if ( ! ( target instanceof p5 . Vector ) ) {
@@ -3020,8 +3034,9 @@ p5.Vector = class {
3020
3034
* @param {p5.Vector } [target] vector to receive the result.
3021
3035
* @return {p5.Vector } the reflected vector
3022
3036
*/
3023
- static reflect ( incidentVector , surfaceNormal , target ) {
3024
- if ( arguments . length < 3 ) {
3037
+ static reflect ( ...args ) {
3038
+ let [ incidentVector , surfaceNormal , target ] = args ;
3039
+ if ( args . length < 3 ) {
3025
3040
target = incidentVector . copy ( ) ;
3026
3041
} else {
3027
3042
if ( ! ( target instanceof p5 . Vector ) ) {
0 commit comments