Changeset 1578
- Timestamp:
- 07/05/07 12:13:15 (1 year ago)
- Files:
-
- gaphas/trunk/gaphas/geometry.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/gaphas/geometry.py
r1518 r1578 133 133 >>> r=Rectangle(5, 7, 20, 25) 134 134 >>> r + (0, 0) 135 Rectangle(0, 0, 25, 32) 135 Traceback (most recent call last): 136 ... 137 AttributeError: Can only add Rectangle or tuple (x, y, width, height), not (0, 0). 136 138 >>> r + (20, 30, 40, 50) 137 139 Rectangle(5, 7, 55, 73) … … 149 151 Traceback (most recent call last): 150 152 ... 151 AttributeError: Don't know how to handle <type 'str'> aap. Convert to a Rectangle first.152 """ 153 if isinstance(obj, Rectangle) or len(obj) == 4:153 AttributeError: Can only add Rectangle or tuple (x, y, width, height), not 'aap'. 154 """ 155 try: 154 156 x, y, width, height = obj 155 x1, y1 = x + width, y + height 156 elif len(obj) == 2: 157 # extend using a point 158 x, y = obj 159 width, height = 0, 0 160 x1, y1 = obj 161 else: 162 raise AttributeError, "Don't know how to handle %s %s." \ 163 " Convert to a Rectangle first." % (type(obj), obj) 157 except ValueError: 158 raise AttributeError, "Can only add Rectangle or tuple (x, y, width, height), not %s." % repr(obj) 159 x1, y1 = x + width, y + height 164 160 if self: 165 ox1, oy1 = self.x 1, self.y1161 ox1, oy1 = self.x + self.width, self.y + self.height 166 162 self.x = min(self.x, x) 167 163 self.y = min(self.y, y) … … 195 191 Traceback (most recent call last): 196 192 ... 197 AttributeError: Don't know how to handle <type 'str'> aap. Convert to a Rectangle first.198 """ 199 if isinstance(obj, Rectangle) or len(obj) == 4:193 AttributeError: Can only substract Rectangle or tuple (x, y, width, height), not 'aap'. 194 """ 195 try: 200 196 x, y, width, height = obj 201 x1, y1 = x + width, y + height202 else:203 raise AttributeError, "Don't know how to handle %s %s." \204 " Convert to a Rectangle first." % (type(obj), obj) 197 except ValueError: 198 raise AttributeError, "Can only substract Rectangle or tuple (x, y, width, height), not %s." % repr(obj) 199 x1, y1 = x + width, y + height 200 205 201 if self: 206 ox1, oy1 = self.x 1, self.y1202 ox1, oy1 = self.x + self.width, self.y + self.height 207 203 self.x = max(self.x, x) 208 204 self.y = max(self.y, y) … … 238 234 Traceback (most recent call last): 239 235 ... 240 AttributeError: Don't know how to handle <type 'str'> aap. Convert to a Rectangle or tuple first.241 """ 242 if isinstance(obj, Rectangle) or len(obj) == 4:236 AttributeError: Should compare to Rectangle, tuple (x, y, width, height) or point (x, y), not 'aap'. 237 """ 238 try: 243 239 x, y, width, height = obj 244 240 x1, y1 = x + width, y + width 245 e lif len(obj) == 2:241 except ValueError: 246 242 # point 247 x, y = obj248 x1, y1= obj249 else:250 raise AttributeError, "Don't know how to handle %s %s." \251 " Convert to a Rectangle or tuple first." % (type(obj),obj)243 try: 244 x, y = obj 245 x1, y1 = obj 246 except ValueError: 247 raise AttributeError, "Should compare to Rectangle, tuple (x, y, width, height) or point (x, y), not %s." % repr(obj) 252 248 return x >= self.x and x1 <= self.x1 and \ 253 249 y >= self.y and y1 <= self.y1
