本文整理汇总了Python中map.Map.get_node_by_location_name方法的典型用法代码示例。如果您正苦于以下问题:Python Map.get_node_by_location_name方法的具体用法?Python Map.get_node_by_location_name怎么用?Python Map.get_node_by_location_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类map.Map
的用法示例。
在下文中一共展示了Map.get_node_by_location_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get_node_by_location_name [as 别名]
def __init__(self, building, level, start, end):
self.building = building
self.level = level
self.start = start
self.end = end
startPoint = Map.get_node_by_location_name(building, level, start)
self.pos = [float(startPoint["x"]), float(startPoint["y"])]
self.nextLoc = {}
self.prevLoc = startPoint
self.isGivingIdInstruction = True
self.reachedLoc = []
self.reachedLoc.append(start)
self.spokenList = []
self.spokenList.append(start)
示例2: is_reach_location
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get_node_by_location_name [as 别名]
def is_reach_location(self, location_name, x, y):
"""current x, and current y"""
node = Map.get_node_by_location_name(self.building,
self.level, location_name)
return self.is_reach_node(node, x, y)
示例3: get_next_location
# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get_node_by_location_name [as 别名]
def get_next_location(self, x, y):
"""
params: current x, and current y
get the nearest node, and based on it, decide the next location
"""
route = self.get_route()
routeLength = len(route)
# base cases:
if routeLength == 1:
return Map.get_node_by_location_name(self.building, self.level, route[0])
elif routeLength == 2:
return Map.get_node_by_location_name(self.building, self.level, route[1])
minDist = sys.maxint
minDistNode = {}
routeIdxOfMinDistNode = -1
# get the nearest node
idx = 0
for location_name in route:
node = Map.get_node_by_location_name(self.building,
self.level, location_name)
distance = Map.get_distance(node["x"], x, node["y"], y)
if distance < minDist:
minDist = distance
minDistNode = node
routeIdxOfMinDistNode = idx
idx += 1
# decide the next location to return
if routeIdxOfMinDistNode == 0:
# if the nearest node is at the start point
# return next node
return Map.get_node_by_location_name(self.building,
self.level, route[1])
elif routeIdxOfMinDistNode == routeLength - 1:
# if is at the end point
# return end node
return minDistNode
else:
# is at point between start & end
# prevNode ----- minDistNode (nearest node) ----- nextNode
prevNode = Map.get_node_by_location_name(self.building, self.level,
route[routeIdxOfMinDistNode - 1])
nextNode = Map.get_node_by_location_name(self.building, self.level,
route[routeIdxOfMinDistNode + 1])
prevDist = Map.get_distance(prevNode["x"], x, prevNode["y"], y)
nextDist = Map.get_distance(nextNode["x"], x, nextNode["y"], y)
if nextDist <= prevDist:
# if nearer to the next node
if minDistNode["nodeName"] in self.reachedLoc:
return nextNode
else:
return minDistNode
else:
# nextDist > prevDist -- nearer to the previous node
if self.is_reach_node(minDistNode, x, y):
# already reached the nearest node
# return next node
return nextNode
else:
# else return the nearest node
if minDistNode["nodeName"] in self.reachedLoc:
return nextNode
else:
return minDistNode