55
66import * as constants from '../core/constants' ;
77
8- /**
8+ /**
99 * This function is used by binary vector operations to prioritize shorter vectors,
1010 * and to emit a warning when lengths do not match.
1111 */
@@ -14,7 +14,7 @@ const prioritizeSmallerDimension = function(currentVectorDimension, args) {
1414
1515 //if (args.length !== currentVectorDimension && args.length !== 1) {
1616 // TODO how to suppress for valid solo arguments?
17- // p5 ._friendlyError(
17+ // this ._friendlyError(
1818 // `Operating on two vectors of different sizes, the smaller dimension is used. In this operation, both vector will be treated as ${minDimension}D vectors, and any additional values of the longer vector will be ignored.`, 'p5.Vector'
1919 //);
2020 //}
@@ -55,7 +55,7 @@ class Vector {
5555 constructor ( ...args ) {
5656
5757 if ( args . length === 0 ) {
58- p5 . _friendlyError (
58+ this . _friendlyError (
5959 'Requires valid arguments.' , 'p5.Vector'
6060 ) ;
6161 }
@@ -69,7 +69,7 @@ class Vector {
6969
7070 this . values = [ ] ;
7171 if ( Array . isArray ( args ) && ! args . every ( v => typeof v === 'number' && Number . isFinite ( v ) ) ) {
72- p5 . _friendlyError (
72+ this . _friendlyError (
7373 'Arguments contain non-finite numbers' ,
7474 target . name
7575 ) ;
@@ -85,6 +85,9 @@ class Vector {
8585 this . isVector = true ;
8686 }
8787
88+ // This will get overwritten when exported as part of p5.
89+ _friendlyError ( _e ) { }
90+
8891 get dimensions ( ) {
8992 return this . values . length ;
9093 }
@@ -123,7 +126,7 @@ class Vector {
123126 if ( index < this . values . length ) {
124127 return this . values [ index ] ;
125128 } else {
126- p5 . _friendlyError (
129+ this . _friendlyError (
127130 'The index parameter is trying to set a value outside the bounds of the vector' ,
128131 'p5.Vector.setValue'
129132 ) ;
@@ -148,7 +151,7 @@ class Vector {
148151 if ( index < this . values . length ) {
149152 this . values [ index ] = value ;
150153 } else {
151- p5 . _friendlyError (
154+ this . _friendlyError (
152155 'The index parameter is trying to set a value outside the bounds of the vector' ,
153156 'p5.Vector.setValue'
154157 ) ;
@@ -3051,7 +3054,7 @@ class Vector {
30513054 if ( ! target ) {
30523055 target = v1 . copy ( ) ;
30533056 if ( arguments . length === 3 ) {
3054- p5 . _friendlyError (
3057+ this . _friendlyError (
30553058 'The target parameter is undefined, it should be of type p5.Vector' ,
30563059 'p5.Vector.add'
30573060 ) ;
@@ -3098,7 +3101,7 @@ class Vector {
30983101 if ( ! target ) {
30993102 target = v1 . copy ( ) ;
31003103 if ( arguments . length === 3 ) {
3101- p5 . _friendlyError (
3104+ this . _friendlyError (
31023105 'The target parameter is undefined, it should be of type p5.Vector' ,
31033106 'p5.Vector.sub'
31043107 ) ;
@@ -3142,7 +3145,7 @@ class Vector {
31423145 if ( ! target ) {
31433146 target = v . copy ( ) ;
31443147 if ( arguments . length === 3 ) {
3145- p5 . _friendlyError (
3148+ this . _friendlyError (
31463149 'The target parameter is undefined, it should be of type p5.Vector' ,
31473150 'p5.Vector.mult'
31483151 ) ;
@@ -3168,7 +3171,7 @@ class Vector {
31683171 target = v . copy ( ) ;
31693172 } else {
31703173 if ( ! ( target instanceof Vector ) ) {
3171- p5 . _friendlyError (
3174+ this . _friendlyError (
31723175 'The target parameter should be of type p5.Vector' ,
31733176 'p5.Vector.rotate'
31743177 ) ;
@@ -3212,7 +3215,7 @@ class Vector {
32123215 target = v . copy ( ) ;
32133216
32143217 if ( arguments . length === 3 ) {
3215- p5 . _friendlyError (
3218+ this . _friendlyError (
32163219 'The target parameter is undefined, it should be of type p5.Vector' ,
32173220 'p5.Vector.div'
32183221 ) ;
@@ -3280,7 +3283,7 @@ class Vector {
32803283 if ( ! target ) {
32813284 target = v1 . copy ( ) ;
32823285 if ( arguments . length === 4 ) {
3283- p5 . _friendlyError (
3286+ this . _friendlyError (
32843287 'The target parameter is undefined, it should be of type p5.Vector' ,
32853288 'p5.Vector.lerp'
32863289 ) ;
@@ -3310,7 +3313,7 @@ class Vector {
33103313 if ( ! target ) {
33113314 target = v1 . copy ( ) ;
33123315 if ( arguments . length === 4 ) {
3313- p5 . _friendlyError (
3316+ this . _friendlyError (
33143317 'The target parameter is undefined, it should be of type p5.Vector' ,
33153318 'p5.Vector.slerp'
33163319 ) ;
@@ -3364,7 +3367,7 @@ class Vector {
33643367 target = v . copy ( ) ;
33653368 } else {
33663369 if ( ! ( target instanceof Vector ) ) {
3367- p5 . _friendlyError (
3370+ this . _friendlyError (
33683371 'The target parameter should be of type p5.Vector' ,
33693372 'p5.Vector.normalize'
33703373 ) ;
@@ -3390,7 +3393,7 @@ class Vector {
33903393 target = v . copy ( ) ;
33913394 } else {
33923395 if ( ! ( target instanceof Vector ) ) {
3393- p5 . _friendlyError (
3396+ this . _friendlyError (
33943397 'The target parameter should be of type p5.Vector' ,
33953398 'p5.Vector.limit'
33963399 ) ;
@@ -3416,7 +3419,7 @@ class Vector {
34163419 target = v . copy ( ) ;
34173420 } else {
34183421 if ( ! ( target instanceof Vector ) ) {
3419- p5 . _friendlyError (
3422+ this . _friendlyError (
34203423 'The target parameter should be of type p5.Vector' ,
34213424 'p5.Vector.setMag'
34223425 ) ;
@@ -3472,7 +3475,7 @@ class Vector {
34723475 target = incidentVector . copy ( ) ;
34733476 } else {
34743477 if ( ! ( target instanceof Vector ) ) {
3475- p5 . _friendlyError (
3478+ this . _friendlyError (
34763479 'The target parameter should be of type p5.Vector' ,
34773480 'p5.Vector.reflect'
34783481 ) ;
@@ -3513,7 +3516,7 @@ class Vector {
35133516 } else if ( v1 instanceof Array ) {
35143517 v = new Vector ( ) . set ( v1 ) ;
35153518 } else {
3516- p5 . _friendlyError (
3519+ this . _friendlyError (
35173520 'The v1 parameter should be of type Array or p5.Vector' ,
35183521 'p5.Vector.equals'
35193522 ) ;
@@ -3601,6 +3604,8 @@ function vector(p5, fn) {
36013604 */
36023605 p5 . Vector = Vector ;
36033606
3607+ Vector . prototype . _friendlyError = p5 . _friendlyError ;
3608+
36043609 /**
36053610 * The x component of the vector
36063611 * @type {Number }
0 commit comments