Skip to content

Commit 4a11290

Browse files
committed
Fix: allow single-arg atan() outside strands; add visual test
1 parent 10a2d43 commit 4a11290

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,10 @@ function shadergenerator(p5, fn) {
16151615
'asin': { args: ['genType'], returnType: 'genType', isp5Function: true },
16161616
'asinh': { args: ['genType'], returnType: 'genType', isp5Function: false },
16171617
'atan': [
1618-
{ args: ['genType'], returnType: 'genType', isp5Function: false },
1619-
{ args: ['genType', 'genType'], returnType: 'genType', isp5Function: false }
1618+
// Single-argument atan is a normal p5 function and should work outside strands
1619+
{ args: ['genType'], returnType: 'genType', isp5Function: true},
1620+
// Two-argument atan(y, x) is GLSL-only and remains strands-only
1621+
{ args: ['genType', 'genType'], returnType: 'genType', isp5Function: false},
16201622
],
16211623
'atanh': { args: ['genType'], returnType: 'genType', isp5Function: false },
16221624
'cos': { args: ['genType'], returnType: 'genType', isp5Function: true },

test/unit/spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ var spec = {
5555
// to omit some for speed if they should only be run manually.
5656
'webgl',
5757
'typography',
58-
'shape_modes'
58+
'shape_modes',
59+
'math'
5960
]
6061
};
6162
document.write(

test/unit/visual/cases/math.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { visualTest, visualSuite } from '../../visual/visualTest.js';
2+
3+
visualSuite('math', () => {
4+
visualTest('atan_outside_strands', async (p5, screenshot) => {
5+
// Ensure no WebGL/strands context is used; call atan directly and draw text
6+
p5.createCanvas(120, 60);
7+
p5.background(255);
8+
p5.fill(0);
9+
const v = p5.atan(0.5);
10+
// Draw the numeric value so visual regression will catch undefined/NaN
11+
p5.textSize(14);
12+
p5.textFont('monospace');
13+
p5.textAlign(p5.LEFT, p5.TOP);
14+
p5.text(`atan(0.5)=${p5.nf(v, 1, 3)}`, 5, 5);
15+
screenshot();
16+
});
17+
});

0 commit comments

Comments
 (0)