Last active
October 24, 2018 12:40
-
-
Save heestand-xyz/609e49f9aedd5e9bcb6888ef60cc1492 to your computer and use it in GitHub Desktop.
Range
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
func range(_ val: CGFloat, low: CGFloat, high: CGFloat, clamp: Bool = true, toLow: CGFloat = 0.0, toHigh: CGFloat = 1.0) -> CGFloat { | |
var norm = (val - low) / (high - low) | |
if clamp { norm = min(max(norm, 0.0), 1.0) } | |
return toLow + norm * (toHigh - toLow) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment