Skip to content

Instantly share code, notes, and snippets.

@b0mbie
Created May 8, 2022 15:25
Show Gist options
  • Select an option

  • Save b0mbie/5834583f533d8d07d840918d1b9a8b8a to your computer and use it in GitHub Desktop.

Select an option

Save b0mbie/5834583f533d8d07d840918d1b9a8b8a to your computer and use it in GitHub Desktop.
Circular difference function for Lua
local abs = math.abs
return function (a, b, m)
local diff = b - a
local hm = m * 0.5
if diff > hm then
return diff - m
elseif diff < -hm then
return m + diff
end
return diff
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment