Created
May 8, 2022 15:25
-
-
Save b0mbie/5834583f533d8d07d840918d1b9a8b8a to your computer and use it in GitHub Desktop.
Circular difference function for Lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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