p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Add friendly warning when p5.Vector.cross() is called on non-3D vectors

Open harshiltewari2004 opened this issue 5 months ago • 0 comments

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 @example blocks in cross()'s reference docs, which used 2D vectors and a stale toString() output. They now use 3D vectors and show the correct vector[...] 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 for angleBetween() and slerp().

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 lint passes
  • [x] [Inline reference] is included / updated
  • [x] [Unit tests] are included / updated

harshiltewari2004 avatar Jun 19 '26 16:06 harshiltewari2004