Skip to content

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

Draft
harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:vector-cross-fes-warning
Draft

Add friendly warning when p5.Vector.cross() is called on non-3D vectors#8944
harshiltewari2004 wants to merge 1 commit into
processing:mainfrom
harshiltewari2004:vector-cross-fes-warning

Conversation

@harshiltewari2004

Copy link
Copy Markdown
Contributor

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

  • npm run lint passes
  • [Inline reference] is included / updated
  • [Unit tests] are included / updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[p5.js 2.0+ Bug Report]: Vector.cross() assumes the vectors have three dimensions

1 participant