Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/webgl/ShaderGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
33 changes: 33 additions & 0 deletions test/unit/math/atan.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion test/unit/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading