Skip to content

Instantly share code, notes, and snippets.

@bastienrobert
Created January 25, 2021 13:05
Show Gist options
  • Save bastienrobert/4f9c3bd388e00c8da34d855ea29c4b91 to your computer and use it in GitHub Desktop.
Save bastienrobert/4f9c3bd388e00c8da34d855ea29c4b91 to your computer and use it in GitHub Desktop.
Shortest clamped distance
function shorterDirection(cur, next, max) {
const toRight = (next - cur + max) % max
const toLeft = (cur - next + max) % max
return toRight > toLeft ? -toLeft : toRight
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment