def test_path_rmul_02(): """A duple and a Path cannot be multiplied.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): (1, 2) * a
def path(points): """A simple path.""" return Path(points)
def test_path_iadd_01(): """A float and a Path cannot be added.""" t = Path([(1, 2), (3, 4)]) with raises(TypeError): t += 3.2
def test_shapes_group_points_03(): '''A non-flat Group has a CoordinateArray.''' g = Group([Path([(1, 2), (3, 4)]), Path([(4, 2), (4, 2)])]) t = Group([g, Path([(100, 200)])]) assert t.points == CoordinateArray([(1, 2), (3, 4), (4, 2), (4, 2), (100, 200)])
def test_path_add_04(): """A Path and a duple cannot be added.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): a + (1, 2)
def test_path_add_05(): """A 2D Path and a triple cannot be added.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): a + (1, 2, 3)
def test_path_rsub_04( ): '''A duple cannot substract a Path.''' a = Path([(1, 2), (3, 4)]) assert raises(TypeError, '(1, 2) - a')
def test_path_add_02(): """A Path and a float cannot be added.""" with raises(TypeError): Path([(1, 2), (3, 4)]) + 3.2
def test_path_rsub_02( ): '''A float cannot substract a Path.''' a = Path([(1, 2), (3, 4)]) assert raises(TypeError, 't = 2.5 - a')
def test_path_sub_01( ): '''A Path cannot substract an int.''' a = Path([(1, 2), (3, 4)]) assert raises(TypeError, 't = a - 2')
def test_path_sub_02( ): '''A Path cannot substract a float.''' a = Path([(1, 2), (3, 4)]) assert raises(TypeError, 't = a - 2.5')
def test_shapes_group_add_01(): '''Group + int is not allowed.''' a = Group([Path([(1, 2), (3, 4)]), Path([(5, 6), (7, 8)])]) assert raises(TypeError, 't = a + 2')
def test_shapes_group_add_02(): '''int + Group is not allowed.''' a = Group([Path([(1, 2), (3, 4)]), Path([(5, 6), (7, 8)])]) assert raises(TypeError, 't = 2 + a')
def test_path_iadd_01(): '''A float and a Path cannot be added.''' t = Path([(1, 2), (3, 4)]) assert raises(TypeError, 't += 3.2')
def test_path_sub_05( ): '''A Path cannot substract a triple.''' a = Path([(1, 2), (3, 4)]) assert raises(TypeError, 'a - (1, 2, 3)')
def spiral_archimedean( radius, num_turns=5, wrapping_constant=1, direction="cw", segments=500 ): """ Constructs an Archimedean (arithmetic) spiral with the given number of turns using the specified number of points. wrapping_constant controls how tightly the spiral is wound. Several classic spirals can be created using different wrapping_constants: lituus: -2 hyperbolic spiral: -1 Archimedes' spiral: 1 Fermat's spiral: 2 scaler controls how large the spiral is. The general Archimedean spiral equation is: r = a * theta^(1/n) where r is the radius, a is the scaler, and n is the wrapping_constant. More info: http://mathworld.wolfram.com/ArchimedeanSpiral.html """ two_pi = math.pi * 2.0 total_rads = two_pi * num_turns theta = 0.0 theta_incr = total_rads / float(segments - 1) exponent = 1.0 / wrapping_constant scaler = float(radius) / math.pow(total_rads, exponent) # Spirals with a negative wrapping_constant technically begin at infinity, # which obviously isn't practical. So we nudge theta by a bit to get a # reasonable starting point if wrapping_constant < 0.0: theta += theta_incr pow = math.pow(theta_incr, abs(exponent)) scaler = float(radius) / (1.0 / pow) spiral_points = [] r = 0.0 for i in range(segments): if exponent > 0: r = scaler * math.pow(theta, exponent) else: pow = math.pow(theta, abs(exponent)) r = scaler * 1.0 / pow x = math.cos(theta) * r y = math.sin(theta) * r if direction == "ccw": y *= -1.0 # print "r: %f theta: %f" % (r, theta) spiral_points.append((x, y)) theta += theta_incr result = Path(spiral_points) return result
def test_path_sub_06( ): '''Two paths cannot be substracted.''' a = Path([(1, 2), (3, 4)]) b = Path([(2, 3)]) assert raises(TypeError, 'a - b')
def test_path_radd_02(): """A float and a Path cannot be added.""" with raises(TypeError): 3.2 + Path([(1, 2), (3, 4)])
def test_path_isub_01( ): '''A float cannot be substracted from a Path in place.''' t = Path([(1, 2), (3, 4)]) assert raises(TypeError, 't -= 2.5')
def test_path_radd_04(): """A duple and a Path cannot be added.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): (1, 2) + a
def path(points): '''A simple path.''' return Path(points)
def test_path_add_06(): """A Path and a Path cannot be added.""" a = Path([(1, 2), (3, 4)]) b = Path([(2, 3)]) with raises(TypeError): a + b
standard_library.install_aliases() from chiplotle.geometry.core.path import Path from chiplotle.geometry.transforms.offset import offset def arrange_shapes_on_path(shapes, path): if not isinstance(path, Path): raise TypeError if len(shapes) != len(path): raise ValueError("len(shapes) == len(path) must be true.") for shape, coord in zip(shapes, path.points): offset(shape, coord) if __name__ == "__main__": from chiplotle import * import random count = 10 coords = [random.randint(0, 4000) for i in range(count * 2)] circs = [circle(100) for i in range(count)] p = Path(coords) PenDecorator(Pen(2))(p) arrange_shapes_on_path(circs, p) io.view(group(circs + [p]))
def test_shapes_group_points_02(): '''A flat Group has a CoordinateArray.''' t = Group([Path([(1, 2), (3, 4)]), Path([(4, 2), (4, 2)])]) assert t.points == CoordinateArray([(1, 2), (3, 4), (4, 2), (4, 2)])
def test_shapes_group_add_02(): """int + Group is not allowed.""" a = Group([Path([(1, 2), (3, 4)]), Path([(5, 6), (7, 8)])]) with raises(TypeError): 2 + a
def test_path_mul_02(): """A Path and a duple cannot be multiplied.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): a * (1, 2)
def line(startpoint, endpoint): """Returns a Path with only two points. The path describes a simple straight line. """ return Path([startpoint, endpoint])
def test_path_mul_03(): """A Path cannot be multiplied with a triple.""" a = Path([(1, 2), (3, 4)]) with raises(TypeError): a * (1, 2, 3)
def __init__(self, points, filled=False): Path.__init__(self, points) self.filled = filled
def __init__(self, points, filled=False): Path.__init__(self, points) self.filled = filled
def test_path_add_06(): '''A Path and a Path cannot be added.''' a = Path([(1, 2), (3, 4)]) b = Path([(2, 3)]) assert raises(TypeError, 'a + b')