-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoints.py
45 lines (31 loc) · 974 Bytes
/
points.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import annotations
class Point:
"""
A 2D point.
"""
def __init__(self, x: float, y: float):
self.x = x
self.y = y
def not_operator(self) -> Point:
return Point(self.x, 1 - self.y)
def __str__(self):
return f"P({self.x};{self.y})"
def __repr__(self):
return self.__str__()
def __mul__(self, other):
return self.__class__(self.x, self.y * other)
def __imul__(self, other):
self.y *= other
return self
def __eq__(self, other):
return self.x == other.x and self.y == other.y
def __ne__(self, other):
return not isinstance(other, Point) or self.x != other.x or self.y != other.y
def __lt__(self, other):
return self.x < other.x
def __le__(self, other):
return self.x <= other.x
def __gt__(self, other):
return self.x > other.x
def __ge__(self, other):
return self.x >= other.x