If we want to determine the intersection of two given rectangles in the Euclidean surface, there are four possibilities. The intersection is either empty, a point (common vertices), a line segment or a rectangle.

doorsnede rechthoeken

Assignment

Define a class Point with which points in the Euclidean surface with whole co-ordinates can be represented. This class must support the following methods:

Define a class Linesegment that can be used to represent the line segments in the Euclidean surface that have a length larger than zero. This class must support the following methods: 

Definie a class Rectangle with which rectangles can be represented in the Euclidean surface that have an area that is larger than zero. This class must support the following methods: 

Example

>>> p1 = Point(1, 2)
>>> p1
Point(1, 2)
>>> print(p1.x, p1.y)
1 2
>>> p2 = Point(3, 5)
>>> print(p2)
Point(3, 5)
>>> p1 < p2
True
>>> p1.distance(p2)
3.605551275463989

>>> l1 = Linesegment(Point(1,2), Point(3, 4))
>>> l1
Linesegment(Point(1, 2), Point(3, 4))
>>> print(l1.point1, l1.point2)
Point(1, 2) Point(3, 4)
>>> l1.length()
2.8284271247461903
>>> l2 = Linesegment(Point(5, -4), Point(-2, 3))
>>> print(l2)
Linesegment(Point(-2, 3), Point(5, -4))
>>> l2.length()
9.899494936611665
>>> l3 = Linesegment(Point(1,2), Point(1, 2))
Traceback (most recent call last):
AssertionError: line segment must have length larger than zero

>>> r1 = Rectangle(Point(1, 1), Point(4, 4))
>>> r1
Rectangle(Point(1, 1), Point(4, 4))
>>> r1.area()
9
>>> r2 = Rectangle(Point(6, 3), Point(3, 6))
>>> r3 = Rectangle(Point(6, 3), Point(4, 2))
>>> print(r3)
Rectangle(Point(4, 2), Point(6, 3))
>>> r3.area()
2
>>> r4 = Rectangle(Point(-7, -3), Point(1, 1))
>>> r1.intersection(r2)
Rectangle(Point(3, 3), Point(4, 4))
>>> r1.intersection(r3)
Linesegment(Point(4, 2), Point(4, 3))
>>> r2.intersection(r3)
Linesegment(Point(4, 3), Point(6, 3))
>>> r1.intersection(r4)
Point(1, 1)
>>> r5 = Rectangle(Point(1, 1), Point(1, 1))
Traceback (most recent call last):
AssertionError: rectangle must have area larger than zero