Skip to content

warn when heading() is called on a non-2D vector - #9442

Open
adityachoudhury29 wants to merge 2 commits into
processing:mainfrom
adityachoudhury29:fix/8214-heading-2d-warning
Open

adityachoudhury29 wants to merge 2 commits into
processing:mainfrom
adityachoudhury29:fix/8214-heading-2d-warning

Conversation

@adityachoudhury29

@adityachoudhury29 adityachoudhury29 commented Dec 3, 2026 •

Copy link
Copy Markdown

Resolves #8214

Changes:

  • heading() now shows a friendly warning via p5.FES.log when called on a vector that isn't 2D. The return value is unchanged (Math.atan2(this.y, this.x)), so existing sketches behave the same.
  • The static p5.Vector.heading(v) gets the warning too, since it calls v.heading().
  • The warning is skipped when friendly errors are disabled. This guard is needed because FES.log returns undefined when FES is disabled, so calling its result would throw. It uses Vector.friendlyErrorsDisabled(), the same check the constructor uses.
  • heading() is a class method, so it can't reach p5.FES directly. A module-level getFES is pointed at p5.FES when the addon registers, and falls back to a no-op for standalone Vector use.
  • Updated the inline reference for heading() to say it's only defined for 2D vectors.
  • Updated unit tests: the existing heading tests now use 2D vectors, and new tests cover 1D, 3D and 4D vectors, the static form, and disabled friendly errors.

Screenshots of the change: N/A

PR Checklist

@welcome

welcome Bot commented Dec 3, 2026

Copy link
Copy Markdown

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

@adityachoudhury29
adityachoudhury29 force-pushed the fix/8214-heading-2d-warning branch from 4c7f3b0 to 4c265b6 Compare December 3, 2026 15:43
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.

[2.x] Fix dimensional quirk in the heading() method of p5.Vector

1 participant