Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
v1 = Vector(1, 2, 3)
v2 = Vector((1, 2, 3))
v3 = Vector({'x': 1, 'y': 2, 'z': 3})
v4 = Vector({'x': 1})
self.assertEqual(v1, (1, 2, 3))
self.assertEqual(v2, (1, 2, 3))
self.assertEqual(v3, (1, 2, 3))
self.assertEqual(v4, Vector(1, 0, 0))
def test_init(self):
v1 = Vector(1, 2, 3)
v2 = Vector((1, 2, 3))
v3 = Vector({'x': 1, 'y': 2, 'z': 3})
v4 = Vector({'x': 1})
self.assertEqual(v1, (1, 2, 3))
self.assertEqual(v2, (1, 2, 3))
self.assertEqual(v3, (1, 2, 3))
self.assertEqual(v4, Vector(1, 0, 0))
def test_break_down_travel(self):
# with 3-dimensional points
p1 = Vector(0, 0, 0)
p2 = Vector(10, -12, 14)
res = helpers.break_down_travel(
p1, p2, increment=5, mode='absolute')
self.assertEquals(res[-1], p2)
self.assertEquals(len(res), 5)
p1 = Vector(10, -12, 14)
res = helpers.break_down_travel(Vector(0, 0, 0), p1, mode='relative')
expected = Vector(
0.46537410754407676,
-0.5584489290528921,
0.6515237505617075)
self.assertEquals(res[-1], expected)
self.assertEquals(len(res), 5)
def test_add(self):
v1 = Vector(1, 2, 3)
v2 = Vector(4, 5, 6)
res = v1 + v2
self.assertEqual(res, Vector(5, 7, 9))
def from_polar(self, r, theta, h):
"""
Converts polar coordiantes within a placeable into a :Vector:
The origin is assumed to be in the center of a Placeable
:r: is between -1.0 and 1.0, relative to max X
:h: is between -1.0 and 1.0, relative to max Z
"""
center = self.size() / 2.0
r = r * center['x']
return center + Vector(r * math.cos(theta),
r * math.sin(theta),
center['z'] * h)
def _setup_container(container_obj):
""" Fix up a loaded container's coordinates. Returns the container """
container_x, container_y, container_z = container_obj._coordinates
# infer z from height
if container_z == 0 and 'height' in container_obj[0].properties:
container_z = container_obj[0].properties['height']
container_obj._coordinates = Vector(
container_x,
container_y,
container_z)
return container_obj
def add_offset(container):
# Adds associated origin offset to all well coordinates
# so that the origin can be transposed
x, y, _ = container._coordinates
for well in container.wells():
old_x, old_y, z = well._coordinates
dx = x + old_x
dy = y + old_y
well._coordinates = Vector(dx, dy, z)
return container
def rotate_container_for_alpha(container):
container = add_offset(container)
_, _, z = container._coordinates
# Change container coordinates to be at the origin + top of container
container._coordinates = Vector(0, 0, z)
transpose_coordinates([well for well in container.wells()])
return container
def handle_transfer_to(self, tool_obj, to_info, volume):
to_well = self.get_well_obj(to_info)
should_touch_tip_on_to = to_info.get('touch-tip', False)
to_tip_offset = to_info.get('tip-offset', 0)
to_delay = to_info.get('delay', 0)
blowout = to_info.get('blowout', False)
to_location = (
to_well,
to_well.from_center(x=0, y=0, z=-1) +
vector.Vector(0, 0, to_tip_offset)
)
tool_obj.dispense(volume, to_location)
if blowout:
tool_obj.blow_out(to_location)
if should_touch_tip_on_to:
tool_obj.touch_tip()
if to_delay is not None:
tool_obj.delay(to_delay)
def from_cartesian(self, x, y, z):
"""
Converts cartesian coordinates within a placeable into a :Vector:
The origin is assumed to be in the center of a Placeable
:x:, :y:, :z: is between -1.0 and 1.0, relative to max X, Y, Z
"""
center = self.size() / 2.0
return center + center * Vector(x, y, z)