Most appropriate sub-area of p5.js?
Math
p5.js version
2.x main (4b096e2)
Actual vs expected behavior
The reference for rem() says all components are set to their values modulo the divisor. The 2.x implementation guards each component with > 0, so negative divisors are silently ignored:
new p5.Vector(3, 4, 5).rem(-2); // actual [3, 4, 5], 1.x gave [1, 0, 1]
new p5.Vector(3, 4, 5).rem([-2, 3, -4]); // actual [3, 1, 5], only y reduced
// plain JS: 3 % -2 === 1
1.x applied % for any nonzero divisor (calculateRemainder2D/3D used if (xComponent !== 0), v1.11.3 line 440), so this is a 2.x regression. The zero-skip (division by zero) is the only case that should be skipped.
Steps to reproduce
Outputs above are from executed runs against current main.
Note
I have a one-line-class fix ready (change both > 0 checks to !== 0) with a "negative divisors" test suite. Verified: with > 0 restored both new tests fail with expected 3 to deeply equal 1; with the fix the vector suite passes 211. 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
rem()says all components are set to their values modulo the divisor. The 2.x implementation guards each component with> 0, so negative divisors are silently ignored:1.x applied
%for any nonzero divisor (calculateRemainder2D/3Dusedif (xComponent !== 0), v1.11.3 line 440), so this is a 2.x regression. The zero-skip (division by zero) is the only case that should be skipped.Steps to reproduce
Outputs above are from executed runs against current main.
Note
I have a one-line-class fix ready (change both
> 0checks to!== 0) with a "negative divisors" test suite. Verified: with> 0restored both new tests fail withexpected 3 to deeply equal 1; with the fix the vector suite passes 211. Filing for approval per the contributing guide; will open the PR once approved.