Esempio n. 1
0
def rotate_coordinatearray_2d(xylst, angle, pivot):
    '''2D rotation of list of coordinate pairs (CoordinateArray).

    - `xylst` list of (x, y) coordinate pairs.
    - `angle` is the angle of rotation in radians.
    - `pivot` the point around which to rotate `xy`.

    Returns a CoordinateArray.
    '''
    result = CoordinateArray( )
    for xy in xylst:
        r = rotate_coordinate_2d(xy, angle, pivot)
        result.append(r)
    return result
Esempio n. 2
0
                result.append((coord_pair, 1))
            else:
                result.append((coord_pair, int(round(segs))))
        return result

    divs = units_per_path_segment(coords, interpolation_unit)
    result = []
    for cp, n in divs:
        newcoords = [interpolate_linear(cp[0], cp[1], float(i) / n) for i in range(n)]
        result.extend(newcoords)

    return Path(result)


## demo
if __name__ == "__main__":
    from chiplotle import *
    import random

    coords = CoordinateArray([random.randint(0, 1000) for i in range(10)])
    # coords = CoordinateArray([0, 0, 300, 0, 300, 300, 0, 300, 0, 0])
    p = path_linear(coords, 100)

    circs = []
    for coord in p.points:
        c = circle(10, 8)
        offset(c, coord)
        circs.append(c)

    io.view(group([p] + circs))
Esempio n. 3
0
 def _preformat_points(self):
     '''Points (coordinates) ready for formatting (conversion to HPGL).'''
     coords = self.points[:]
     coords.append(coords[0])
     return CoordinateArray(coords)
Esempio n. 4
0
 def fset(self, arg):
     self._coords = CoordinateArray(arg)
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_shapes_group_points_01():
    '''An empty Group has an empty CoordinateArray.'''
    t = Group()
    assert t.points == CoordinateArray([])
    for coord in coord_array.difference:
        ratio = coord.magnitude / total_length
        c = rounder.round(count * ratio)
        r = split_vector_equidistantly(coord, c)
        r = r.difference
        result.extend(r)
    result = CoordinateArray(result).cumsum + coord_array[0]
    assert len(result) == count + 1
    return result


class Rounder(object):
    '''Hack class to keep track of residues.
    Come up with a good structural / rational solution.
    '''
    def __init__(self):
        self.residue = 0

    def round(self, n):
        if abs(self.residue) >= 0.5:
            n = n - self.residue
            self.residue = 0
        rn = int(round(n))
        self.residue += rn - n
        return rn


if __name__ == '__main__':
    ca = CoordinateArray([(20, 0), (20, 500), (20, 1000)])
    print split_coordinatearray_proportionally(ca, 8)
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)])
Esempio n. 9
0
 def points(self, arg):
     self._points = CoordinateArray(arg)
Esempio n. 10
0
 def __init__(self, points):
     _Shape.__init__(self)
     self.points = CoordinateArray(points)
Esempio n. 11
0
    def __sub__(self, arg):
        return self + (-arg)

    def __isub__(self, arg):
        self.points = self.points - arg
        return self

    def __rsub__(self, arg):
        return -(self - arg)

    def __eq__(self, arg):
        try:
            return self.points == arg.points
        except AttributeError:
            return False

    def __ne__(self, arg):
        return not (self == arg)

    def __neg__(self):
        return Path(-self.points)


## RUN DEMO CODE

if __name__ == "__main__":
    from chiplotle.tools import io

    p = Path(CoordinateArray([(1, 2), (4, 6), (0, 2), (5, 1)]) * 1000)
    io.view(p)
Esempio n. 12
0
def _assert_transform_changes_coords(shape, transform, trans_args):
    points_before = CoordinateArray(shape.points)
    transform(shape, *trans_args)
    points_after = CoordinateArray(shape.points)
    assert points_before != points_after
Esempio n. 13
0
def _assert_transform_preserves_diff(shape, transform, trans_args):
    points_before = CoordinateArray(shape.points).difference
    transform(shape, *trans_args)
    points_after = CoordinateArray(shape.points).difference
    assert points_before == points_after