-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinate.py
More file actions
56 lines (47 loc) · 1.23 KB
/
coordinate.py
File metadata and controls
56 lines (47 loc) · 1.23 KB
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
46
47
48
49
50
51
52
53
54
55
56
class Coordinate:
"""
Represents a (x,y) coordinate
"""
def __init__(self, x, y):
"""
Constructs a Coordinate
x: the position on the x-axis
y: the position on the y-axis
"""
self._x = x
self._y = y
def getX(self):
"""
returns: the x coordinate
"""
return self._x
def getY(self):
"""
returns: the y coordinate
"""
return self._y
def setX(self, x):
"""
sets the x coordinate
"""
self._x = x
def setY(self, y):
"""
sets the y coordinate
"""
self._y = y
def distance(self, other):
"""
returns: the distance to another coordinate
"""
if isinstance(other, tuple) :
return ((self._x - other[0])**2 + (self._y - other[1])**2)**0.5
elif isinstance(other, Coordinate):
return ((self._x - other.getX())**2 + (self._y - other.getY())**2)**0.5
else:
raise ValueError('Not a valid Coordinate')
def __str__(self):
"""
returns: a String representation of the coordinate
"""
return '(' + str(self._x) + ',' + str(self._y) + ')'