Define a class Point
that can be used to represent points in the two-dimensional Euclidean plane. Two arguments must be passed when creating a new point \((x, y)\) (Point
): i) the \(x\)-coordinate (int
) of the point and ii) the \(y\)-coordinate (int
) of the point.
Define a class Rectangle
that can be used to represent rectangles in the two-dimensional Euclidean plane. Three arguments must be passed when creating a new rectangle (Rectangle
): i) the point \(p\) (Point
) in the top left corner of the rectangle, ii) the width \(w\) (int
) of the rectangle and iii) the height \(h\) (int
) of the rectangle. If it does not hold that \(b,h > 0\), an AssertionError
must be raised with the message invalid rectangle
. Rectangles (Rectangle
) must at least support the following methods:
A method surface_area
that returns the surface area (int
, \(b \times h\)) of the rectangle.
A method circumference
that returns the circumference (int
, \(2(b + h)\)) of the rectangle.
A method bottom_right
that returns the point (Punt
) in the bottom right corner of the rectangle.
A method overlap
that takes a rectangle (Rectangle
). If both rectangles (the rectangle on which the method was called and the rectangle passed as an argument to the method) overlap, the method must return a rectangle (Rectangle
) that represents the overlapping region of the two rectangles. Otherwise, the value None
must be returned.
If a point (Point
) or a rectangle (Rectangle
) is passed to the builtin functions repr
or str
, a string representation (str
) of the point or the rectangle must be returned that reads as a Python expression that creates a point or a rectangle at the same location.
>>> p = Point(3, 4)
>>> p
Point(3, 4)
>>> print(p)
Point(3, 4)
>>> r1 = Rectangle(Point(1, 1), 8, 5)
>>> r2 = Rectangle(Point(2, 3), 9, 2)
>>> r1
Rectangle(Point(1, 1), 8, 5)
>>> print(r2)
Rectangle(Point(2, 3), 9, 2)
>>> r1.surface_area()
40
>>> r1.circumference()
26
>>> r1.bottom_right()
Point(9, 6)
>>> r1.overlap(r2)
Rectangle(Point(2, 3), 7, 2)
>>> r2.overlap(Rectangle(Point(0, 0), 2, 2))
>>> Rectangle(Point(3, 4), -2, 7)
Traceback (most recent call last):
AssertionError: invalid rectangle