Last active
July 27, 2016 12:08
-
-
Save arashkashi/62a6f047fad51e0b76cd80e632231664 to your computer and use it in GitHub Desktop.
maps a range of input to a range of output
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
import Cocoa | |
var str = "Hello, playground" | |
typealias LinearEquation = Double -> Double | |
func getLinearEquation(inp: (min: Double, max: Double), | |
out: (min: Double, max: Double)) -> LinearEquation { | |
let m = (out.max - out.min) / (inp.max - inp.min) | |
let b = out.max - m * inp.max | |
return { | |
$0 * m + b | |
} | |
} | |
let linearmap = getLinearEquation((3, 5), out: (20, 60)) | |
linearmap(3) | |
linearmap(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment