-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpath.py
27 lines (22 loc) · 848 Bytes
/
path.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
class Path:
"""A list of points representing a path."""
def __init__(self,points):
"""Intialise the path object."""
self.points = points
def getNearestWaypoint(self,p):
"""Return the index of the nearest waypoint on this path to arbitrary
point p."""
nearest = 0
d = (p-self.points[nearest]).length()
for index,point in enumerate(self.points[1:]):
if (p-point).length() < d:
nearest = index+1
d = (p-point).length()
return nearest
# FIXME: This class should probably extend the standard list class
def __getitem__(self,key):
return self.points[key]
def __setitem__(self,key,value):
self.points[key]=value
def __len__(self):
return len(self.points)