Global Function

remap()

Declaration

func remap(value: Double, start1: Double, stop1: Double, start2: Double, stop2: Double) -> Double

Parameters

value The input value to be re-mapped.
start1 The lower bound of the input range.
stop1 The upper bound of the input range.
start2 The lower bound of the output range.
stop2 The upper bound of the output range.

Returns

Double

Description

Remap a number from one range to another. Numbers outside the input range are not clamped, since out of range can be useful. Example: If the input range is 0 to 1, and output range is 0 to 100. Given the value 0.25, the result 25.0 is returned.

Examples

let a = 0.25
let b = remap(value: a, start1:0.0, stop1: 1.0, start2: 0.0, stop2: 100.0)
// The value of b is 25.0

let v1 = 25.0
let v2 = remap(value: v1, start1:0.0, stop1: 100.0, start2: 1000.0, stop2: 2000.0)
// The value of v2 is 1250.0

Related