def smart_map_point(s):
'''Map point s to closets point on route conscious of nextStopID'''
#Calculate range of indexes of points to check
half = int(len(points) / 3)
lat, lng, nextStopID = s
print(s)
destination_index = stops[nextStopID]
if (destination_index - half) >= 0: #chuck to check is in higher half
check = [i for i in range(destination_index - half, destination_index)]
else: #chunk to check dips below 0
check = [i for i in range(0, destination_index)]
delta = -(destination_index - half)
check.extend( [i for i in range(len(points) - delta, len(points))])
check.extend([i % len(points) for i in range(destination_index,
destination_index + 3)])
#Actual search
running_min = float("inf")
point_index = None #index of closest point on map
for i in check:
dist = distance(points[i], s).miles
if dist < running_min:
running_min = dist
point_index = i
return point_index
评论列表
文章目录