def assert_round_trip(self, color, space): """Cycle through all the other colors and convert to them and back and check the results.""" c1 = Color(color).convert(space) for space in SPACES: # Print the color space to easily identify which color space broke. c2 = c1.convert(space) c2.convert(c1.space(), in_place=True) # Catch cases where we are really close to 360 which should wrap to 0 for c in (c1, c2): if isinstance(c._space, Cylindrical): if util.round_half_up(util.no_nan(c.hue), c.PRECISION) == 360: c.hue = 0 # Run rounded string back through parsing in case we hit something like a hue that needs normalization. str1 = Color(c1.to_string(color=True, fit=False)).to_string(color=True, fit=False) str2 = Color(c2.to_string(color=True, fit=False)).to_string(color=True, fit=False) # Print failing results for debug purposes if str1 != str2: print('----- Convert: {} <=> {} -----'.format( c1.space(), space)) print('Original: ', color.to_string(color=True, fit=False)) print(c1.space() + ': ', str1, c1.coords()) print(space + ': ', str2, c2.coords()) assert str1 == str2
def initial_text(self): """Initial text.""" if self.color is not None: return self.color elif len(self.view.sel()) == 1: self.setup_color_class() text = self.view.substr(self.view.sel()[0]) if text: color = None try: color = self.custom_color_class(text, filters=self.filters) except Exception: pass if color is not None: color = Color(color) if color.space() not in util.SRGB_SPACES: color = color.convert("srgb", fit=True) return color.to_string(**util.DEFAULT) return ''