Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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