Exemplo n.º 1
0
def test_pu_init_04():
    """PU argument must be a list or tuple of length == 2*n"""
    with pytest.raises(TypeError):
        PU([1])
    with pytest.raises(TypeError):
        PU([1, 2, 3])
    with pytest.raises(TypeError):
        PU([1, 2, 3, 4, 5])
Exemplo n.º 2
0
def test_hpglprimitive_terminator_01():
    """the _HPGLPrimitive class has a _terminator attribute that defines
    the terminator for HPGL commands. The default is `;`."""

    assert _HPGLPrimitive._terminator == b";"

    t = PU()
    assert t.format == b"PU;"

    _HPGLPrimitive._terminator = b"@"
    assert t.format == b"PU@"

    t = PU()
    assert t.format == b"PU@"
Exemplo n.º 3
0
def test_pu_init_06():
    """PU initialize properly with list or tuple of length == 2**n."""
    t = PU([(1, 2), (3, 4)])
    assert type(t.xy) == CoordinateArray
    assert t.xy == CoordinateArray([(1, 2), (3, 4)])
    assert t.x == (1, 3)
    assert t.y == (2, 4)
Exemplo n.º 4
0
def test_pu_init_05():
    """PU initialize properly with list or tuple of 2."""
    t = PU([(1, 2)])
    assert type(t.xy) == CoordinateArray
    assert t.xy == CoordinateArray([(1, 2)])
    assert t.x == (1, )
    assert t.y == (2, )
Exemplo n.º 5
0
def test_pu_init_02():
    """PU can be initialized with empty list."""
    t = PU([])
    assert type(t.xy) == CoordinateArray
    assert len(t.xy) == 0
    assert len(t.x) == 0
    assert len(t.y) == 0
Exemplo n.º 6
0
def test_pu_init_01():
    """PU can be initialized with nothing."""
    t = PU()
    assert type(t.xy) == CoordinateArray
    assert len(t.xy) == 0
    assert len(t.x) == 0
    assert len(t.y) == 0
def convert_coordinates_to_hpgl_absolute_path(coords):
    """Converts an iterator of lists of coordinates
    e.g., [<x1, y1>, <x2, y2>, <x3, y3>, ...]
    into a list of PA, PD and PU HPGL commands.
    """
    if not isinstance(coords, (list, tuple, CoordinateArray)):
        raise TypeError("`coords` must be a list of coordinates or CoordinateArray.")

    coords = [list(c) for c in coords]
    result = []
    result.append(PU())
    result.append(PA([coords[0]]))
    result.append(PD())
    ## this denies the possibility of paths with one coord.
    # result.append(PA(coords[1:]))
    result.append(PA(coords))
    result.append(PU())
    return result
Exemplo n.º 8
0
def test_hpglprimitive_terminator_01( ):
    '''the _HPGLPrimitive class has a _terminator attribute that defines
    the terminator for HPGL commands. The default is `;`.'''

    assert _HPGLPrimitive._terminator == ';'

    t = PU( )
    assert t.format == 'PU;'

    _HPGLPrimitive._terminator = '@'
    assert t.format == 'PU@'

    t = PU( )
    assert t.format == 'PU@'

    ## Reset terminator back to default ';' so that future
    ## tests don't fail.
    _HPGLPrimitive._terminator = ';'
Exemplo n.º 9
0
def pens_updown_to_papr(lst):
    '''Converts all PU((x1, y1, x2, y2) and PD(x1, y1, x2, y2) found in `lst`
    into (PU( ), PA(x1, y1, x2, y2)) pair sequences.
    The function removes the coordinates from PU and PD and places them in
    PR or PA, whatever was last found in lst prior to a PU or PD.'''

    if not isinstance(lst, (list, tuple)):
        raise TypeError('`lst` argument must be a list or tuple.')

    result = []
    last_move = None

    pen_down = False
    pen_up = True

    for e in lst:
        if isinstance(e, (PU, PD)):

            if len(e.xy) > 0:
                if last_move is None:
                    msg = "*** WARNING: %s with coordinates found without prior PA or PR. PA assumed." % e
                    print(msg)
                    last_move = PA()

                new_move = None

                if isinstance(last_move, PA):
                    new_move = PA()
                elif isinstance(last_move, PR):
                    new_move = PR()

                new_move.xy = e.xy

                up_down_command = None

                if isinstance(e, PU):
                    if pen_down:
                        up_down_command = PU()
                        result.append(up_down_command)
                        pen_up = True
                        pen_down = False

                elif isinstance(e, PD):
                    if pen_up:
                        up_down_command = PD()
                        result.append(up_down_command)
                        pen_down = True
                        pen_up = False

                result.append(new_move)

                last_move = new_move
            else:
                if isinstance(e, PU):
                    if pen_down:
                        result.append(e)
                        pen_up = True
                elif isinstance(e, PD):
                    if pen_up:
                        result.append(e)
                        pen_down = True
        else:
            if isinstance(e, PR):
                last_move = PR()
            elif isinstance(e, PA):
                last_move = PA()
            result.append(e)

    return result
Exemplo n.º 10
0
def test_pu_format_03():
    """Ints are kept ints at format."""
    t = PU([(0, 0)])
    assert t.format == b"PU0,0;"
Exemplo n.º 11
0
def test_pu_format_02():
    """Floats are left floats at format."""
    t = PU([(1, 0.)])
    assert t.format == b"PU1.00,0.00;"
Exemplo n.º 12
0
def test_pu_format_01():
    """Empty PU( )."""
    t = PU()
    assert t.format == b"PU;"
Exemplo n.º 13
0
def test_pu_init_03():
    """PU argument must be list-like (list, tuple, Ndarray,...)."""
    with pytest.raises(TypeError):
        PU(4)
Exemplo n.º 14
0
def test_pu_format_03():
    '''Ints are kept ints at format.'''
    t = PU([(0, 0)])
    assert t.format == 'PU0,0;'
Exemplo n.º 15
0
def test_pu_format_02():
    '''Floats are left floats at format.'''
    t = PU([(1, 0.)])
    assert t.format == 'PU1.00,0.00;'
Exemplo n.º 16
0
def test_pu_format_01():
    '''Empty PU( ).'''
    t = PU()
    assert t.format == 'PU;'