diff --git a/src/math/Matrices/Matrix.js b/src/math/Matrices/Matrix.js index 18545759bb..8676fc5cd1 100644 --- a/src/math/Matrices/Matrix.js +++ b/src/math/Matrices/Matrix.js @@ -249,7 +249,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 e59c3582f6..76a8797c4d 100644 --- a/src/math/p5.Vector.js +++ b/src/math/p5.Vector.js @@ -2019,12 +2019,10 @@ class Vector { * } */ setHeading(a) { - if ( - this.dimensions < 2 || - (this._values instanceof Array && - this._values.slice(2).some(v => v !== 0)) + if (this.dimensions < 2 || ( + 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.', @@ -3666,6 +3664,7 @@ class Vector { 'The v1 parameter should be of type Array or p5.Vector', 'p5.Vector.equals' ); + return false; } return v.equals(v2); } @@ -3755,6 +3754,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 ebc6bc0b1e..3130b55b25 100644 --- a/test/unit/math/p5.Vector.js +++ b/test/unit/math/p5.Vector.js @@ -2373,4 +2373,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'); + }); + }); });