Function fractal_analysis::normalise[][src]

pub fn normalise<Input, Coordinate>(
    x: Input,
    minimum: Input,
    maximum: Input
) -> Coordinate where
    Input: Add<Output = Input> + Sub<Output = Input> + Div<Output = Input> + TryInto<Coordinate> + CheckedShl + CheckedSub + Copy,
    Coordinate: Zero

A convenience function that takes an arbitrary value, along with its minimum and maximum value, and normalises it to the limits of the coordinate data-type it’s given.

let x = 1024u32;
let norm_x: u8 = normalise(x, 0, 65536);
assert_eq!(norm_x, 4);

Please bear in mind:

  1. This function assumes that the minimum will be inclusive and the maximum exclusive.
  2. This function will silently return a zero if maximum * (Coordinate::MAX + 1) overflows, or if the value provided is outside minimum..maximum.