Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix atan2 implementation to behave like Javascript Math.atan2 #683

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ted-piotrowski
Copy link

  • 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.

- 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
@ted-piotrowski
Copy link
Author

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

@sojs-coder
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

atan2 is implemented as atan(y/x) in gpu backend
2 participants