Skip to content

Commit 166a48a

Browse files
committed
final (thanks @ted-piotrowski)
1 parent 63d4d1e commit 166a48a

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

src/backend/web-gl2/fragment-shader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ __CONSTANTS__;
1414
in vec2 vTexCoord;
1515
1616
float atan2(float v1, float v2) {
17-
if (v1 == 0.0 || v2 == 0.0) return 0.0;
18-
return atan(v1 / v2);
17+
if (v2 == 0.0) {
18+
if (v1 == 0.0) return 0.0;
19+
if (v1 > 0.0) return 1.5707963267948966;
20+
if (v1 < 0.0) return -1.5707963267948966;
21+
}
22+
return atan(v1, v2);
1923
}
2024
2125
float cbrt(float x) {

test/all.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@
9191
<script type="module" src="features/raw-output.js"></script>
9292
<script type="module" src="features/read-color-texture.js"></script>
9393
<script type="module" src="features/read-from-texture.js"></script>
94-
<script type="module" src="features/read-image-bitmap.js"></script>
95-
<script type="module" src="features/read-image-data.js"></script>
96-
<script type="module" src="features/read-offscreen-canvas.js"></script>
9794
<script type="module" src="features/return-arrays.js"></script>
9895
<script type="module" src="features/single-precision-textures.js"></script>
9996
<script type="module" src="features/single-precision.js"></script>
@@ -183,6 +180,7 @@
183180
<script type="module" src="issues/585-inaccurate-lookups.js"></script>
184181
<script type="module" src="issues/586-unable-to-resize.js"></script>
185182
<script type="module" src="issues/608-rewritten-arrays.js"></script>
183+
<script type="module" src="issues/647-atan2-range.js"></script>
186184
<script type="module" src="issues/91-create-kernel-map-array.js"></script>
187185
<script type="module" src="issues/96-param-names.js"></script>
188186
<script type="module" src="features/to-string/as-file.js"></script>
@@ -325,4 +323,4 @@
325323
<script type="module" src="features/to-string/precision/unsigned/kernel-map/object/memory-optimized-number-texture.js"></script>
326324
<script type="module" src="features/to-string/precision/unsigned/kernel-map/object/number-texture.js"></script>
327325
</body>
328-
</html>
326+
</html>

test/issues/647-atan2-range.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { assert, skip, test, module: describe } = require('qunit');
2+
const { GPU } = require('../../src');
3+
4+
describe('issue #647');
5+
6+
function buildAtan2KernelResult(mode) {
7+
const gpu = new GPU({ mode });
8+
const kernel = gpu.createKernel(function (x, y) {
9+
return Math.atan2(y[this.thread.x], x[this.thread.x]);
10+
}, {
11+
output: [5],
12+
});
13+
14+
// test atan2 at center, E, N, W, S on unit circle
15+
// [0,0] [1,0], [0, 1], [-1, 0], [0, -1]
16+
const x = [0, 1, 0, -1, 0];
17+
const y = [0, 0, 1, 0, -1];
18+
const result = kernel(x, y);
19+
20+
assert.equal(result[0].toFixed(7), 0.0000000);
21+
assert.equal(result[1].toFixed(7), 0.0000000);
22+
assert.equal(result[2].toFixed(7), 1.5707964);
23+
assert.equal(result[3].toFixed(7), 3.1415927);
24+
assert.equal(result[4].toFixed(7), -1.5707964);
25+
gpu.destroy();
26+
}
27+
28+
test('Issue #647 atan2 - auto', () => {
29+
buildAtan2KernelResult();
30+
});
31+
32+
test('Issue #647 atan2 - gpu', () => {
33+
buildAtan2KernelResult('gpu');
34+
});
35+
36+
(GPU.isWebGLSupported ? test : skip)('Issue #647 atan2 - webgl', () => {
37+
buildAtan2KernelResult('webgl');
38+
});
39+
40+
(GPU.isWebGL2Supported ? test : skip)('Issue #647 atan2 - webgl2', () => {
41+
buildAtan2KernelResult('webgl2');
42+
});
43+
44+
(GPU.isHeadlessGLSupported ? test : skip)('Issue #647 atan2 - headlessgl', () => {
45+
buildAtan2KernelResult('headlessgl');
46+
});
47+
48+
test('Issue #647 atan2 - cpu', () => {
49+
buildAtan2KernelResult('cpu');
50+
});

0 commit comments

Comments
 (0)