diff --git a/src/webgl/ShaderGenerator.js b/src/webgl/ShaderGenerator.js index 2e716ce39f..506a880537 100644 --- a/src/webgl/ShaderGenerator.js +++ b/src/webgl/ShaderGenerator.js @@ -1615,8 +1615,10 @@ function shadergenerator(p5, fn) { 'asin': { args: ['genType'], returnType: 'genType', isp5Function: true }, 'asinh': { args: ['genType'], returnType: 'genType', isp5Function: false }, 'atan': [ - { args: ['genType'], returnType: 'genType', isp5Function: false }, - { args: ['genType', 'genType'], returnType: 'genType', isp5Function: false } + // Single-argument atan is a normal p5 function and should work outside strands + { args: ['genType'], returnType: 'genType', isp5Function: true}, + // Two-argument atan(y, x) is GLSL-only and remains strands-only + { args: ['genType', 'genType'], returnType: 'genType', isp5Function: false}, ], 'atanh': { args: ['genType'], returnType: 'genType', isp5Function: false }, 'cos': { args: ['genType'], returnType: 'genType', isp5Function: true }, diff --git a/test/unit/math/atan.js b/test/unit/math/atan.js new file mode 100644 index 0000000000..19a14e4664 --- /dev/null +++ b/test/unit/math/atan.js @@ -0,0 +1,33 @@ +import trigonometry from '../../../src/math/trigonometry.js'; +import { assert } from 'chai'; + +suite('atan', function() { + const mockP5 = { + RADIANS: 'radians', + DEGREES: 'degrees', + _validateParameters: () => {} + }; + const mockP5Prototype = {}; + + beforeEach(function() { + mockP5Prototype._angleMode = mockP5.RADIANS; + mockP5Prototype.angleMode = function(mode) { + this._angleMode = mode; + }; + trigonometry(mockP5, mockP5Prototype); + }); + + test('should return the correct value for atan(0.5) in radians', function() { + mockP5Prototype.angleMode(mockP5.RADIANS); + const expected = 0.4636476090008061; // pre-calculated value + const actual = mockP5Prototype.atan(0.5); + assert.closeTo(actual, expected, 1e-10); + }); + + test('should return the correct value for atan(0.5) in degrees', function() { + mockP5Prototype.angleMode(mockP5.DEGREES); + const expected = 26.56505117707799; // pre-calculated value + const actual = mockP5Prototype.atan(0.5); + assert.closeTo(actual, expected, 1e-10); + }); +}); diff --git a/test/unit/spec.js b/test/unit/spec.js index fd9bbc759f..7dd87068a7 100644 --- a/test/unit/spec.js +++ b/test/unit/spec.js @@ -55,7 +55,7 @@ var spec = { // to omit some for speed if they should only be run manually. 'webgl', 'typography', - 'shape_modes' + 'shape_modes', ] }; document.write(