p5.js
p5.js copied to clipboard
Add friendly warning when p5.Vector.cross() is called on non-3D vectors
Resolves #8925
Changes:
p5.Vector.cross()now emits a non-blocking friendly warning (via_friendlyError) when either vector isn't 3D, since the cross product is only defined in 3D. The result is still computed from the x/y/z components — behavior is otherwise unchanged.- Fixed the two
@exampleblocks incross()'s reference docs, which used 2D vectors and a staletoString()output. They now use 3D vectors and show the correctvector[...]output. - Added unit tests in
test/unit/math/p5.Vector.js:cross()warns for non-3D input (2D and >3D),cross()stays quiet for two 3D vectors, and no-leak guards forangleBetween()andslerp().
Note on the two failing tests (opening as a draft for this reason): angleBetween() and slerp() both call cross() internally on the raw input vectors, so the new warning currently leaks through them for legitimate 2D input. The two no-leak tests are guards that turn green once #8926 (angleBetween) and #8928 (slerp) decouple those methods from cross().
Screenshots of the change: N/A — adds a console warning and fixes reference examples; no visual output change.
PR Checklist
- [x]
npm run lintpasses - [x] [Inline reference] is included / updated
- [x] [Unit tests] are included / updated