Computes an index which wraps around a given maximum value. For values >= 0, this is equals to
val % max. For values < 0, this is equal to
max - (-val) % max
-
Parameters:
-
index - index the value to wrap
-
max - max the maximum value (or modulus)
-
Returns:
-
the wrapped index