Last active
July 17, 2024 09:38
-
-
Save mcichecki/bf8808f123ce342b17058abcca3b5378 to your computer and use it in GitHub Desktop.
Normalized value of CGFloat between two values
This file contains 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
extension BinaryFloatingPoint { | |
/// Returns normalized value for the range between `a` and `b` | |
/// - Parameters: | |
/// - min: minimum of the range of the measurement | |
/// - max: maximum of the range of the measurement | |
/// - a: minimum of the range of the scale | |
/// - b: minimum of the range of the scale | |
func normalize(min: Self, max: Self, from a: Self = 0, to b: Self = 1) -> Self { | |
(b - a) * ((self - min) / (max - min)) + a | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment