diff --git a/src/math/Matrices/Matrix.js b/src/math/Matrices/Matrix.js index 6a09f7bede..993477e23b 100644 --- a/src/math/Matrices/Matrix.js +++ b/src/math/Matrices/Matrix.js @@ -246,7 +246,7 @@ export class Matrix extends MatrixInterface { refArray = GLMAT_ARRAY_TYPE.from(inMatrix); } if (refArray.length !== this.matrix.length) { - p5._friendlyError( + this._friendlyError( `Expected same dimensions values but received different ${refArray.length}.`, 'p5.Matrix.set' ); diff --git a/src/math/p5.Matrix.js b/src/math/p5.Matrix.js index 8923bb420c..0ebee52b4c 100644 --- a/src/math/p5.Matrix.js +++ b/src/math/p5.Matrix.js @@ -104,6 +104,7 @@ function matrix(p5, fn) { * console.log("Transformed Vector:", transformedVector.toString()); * } */ + Matrix.prototype._friendlyError = p5._friendlyError; p5.Matrix = Matrix; } diff --git a/src/math/p5.Vector.js b/src/math/p5.Vector.js index e5275ad7cc..6770e17678 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2023,9 +2023,9 @@ class Vector { */ setHeading(a) { if (this.dimensions < 2 || ( - this._values instanceof Array && this._values.slice(2).some(v => v !== 0)) + this.values instanceof Array && this.values.slice(2).some(v => v !== 0)) ) { - p5._friendlyError( + this._friendlyError( 'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' + 'For 3D or higher-dimensional vectors, use rotate() or another ' + 'appropriate method instead.', @@ -3575,6 +3575,7 @@ class Vector { 'The v1 parameter should be of type Array or p5.Vector', 'p5.Vector.equals' ); + return false; } return v.equals(v2); } @@ -3664,6 +3665,11 @@ function vector(p5, fn) { return p5.disableFriendlyErrors; }; + Vector._friendlyError = p5._friendlyError; + Vector.friendlyErrorsDisabled = function() { + return p5.disableFriendlyErrors; + }; + /** * The x component of the vector * @type {Number} diff --git a/test/unit/math/p5.Vector.js b/test/unit/math/p5.Vector.js index bbe7c38a5b..5ed0239f40 100644 --- a/test/unit/math/p5.Vector.js +++ b/test/unit/math/p5.Vector.js @@ -2220,4 +2220,12 @@ suite('p5.Vector', function () { ]); }); }); + + suite('p5.Vector.equals() [CLASS]', function () { + it('should trigger friendly error if first parameter is not a vector or array', function () { + FESCalled = false; + Vector.equals(1, new Vector(1, 2)); + assert.isTrue(FESCalled, 'Friendly error should have been triggered'); + }); + }); });