Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/math/Matrices/Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
1 change: 1 addition & 0 deletions src/math/p5.Matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function matrix(p5, fn) {
* console.log("Transformed Vector:", transformedVector.toString());
* }
*/
Matrix.prototype._friendlyError = p5._friendlyError;
p5.Matrix = Matrix;
}

Expand Down
10 changes: 8 additions & 2 deletions src/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -3664,6 +3665,11 @@ function vector(p5, fn) {
return p5.disableFriendlyErrors;
};

Vector._friendlyError = p5._friendlyError;
Vector.friendlyErrorsDisabled = function() {
return p5.disableFriendlyErrors;
};
Comment on lines +3668 to +3671

@perminder-17 perminder-17 Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we are defining the fes in the vector class and here p5._firendlyError is a global static.

What if we don't do this and everywhere in this file wherever this._friendlyError is called we replace it with p5._friendlyError it should work the same and could look a little cleaner?

It's similar to how setHeading() is in this file (line no. 2028)?

what you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, It works perfectly fine in codebase, cleaniness could be maintained and we dont have to create its duplicate method.

I could apply those changes, share ur thoughts on that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do @Ayush4958 thanks!

@Ayush4958 Ayush4958 Jul 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ksen0 @perminder-17
I was trying to implement planned changes in code, but it's throwing rerference p5 is not defined.
because vector sits above that wrapper, any code inside the class methods that tries to say p5._friendlyError will crash the entire library because p5 doesn't exist in that context.

we can go with the implementation I had proposed in PR


/**
* The x component of the vector
* @type {Number}
Expand Down
8 changes: 8 additions & 0 deletions test/unit/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Loading