-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.py
More file actions
32 lines (23 loc) · 928 Bytes
/
point.py
File metadata and controls
32 lines (23 loc) · 928 Bytes
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
class Point:
def __init__(self, points):
self.points = points
def __sub__(self, other):
array_of_substracted_points = []
for i in range(len(self.points)):
array_of_substracted_points.append(self.points[i] - other[i])
return Point(array_of_substracted_points)
def distance_from_origin(self):
sum_of_squares_by_index = 0
for x in self.points:
sum_of_squares_by_index += x*x
return sum_of_squares_by_index
def distance_from_point(self, other):
temp_point = Point(self.points.copy())
temp_point = Point(temp_point - other)
return temp_point.distance_from_origin()
def array_form(self):
return self.points
def __getitem__(self, index):
return self.points[index]
def __lt__(self, other):
return self.distance_from_origin() < other.distance_from_origin()