Exemplo n.º 1
0
def test_outliner_mode():
    # We can set up a pattern in one mode,
    p = Pen()
    p.set_mode(StrokeOutlineMode(sqrt3, 0.2 * sqrt3, 'blue', 'black'))

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5, end_slant=60)

    # Then continue it in another mode without caring what the first mode was.
    old_mode = p.mode
    p.set_mode(p.mode.outliner_mode())

    p.turn_to(60)
    p.move_forward(1.0)

    p.turn_left(60)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)

    p.turn_to(60)
    p.move_forward(3.0)
    p.turn_to(120)

    p.set_mode(old_mode)

    p.line_forward(5, start_slant=60)

    assert_svg_file(
        p, 3,
        'test_outliner_mode.svg'
    )
Exemplo n.º 2
0
def test_outliner_mode():
    # We can set up a pattern in one mode,
    p = Pen()
    p.set_mode(StrokeOutlineMode(sqrt3, 0.2 * sqrt3, 'blue', 'black'))

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5, end_slant=60)

    # Then continue it in another mode without caring what the first mode was.
    old_mode = p.mode
    p.set_mode(p.mode.outliner_mode())

    p.turn_to(60)
    p.move_forward(1.0)

    p.turn_left(60)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)
    p.turn_right(120)
    p.line_forward(2.0)

    p.turn_to(60)
    p.move_forward(3.0)
    p.turn_to(120)

    p.set_mode(old_mode)

    p.line_forward(5, start_slant=60)

    assert_svg_file(
        p, 3,
        'test_outliner_mode.svg'
    )
Exemplo n.º 3
0
def test_offwidth_joint():
    p = Pen()
    p.stroke_mode(1.0)
    p.turn_to(0)
    p.move_forward(-3)
    p.line_forward(3)
    p.stroke_mode(0.5)
    p.turn_left(90)
    p.line_forward(3)

    assert_path_data(
        p, 2,
        (
            'M-3.00,-0.50 L-3.00,0.50 L0.25,0.50 L0.25,-3.00 '
            'L-0.25,-3.00 L-0.25,-0.50 L-3.00,-0.50 z'
        ),
    )
Exemplo n.º 4
0
def test_offwidth_joint():
    p = Pen()
    p.stroke_mode(1.0)
    p.turn_to(0)
    p.move_forward(-3)
    p.line_forward(3)
    p.stroke_mode(0.5)
    p.turn_left(90)
    p.line_forward(3)

    assert_path_data(
        p, 2,
        (
            'M-3.00,-0.50 L-3.00,0.50 L0.25,0.50 L0.25,-3.00 '
            'L-0.25,-3.00 L-0.25,-0.50 L-3.00,-0.50 z'
        ),
    )
Exemplo n.º 5
0
def test_arc_start_slant_bug():
    # Some arcs are not reporting their start and end slants correctly.

    # Set up positions on a circle at angles -120 and 30
    p = Pen()
    p.fill_mode()

    p.move_to((0, 0))
    p.turn_to(30)
    p.move_forward(3)
    p1 = p.position
    p.turn_left(90)
    h1 = p.heading

    p.move_to((0, 0))
    p.turn_to(-120)
    p.move_forward(3)
    p2 = p.position

    # Create an arc using arc_left.
    p = Pen()
    p.fill_mode()

    p.move_to(p1)
    p.turn_to(h1)
    p.arc_left(210, 3)
    arc = p.last_segment()
    assert_almost_equal(arc.start_heading, 120)
    assert_almost_equal(arc.end_heading, 330)

    # Create the same arc using arc_to.
    p = Pen()
    p.fill_mode()

    p.move_to(p1)
    p.turn_to(h1)
    p.arc_to(p2)
    arc = p.last_segment()
    assert_almost_equal(arc.start_heading.theta, 120)
    assert_almost_equal(arc.end_heading.theta, 330)
Exemplo n.º 6
0
def test_arc_start_slant_bug():
    # Some arcs are not reporting their start and end slants correctly.

    # Set up positions on a circle at angles -120 and 30
    p = Pen()
    p.fill_mode()

    p.move_to((0, 0))
    p.turn_to(30)
    p.move_forward(3)
    p1 = p.position
    p.turn_left(90)
    h1 = p.heading

    p.move_to((0, 0))
    p.turn_to(-120)
    p.move_forward(3)
    p2 = p.position

    # Create an arc using arc_left.
    p = Pen()
    p.fill_mode()

    p.move_to(p1)
    p.turn_to(h1)
    p.arc_left(210, 3)
    arc = p.last_segment()
    assert_almost_equal(arc.start_heading, 120)
    assert_almost_equal(arc.end_heading, 330)

    # Create the same arc using arc_to.
    p = Pen()
    p.fill_mode()

    p.move_to(p1)
    p.turn_to(h1)
    p.arc_to(p2)
    arc = p.last_segment()
    assert_almost_equal(arc.start_heading.theta, 120)
    assert_almost_equal(arc.end_heading.theta, 330)
Exemplo n.º 7
0
def test_circle_color():
    p = Pen()
    p.move_to((0, 0))

    p.turn_to(0)
    p.fill_mode((1.0, 0.0, 0.0))
    p.circle(1)
    p.move_forward(2)
    p.fill_mode((0.0, 1.0, 0.0))
    p.circle(1)
    p.move_forward(2)
    p.fill_mode((0.0, 0.0, 1.0))
    p.circle(1)

    assert_equal(
        p.paper.svg_elements(0),
        [
            '<path d="M1,0 A 1,1 0 0 0 -1,0 A 1,1 0 0 0 1,0 z" fill="#ff0000" />',
            '<path d="M3,0 A 1,1 0 0 0 1,0 A 1,1 0 0 0 3,0 z" fill="#00ff00" />',
            '<path d="M5,0 A 1,1 0 0 0 3,0 A 1,1 0 0 0 5,0 z" fill="#0000ff" />',
        ]
    )
Exemplo n.º 8
0
def test_circle_color():
    p = Pen()
    p.move_to((0, 0))

    p.turn_to(0)
    p.fill_mode((1.0, 0.0, 0.0))
    p.circle(1)
    p.move_forward(2)
    p.fill_mode((0.0, 1.0, 0.0))
    p.circle(1)
    p.move_forward(2)
    p.fill_mode((0.0, 0.0, 1.0))
    p.circle(1)

    assert_equal(
        p.paper.svg_elements(0),
        [
            '<path d="M1,0 A 1,1 0 0 0 -1,0 A 1,1 0 0 0 1,0 z" fill="#ff0000" />',
            '<path d="M3,0 A 1,1 0 0 0 1,0 A 1,1 0 0 0 3,0 z" fill="#00ff00" />',
            '<path d="M5,0 A 1,1 0 0 0 3,0 A 1,1 0 0 0 5,0 z" fill="#0000ff" />',
        ]
    )