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.
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 assertingangleMode(DEGREES); v.setHeading(180)prints 180. The 2.x implementation never converts the input: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 isvalues), 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'sp5._friendlyErroris 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
_toRadiansconversion, correct the guard tovaluesandthis._friendlyError) with 5 unit tests replacing the twosuite.todosetHeading suites. Verified: removing the conversion fails 2 tests withexpected 57.29577951308232 to be close to 1, and restoring the_valuestypo 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.