Function fractal_analysis::create_normaliser [−][src]
pub fn create_normaliser<Input, Coordinate>(
minimum: Input,
maximum: Input
) -> Option<impl Fn(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 a minimum and maximum value, inclusive and exclusive respectively, and returns a function to normalise values to the limits of the coordinate data-type it’s given.
let norm_fn = create_normaliser::<u32, u8>(0u32, 8192).unwrap(); assert_eq!(norm_fn(31), 0); assert_eq!(norm_fn(32), 1); assert_eq!(norm_fn(250), 7);
Please note:
- This function returns
None
ifmaximum * (Coordinate::MAX + 1)
overflows. - The output function will return a zero if given a value that’s outside bounds.