[][src]Function fart_utils::map_range

pub fn map_range<N, M>(
    value: N,
    Range { start: in_low, end: in_high }: Range<N>,
    Range { start: out_low, end: out_high }: Range<M>
) -> M where
    N: Num + NumCast + Copy + PartialOrd,
    M: Num + NumCast + Copy + PartialOrd

Map a value from one range to another range.

Example

let x = map_range(5, 0..10, 0..100);
assert_eq!(x, 50);

let y = map_range(3, 2..5, 0..3);
assert_eq!(y, 1);

Panics

Panics if the given value is outside the input range, if in_low >= in_high, or if out_low >= out_high, or if number conversions fail.