From 065a8c9124ac535d271e2ad071687f44e8cc8464 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Wed, 16 May 2012 14:17:27 -0700 Subject: [PATCH] Compare equality for colors --- src/colors.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/colors.py b/src/colors.py index fa063a3..4a2b04f 100644 --- a/src/colors.py +++ b/src/colors.py @@ -45,6 +45,16 @@ def rgb(self): def hsv(self): raise NotImplemented + def __eq__(self, other): + self_rgb = self.rgb + other_rgb = other.rgb + return self_rgb.red == other_rgb.red \ + and self_rgb.green == other_rgb.green \ + and self_rgb.blue == other_rgb.blue + + def __ne__(self, other): + return not self.__eq__(other) + def __iter__(self): """ Treat the color object as an iterable to iterate over color values Allows mapping such as: