a7_2a.py

import a7_1a

class Rectangle(a7_1a.Rectangle):
	"""Rectangle that supports + operator.
	"""

	def __add__(self, other):
		x = min(self.corner.x, other.corner.x)
		y = min(self.corner.y, other.corner.y)
		mx = max(self.corner.x + self.width,
				other.corner.x + other.width)
		my = max(self.corner.y + self.height,
				other.corner.y + other.height)
		width = mx - x
		height = my - y
		return Rectangle(x, y, width, height)

if __name__ == "__main__":
	r1 = Rectangle(10, 20, 10, 10)
	r2 = Rectangle(20, 50, 15, 20)
	print r1 + r2