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
6 changes: 6 additions & 0 deletions src/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3571,6 +3571,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 @@ -3660,6 +3661,11 @@ function vector(p5, fn) {
return p5.disableFriendlyErrors;
};

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

@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!

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 methods are completely blind to the p5, p5 instance introduced at bottom when it gets wrapped in vector func. 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 @@ -2189,4 +2189,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');
});
});
});