gpu.js icon indicating copy to clipboard operation
gpu.js copied to clipboard

Fix atan2 implementation to behave like Javascript Math.atan2

Open ted-piotrowski opened this issue 3 years ago • 2 comments

  • Previous implementation returned values in -PI/2 to PI/2 range even though Javascript returns in -PI to PI range
  • Add unit tests covering edge cases

Fixes #647

Previously the following cases failed:

Math.atan2(1, 0);
Math.atan2(-1,0);
Math.atan(0,-1);

According to MDN Math.atan2(y, x) returns a value between -PI and PI. According to OpenGL atan(y / x) returns a value between -PI/2 and PI/2 while atan(y, x) returns a value between -PI and PI.

The main fix was to change the atan signature to take (y, x) instead of (y / x) and then to handle the cases Math.atan2(-1, 0), Math.atan2(1, 0), Math.atan(0, 0) because in OpenGL atan is undefined when x = 0 but defined in Javascript.

Note: atan arguments are passed y first and then x. This caused me some confusion at first.

ted-piotrowski avatar Mar 23 '21 20:03 ted-piotrowski

@robertleeplummerjr I noticed you've been active on this project again. What are your thoughts on merging this fix?

ted-piotrowski avatar Jan 23 '23 18:01 ted-piotrowski

@robertleeplummerjr @ted-piotrowski any update on merging this fix? this issue I believe relies on it.

sojs-coder avatar Dec 16 '23 22:12 sojs-coder