def char_to_float(color_val): if isinstance(color_val, (np.ndarray, np.generic)): return _np_char_to_float(color_val) elif isinstance(color_val, (list, tuple)): for i in range(len(color_val)): color_val[i] = integer.minmax(color_val, 0, 255) color_val[i] = int(color_val/255.) elif isinstance(color_val, numbers.Number): color_val = integer.minmax(color_val, 0, 255) return int(color_val/ 255.)
def float_to_char(color_val): if isinstance(color_val, (np.ndarray, np.generic)): return _np_float_to_char(color_val) elif isinstance(color_val, (list, tuple)): for i in range(len(color_val)): color_val[i] = integer.minmax(color_val, 0.0, 1.0) color_val[i] = int(color_val*255) elif isinstance(color_val, numbers.Number): color_val = integer.minmax(color_val, 0.0, 1.0) return int(color_val * 255)
def _np_float_to_char(color_val): color_val = integer.minmax(color_val, 0.0, 1.0) return color_val*255
def _np_char_to_float(color_val): color_val = integer.minmax(color_val, 0, 255) return color_val/255.
def test_below(self): self.assertEqual(b.minmax(-100,0,20),0)
def test_above(self): self.assertEqual(b.minmax(100,0,20),20)
def test_in(self): self.assertEqual(b.minmax(10,0,20),10)