1.2 – Wrapping
So you want your value to be within a particular range, but instead of clamping when it gets outside that range, you want it to repeat back to the beginning of the range?
Now that's as simple as calling .wrapped(within:) on any number!
value.wrapped(within: range)This loops the number within the range, like this:
Here's a code example of how this works:
print(0.wrapped(within: 3..<6)) // 3
print(1.wrapped(within: 3..<6)) // 4
print(2.wrapped(within: 3..<6)) // 5
print(3.wrapped(within: 3..<6)) // 3
print(4.wrapped(within: 3..<6)) // 4
print(5.wrapped(within: 3..<6)) // 5
print(6.wrapped(within: 3..<6)) // 3
print(7.wrapped(within: 3..<6)) // 4
print(8.wrapped(within: 3..<6)) // 5Patches
1.2.1• #10 • Fixed compiler error when archiving

