本文整理汇总了Python中Function.relativePosition方法的典型用法代码示例。如果您正苦于以下问题:Python Function.relativePosition方法的具体用法?Python Function.relativePosition怎么用?Python Function.relativePosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Function
的用法示例。
在下文中一共展示了Function.relativePosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateReference
# 需要导入模块: import Function [as 别名]
# 或者: from Function import relativePosition [as 别名]
def updateReference(self):
""" Set up the position when the local node move."""
# The node is the center of a local bench mark.
relative_position = Function.relativePosition(self.position, globalvars.me.position)
self.local_position = [
long(relative_position[0] - globalvars.me.position[0]),
long(relative_position[1] - globalvars.me.position[1]),
]
示例2: updatePos
# 需要导入模块: import Function [as 别名]
# 或者: from Function import relativePosition [as 别名]
def updatePos(self, new_pos):
""" update the position of the entity"""
# update position
old_position = self.position
self.position = new_pos
relative_position = Function.relativePosition(self.position, globalvars.me.position)
self.local_position = [
long(relative_position[0] - globalvars.me.position[0]),
long(relative_position[1] - globalvars.me.position[1]),
]
# compute delta
delta_pos = []
delta_pos.append(self.position[0] - old_position[0])
delta_pos.append(self.position[1] - old_position[1])
# update lists
globalvars.me.ccwAdjacents.replace(self)
globalvars.me.distAdjacents.replace(self)
# send message to Media
if globalvars.me.GUIConnected:
stringVar = "POS"
stringVariation = str(delta_pos[0]) + ", " + str(delta_pos[1])
for media in globalvars.me.media.values():
if media.push:
resul = media.thread.modNode(self.id, stringVar, stringVariation)
if not resul:
if (
media.thread.newNode(
self.id,
self.local_position[0],
self.local_position[1],
self.caliber,
self.pseudo,
self.ori,
)
== -1
):
sys.stderr.write("error in modNode updateOri")
if media.addBug():
del globalvars.me.media[media.id]
else:
media.bug = 0
elif resul == -1:
if media.addBug():
del globalvars.me.media[media.id]
else:
media.bug = 0
示例3: confirm
# 需要导入模块: import Function [as 别名]
# 或者: from Function import relativePosition [as 别名]
def confirm(self, pos, ori, ar, ca, pseudo):
""" confirm and update informations: to detect liars"""
self.ok = 1
# update informations about this entity.
self.position = pos
relative_position = Function.relativePosition(self.position, globalvars.me.position)
self.local_position = [
relative_position[0] - globalvars.me.position[0],
relative_position[1] - globalvars.me.position[1],
]
self.awareness_radius = ar
self.pseudo = pseudo
self.caliber = ca
self.ori = ori
# send informations to media
if globalvars.me.GUIConnected:
for media in globalvars.me.media.values():
if media.push:
if (
media.thread.newNode(
self.id, self.local_position[0], self.local_position[1], self.caliber, self.pseudo, self.ori
)
== -1
):
sys.stderr.write("error in newNode " + self.pseudo + "\n")
if media.addBug():
del globalvars.me.media[media.id]
else:
media.bug = 0
# we save a trace of this entity for further connection
globalvars.me.met[(self.host, self.port)] = 1
globalvars.me.nb_met += 1
return 1
示例4: __init__
# 需要导入模块: import Function [as 别名]
# 或者: from Function import relativePosition [as 别名]
def __init__(self, id, host, port, pos, ori, awareness_radius, caliber, pseudo):
""" Create a new Entity and keep information about it"""
# identifier
self.id = id
# network data
self.host = host
self.port = int(port)
# position and relative position
self.position = pos
relative_position = Function.relativePosition(self.position, globalvars.me.position)
self.local_position = [
relative_position[0] - globalvars.me.position[0],
relative_position[1] - globalvars.me.position[1],
]
# awareness radius, caliber, pseudo, orientation
self.awareness_radius = awareness_radius
self.caliber = caliber
self.pseudo = pseudo
self.ori = ori
# two boolean variables indicating that
# we received a message from this entity
self.message_received = 1
# we sent a message to this entity
self.message_sent = 0
# services provided by entity
# {id_service: [desc_service, host, port], ...}
self.services = {}
# boolean confirmation of the accuracy of informations
self.ok = 0