-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
closest orthagonal distance function #426
Conversation
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Wait a second. There are a few cosmetic issues. It is 'orthOgonal', not 'orthAgonal'. Also, |
Isn't this just return vec2(this.x < 0 ? left : right, this.y < 0 ? up : down) ? |
Not quite. It does the orthogonal direction closest to the angle of this, so say if you have vec2(-1, -10) it will return UP not LEFT. Since it is only 4 candidates, I suspect it can be done with a bunch of conditionals, however, it made more sense to use a loop to me. 🤷 It might be faster to use conditionals, but until this function is used somewhere I really can't say. |
So return Math.abs(this.x) > Math.abs(this.y) ? Two conditionals will always be faster than calculating 4 square roots (which weren't really needed, the dot product is enough to compare distances). |
@mflerackers' suggestion kaplayjs#426 (comment)
idk this might be useful?