processing / processing/p5.js

[p5.js 2.0+ Bug Report]: setHeading() ignores angleMode(), a 1.x regression, and its 3D guard is dead code

Open
#9,131 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sub-area of p5.js?

Math

p5.js version

2.x main (4b096e2)

Actual vs expected behavior

The reference for p5.Vector.setHeading() promises it "uses the units of the current angleMode()", with an example asserting angleMode(DEGREES); v.setHeading(180) prints 180. The 2.x implementation never converts the input:

angleMode(DEGREES);
const v = createVector(0, 1);
v.setHeading(180);
v.heading(); // actual -126.75968764518224, documented 180
rotate(90);  // works correctly on the same setup, showing the inconsistency

p5 1.x (v1.11.3, line 2231) has if (this.isPInst) a = this._toRadians(a);, the fix for #5497, so this is a straight 2.x regression.

Secondary defect in the same function: the 2D guard merged in #8255 reads this._values, which does not exist (the property is values), so it never fires. new p5.Vector(1, 1, 5).setHeading(PI/4) silently mangles x and y with no friendly error, and the guard's p5._friendlyError is a bare reference that would throw a ReferenceError in module builds if it were ever reached. #8215 (open) discusses restricting setHeading to 2D and its last comment notices the guard misbehaving; this report is primarily about the angleMode regression.

Steps to reproduce

Outputs above are from executed runs against current main via the unit test harness.

Note

I have a fix ready (add the _toRadians conversion, correct the guard to values and this._friendlyError) with 5 unit tests replacing the two suite.todo setHeading suites. Verified: removing the conversion fails 2 tests with expected 57.29577951308232 to be close to 1, and restoring the _values typo fails the guard test; full vector suite passes 214 with the fix. Filing for approval per the contributing guide; will open the PR once approved.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at p5.Vector.setHeading() and inspect the existing setHeading unit-test suites in the unit test harness. Reproduce the angleMode(DEGREES) and 3D-vector cases, then run the vector suite; done means angle units are respected, the 2D guard reports the intended error, and all vector tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.