Added equality method to compare two geometries
authorThierry Florac <tflorac@ulthar.net>
Tue, 05 Feb 2019 09:38:25 +0100
changeset 174 d49bcf382187
parent 173 a68e640a4089
child 175 ab573883a5c7
Added equality method to compare two geometries
src/pyams_file/image.py
--- a/src/pyams_file/image.py	Tue Feb 05 09:37:43 2019 +0100
+++ b/src/pyams_file/image.py	Tue Feb 05 09:38:25 2019 +0100
@@ -19,11 +19,10 @@
 from zope.interface import implementer
 from zope.schema.fieldproperty import FieldProperty
 
+from pyams_file import _
 from pyams_file.interfaces import IImage, IResponsiveImage, IThumbnailGeometry, IThumbnailer, IThumbnails
 from pyams_utils.adapter import ContextAdapter, adapter_config
 
-from pyams_file import _
-
 
 WEB_FORMATS = ('JPEG', 'PNG', 'GIF')
 THUMB_SIZE = re.compile('^(?:\w+\:)?([0-9]+)x([0-9]+)$')
@@ -41,6 +40,15 @@
     def __repr__(self):
         return '<ThumbnailGeometry: x1,y1={0.x1},{0.y1} - x2,y2={0.x2},{0.y2}>'.format(self)
 
+    def __eq__(self, other):
+        if IThumbnailGeometry.providedBy(other):
+            return (self.x1 == other.x1) and \
+                   (self.x2 == other.x2) and \
+                   (self.y1 == other.y1) and \
+                   (self.y2 == other.y2)
+        else:
+            return False
+
 
 @adapter_config(context=IImage, provides=IThumbnailer)
 class ImageThumbnailer(ContextAdapter):