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

Fix: restrict setHeading() to 2D vectors and add friendly error for others

Open reshma045 opened this issue 2 months ago • 0 comments

Resolves #8215

Changes:

This PR updates the p5.Vector.setHeading() method to support only 2D vectors in alignment with the proposed 2.x design.

  • Added a dimension check in setHeading():
  • If the vector’s z component is nonzero (i.e., not 2D), the method now emits a clear p5._friendlyError() explaining that setHeading() is 2D-only in p5.js 2.x.
  • For 2D vectors (z === 0), heading behavior remains the same, preserving magnitude and rotating in the xy-plane.
  • Keeps compatibility with existing sketches that use setHeading() on true 2D vectors.

PR Checklist

reshma045 avatar Nov 11 '25 06:11 reshma045