本文整理汇总了Python中utils.vector_add函数的典型用法代码示例。如果您正苦于以下问题:Python vector_add函数的具体用法?Python vector_add怎么用?Python vector_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了vector_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_mouse_move
def on_mouse_move(self, event, position):
if self.scroll_point:
change = utils.make_vector(position, self.scroll_point)
self.canvas.set_viewport(
utils.vector_add(self.canvas.get_viewport(), change))
return
if self.drag_items:
change = utils.make_vector(self.drag_mouse_origin, position)
for i, item in enumerate(self.drag_items):
new_position = utils.vector_add(self.drag_items_origin[i], change)
new_position = utils.snap_to_grid(new_position, self.grid_size)
item.set_position(new_position)
self.canvas.redraw()
return
item = self.get_item_at_position(position)
if item:
self.canvas.set_cursor(get_cursor(item.action))
if self.selection:
self.mouseover_items = item.get_group()
self.set_highlight()
elif self.mouseover_items:
self.canvas.set_cursor(None)
self.mouseover_items = []
self.set_highlight()
else:
self.canvas.set_cursor(None)
示例2: add_extra_simrun_items
def add_extra_simrun_items(self, items):
def text_fn(text, item, attr):
return lambda: ("{0}: {1}".format(text,
getattr(item, attr)),)
for item in self.net.transitions():
box_position = item.box.get_position()
if item.get_time_substitution():
size = item.box.size
position = utils.vector_add_t(box_position, size, 0.5)
i = citems.SimRunLabel(
None, "simrunbox", citems.RelativePlacement(item.box, position))
i.text_fn = text_fn("time", item, "time_substitution_code")
items.append(i)
box_position = utils.vector_add(box_position, (0, 20))
if item.get_clock_substitution():
size = item.box.size
position = utils.vector_add_t(box_position, size, 0.5)
i = citems.SimRunLabel(
None, "simrunbox", citems.RelativePlacement(item.box, position))
i.text_fn = text_fn("clock", item, "clock_substitution_code")
items.append(i)
for item in self.net.edges():
if item.get_size_substitution():
position = utils.vector_add(item.inscription.get_position(), (0, 10))
i = citems.SimRunLabel(
None, "simrunbox", citems.RelativePlacement(item.inscription, position))
i.text_fn = text_fn("size", item, "size_substitution_code")
items.append(i)
示例3: get_packet_items
def get_packet_items(self):
def get_size(self, cr):
if not self.texts:
return
tx = max(utils.text_size(cr, t)[0] for t in self.texts)
tx += 20
ty = 13 * len(self.texts) + 4
return (tx, ty)
result = []
color = (0.8, 0.3, 0.1, 0.85)
color_active = (1, 1, 1)
color_inactive = (0.8, 0.8, 0.8)
for edge in self.perspective.runinstance.net.edges_out():
packets = self.perspective.get_packets_info(edge.id)
packet_box = self.packet_boxes.get(edge.id)
if packet_box is None:
position = utils.vector_add(edge.inscription.get_position(),
(0, 15))
placement = citems.AbsPlacement(position)
packet_box = citems.Box(None,
"packetbox",
placement)
packet_box.size_fn = get_size
packet_box.background = color
packet_box.radius = 5
self.packet_boxes[edge.id] = packet_box
result.append(packet_box)
packet_box.texts = [ p[3] for p in packets ]
for i, (process_id, origin_id, top, text) in enumerate(packets):
position = utils.vector_add(packet_box.get_position(),
(10, 13 * i))
t = citems.Text(
None,
"packet",
packet_box.get_relative_placement(position),
text)
if top:
t.color = color_active
t.packet_data = (process_id, origin_id)
else:
t.color = color_inactive
t.packet_data = None
t.padding_y = 4
t.z_level = 15
t.action = None
result.append(t)
return result
示例4: solve_move
def solve_move(self, ntuple):
print('mock solver: begin move')
world = self.world
home_pos = world.robot1_instance.pos
for parameters in ntuple.parameters:
acted_upon = parameters.acted_upon
heading = parameters.heading
direction = parameters.direction
goal = parameters.goal
inst = getattr(world, acted_upon)
if goal:
# TODO: super/subtype relations missing!
if goal.ontological_category.type() == 'location':
print('| move(x={x}, y={y}, z=0.0)'.format(x=goal.xCoord, y=goal.yCoord))
self.setpos(inst, (float(goal.xCoord), float(goal.yCoord), 0.0))
else:
# We assume it's an object, like a box or a block
obj = getattr(world, goal.referent.type())
print('| move(x={x}, y={y}, z={z})'.format(x=obj.pos.x, y=obj.pos.y, z=obj.pos.z))
self.setpos(inst, (obj.pos.x, obj.pos.y, obj.pos.z))
elif direction == 'home':
print('| move(x={x}, y={y}, z=0.0)'.format(x=home_pos.x, y=home_pos.y))
self.setpos(inst, (home_pos.x, home_pos.y, home_pos.z))
elif heading:
n = float(parameters.distance.value)
pos = self.getpos(inst)
newpos = vector_add(pos, vector_mul(n, self.headings[heading]))
print('| move(x={0[0]}, y={0[1]}, z={0[2]})'.format(newpos))
self.setpos(inst, newpos)
print('mock solver: end move')
示例5: is_legal_move
def is_legal_move(self, board, start, steps, player):
"""Move is a tuple which contains starting points of checkers to be
moved during a player's turn. An on-board move is legal if both the destinations
are open. A bear-off move is the one where a checker is moved off-board.
It is legal only after a player has moved all his checkers to his home."""
dest1, dest2 = vector_add(start, steps)
dest_range = range(0, 24)
move1_legal = move2_legal = False
if dest1 in dest_range:
if self.is_point_open(player, board[dest1]):
self.move_checker(board, start[0], steps[0], player)
move1_legal = True
else:
if self.allow_bear_off[player]:
self.move_checker(board, start[0], steps[0], player)
move1_legal = True
if not move1_legal:
return False
if dest2 in dest_range:
if self.is_point_open(player, board[dest2]):
move2_legal = True
else:
if self.allow_bear_off[player]:
move2_legal = True
return move1_legal and move2_legal
示例6: get_canvas_items
def get_canvas_items(self):
items = [ self.box, self.guard ]
if self.clock:
p = utils.vector_add(self.box.get_position(), (-9, 7))
items.append(citems.ClockIcon(
self, "clock", self.box.get_relative_placement(p)))
return items
示例7: __init__
def __init__(self, net, id, position, size):
NetItem.__init__(self, net, id)
self.point1 = citems.Point(self, "point1", citems.AbsPlacement(position))
self.point1.action = "resize_ltop"
self.point2 = citems.Point(self, "point2", citems.AbsPlacement(
utils.vector_add(position, size)))
self.point2.owner = self
self.point2.action = "resize_rbottom"
示例8: on_mouse_move
def on_mouse_move(self, event, position):
if self.resize_item:
change = utils.make_vector(self.initial_mouse, position)
change = utils.snap_to_grid(change, self.grid_size)
new_size = utils.vector_add(self.initial_size, change)
new_size = utils.vector_at_least(new_size, 0, 0)
self.resize_item.size = new_size
self.canvas.redraw()
else:
NetEditCanvasConfig.on_mouse_move(self, event, position)
示例9: solve_move
def solve_move(self, parameters):
color = None
size = None
world = self.world
print('solver: begin move_to_destination')
#for parameters in ntuple.parameters:
protagonist = self.get_described_obj(parameters.protagonist['objectDescriptor'])
speed = parameters.speed * 6
heading = parameters.heading
goal = parameters.goal
direction = parameters.direction
inst =protagonist
#getattr(self.world, protagonist)
if goal:
# TODO: super/subtype relations missing!
# print(goal)
if 'location' in goal:
#inst.move(x=float(goal['location'][0]), y=float(goal['location'][1]), z=0.0)
if goal['location'] == 'home':
self.move(inst, self.home_pos.x, self.home_pos.y, self.home_pos.z, tolerance= 2, speed=speed)
else:
self.move(inst,float(goal['location'][0]), float(goal['location'][1]), 0.0, speed=speed)
elif goal == 'home':
self.move(inst, home_pos.x, home_pos.y, home_pos.z, speed=speed)
elif 'referent' in goal:
obj = getattr(self.world, goal['referent'])
#inst.move(x=obj.pos.x, y=obj.pos.y, z=obj.pos.z)
self.move(inst, obj.pos.x, obj.pos.y, obj.pos.z, speed=speed)
elif ('partDescriptor' in goal):
if goal['partDescriptor']['relation']['type'] == 'side':
loc = self.get_described_part_pos(goal['partDescriptor'],inst)
if (loc):
self.move(inst, loc[0], loc[1], tolerance= 2, speed=speed)
else:
if ('objectDescriptor') in goal:
properties = goal['objectDescriptor']
obj = self.get_described_obj(properties, multiple=True)
if (obj):
self.move(inst, obj.pos.x, obj.pos.y, obj.pos.z, speed=speed)
elif ('locationDescriptor') in goal:
properties = goal['locationDescriptor']
loc = self.get_described_loc_pos(properties,getattr(self.world, inst))
if (loc):
self.move(inst, loc[0], loc[1], speed=speed)
elif heading:
n = float(parameters.distance.value)
print(inst)
name = getattr(inst, 'name')
#pos = getattr(inst, 'pos') #self.getpos(inst)
pos = self.getpos(name)
newpos = vector_add(pos, vector_mul(n, self.headings[heading]))
self.move(inst, newpos[0], newpos[1], newpos[2], speed=speed)
print('solver: end move_to_destination')
示例10: get_canvas_items
def get_canvas_items(self, view_mode):
items = NetElement.get_canvas_items(self, view_mode)
items.append(self.guard)
if self.collective:
items.append(self.root)
if self.clock:
p = utils.vector_add(self.box.get_position(), (-9, 7))
items.append(citems.ClockIcon(
self, "clock", self.box.get_relative_placement(p)))
return items
示例11: create_activations
def create_activations(self, values):
results = []
position = self.get_position()
start = utils.vector_add(position, (12, 0))
position = start
count = 0
for text, color, data in values:
activation = TransitionActivation(data,
"activation",
self.get_relative_placement(position),
text,
color)
results.append(activation)
position = utils.vector_add(position, (self.space_x + activation.size[0], 0))
count += 1
if count == 6:
count = 0
start = utils.vector_add(start, (0, self.space_y + activation.size[1]))
position = start
return results
示例12: get_activation_items
def get_activation_items(self):
result = []
for transition in self.perspective.runinstance.net.transitions():
activations = self.activations.get(transition.id)
if activations is None:
position = utils.vector_add(transition.box.get_position(), (0, transition.box.size[1] + 10))
activations = citems.TransitionActivations(None, "activations", citems.AbsPlacement(position))
self.activations[transition.id] = activations
values = self.perspective.get_activations_values(transition)
if values:
result.append(activations)
result += activations.create_activations(values)
return result
示例13: get_error_items
def get_error_items(self):
result = []
messages = self.net.project.get_error_messages(self)
if not messages:
return result
items = self.get_canvas_items_dict(None)
for name in messages:
item = items.get(name)
if item is None:
# Key was not found, take first item
# For transition/place it is expected that "box" is returned
item = self.get_canvas_items()[0]
position = utils.vector_add(item.get_position(), item.size)
position = utils.vector_add(position, (0, 0))
placement = item.get_relative_placement(position)
error_item = citems.Text(None, "error", placement)
error_item.delegate_selection = item
error_item.background_color = (255, 0, 0)
error_item.border_color = (0, 0, 0)
error_item.align_y = 0
error_item.z_level = 20
error_item.text = messages[name][0]
result.append(error_item)
return result
示例14: get_token_items
def get_token_items(self):
places = self.perspective.runinstance.net.places()
result = []
for place in places:
token_box = self.token_boxes.get(place.id)
if token_box is None:
sx, sy = place.box.size
position = utils.vector_add(place.box.get_position(),
(sx + 20, sy / 2))
token_box = citems.TokenBox(None, "tokenbox", citems.AbsPlacement(position))
self.token_boxes[place.id] = token_box
token_box.set_tokens(self.perspective.get_tokens(place),
self.perspective.get_new_tokens(place),
self.perspective.get_removed_tokens(place))
result.append(token_box)
return result
示例15: ray_cast
def ray_cast(self, sensor_num, kin_state):
"""Returns distace to nearest obstacle or map boundary in the direction of sensor"""
pos = kin_state[:2]
orient = kin_state[2]
# sensor layout when orientation is 0 (towards North)
# 0
# 3R1
# 2
delta = ((sensor_num%2 == 0)*(sensor_num - 1), (sensor_num%2 == 1)*(2 - sensor_num))
# sensor direction changes based on orientation
for _ in range(orient):
delta = (delta[1], -delta[0])
range_count = 0
while (0 <= pos[0] < self.nrows) and (0 <= pos[1] < self.nrows) and (not self.m[pos[0]][pos[1]]):
pos = vector_add(pos, delta)
range_count += 1
return range_count