Esempio n. 1
0
def test_offwidth_arc_joins():
    # Join arcs and lines of different widths.
    p = Pen()
    p.move_to((0, 0))
    p.turn_to(0)

    p.stroke_mode(0.8)
    p.line_forward(5)
    p.turn_left(45)
    p.stroke_mode(3.0)
    p.arc_left(90, 5)

    p.turn_to(-180)
    p.line_forward(5)
    p.turn_left(45)
    p.stroke_mode(0.8)
    p.arc_left(45, 5)

    p.turn_right(90)
    p.stroke_mode(3.0)
    p.arc_right(90, 4)

    assert_svg_file(
        p, 3,
        'test_offwidth_arc_joins.svg'
    )
Esempio n. 2
0
def test_offwidth_arc_joins():
    # Join arcs and lines of different widths.
    p = Pen()
    p.move_to((0, 0))
    p.turn_to(0)

    p.stroke_mode(0.8)
    p.line_forward(5)
    p.turn_left(45)
    p.stroke_mode(3.0)
    p.arc_left(90, 5)

    p.turn_to(-180)
    p.line_forward(5)
    p.turn_left(45)
    p.stroke_mode(0.8)
    p.arc_left(45, 5)

    p.turn_right(90)
    p.stroke_mode(3.0)
    p.arc_right(90, 4)

    assert_svg_file(
        p, 3,
        'test_offwidth_arc_joins.svg'
    )
Esempio n. 3
0
def test_arc_joint_continue():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)

    p.arc_left(90, 5)
    p.arc_left(90, 5)

    p.move_to((0, 0))
    p.turn_to(0)

    p.arc_right(90, 5)
    p.arc_right(90, 5)

    assert_path_data(
        p, 0,
        (
            'M0,-1 L0,1 A 6,6 0 0 0 6,-5 A 6,6 0 0 0 0,-11 '
            'L0,-9 A 4,4 0 0 1 4,-5 A 4,4 0 0 1 0,-1 z '
            'M0,-1 L0,1 A 4,4 0 0 1 4,5 A 4,4 0 0 1 0,9 '
            'L0,11 A 6,6 0 0 0 6,5 A 6,6 0 0 0 0,-1 z'
        ),
    )
Esempio n. 4
0
def test_arc_joint_continue():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)

    p.arc_left(90, 5)
    p.arc_left(90, 5)

    p.move_to((0, 0))
    p.turn_to(0)

    p.arc_right(90, 5)
    p.arc_right(90, 5)

    assert_path_data(
        p, 0,
        (
            'M0,-1 L0,1 A 6,6 0 0 0 6,-5 A 6,6 0 0 0 0,-11 '
            'L0,-9 A 4,4 0 0 1 4,-5 A 4,4 0 0 1 0,-1 z '
            'M0,-1 L0,1 A 4,4 0 0 1 4,5 A 4,4 0 0 1 0,9 '
            'L0,11 A 6,6 0 0 0 6,5 A 6,6 0 0 0 0,-1 z'
        ),
    )
Esempio n. 5
0
def test_arc_zero():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    # Zero-angle and zero-radius arcs have zero length, so they are not added.
    p.arc_left(0, radius=1)
    assert_equal(p.paper.paths, [])

    p.arc_left(90, radius=0)
    assert_equal(p.paper.paths, [])
Esempio n. 6
0
def test_arc_sweep_bug():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((3, 0))
    p.turn_to(90)
    p.arc_left(270, 3)

    assert_path_data(
        p, 0,
        'M2,0 L4,0 A 4,4 0 1 0 0,4 L0,2 A 2,2 0 1 1 2,0 z'
    )
Esempio n. 7
0
def test_arc_normalize():
    # Arc angles larger than 360 behave correctly.
    p = Pen()
    p.fill_mode()
    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(360 + 90, radius=5)

    assert_path_data(
        p, 0,
        'M-5,0 A 5,5 0 0 0 0,-5'
    )
Esempio n. 8
0
def test_arc_normalize():
    # Arc angles larger than 360 behave correctly.
    p = Pen()
    p.fill_mode()
    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(360 + 90, radius=5)

    assert_path_data(
        p, 0,
        'M-5,0 A 5,5 0 0 0 0,-5'
    )
Esempio n. 9
0
def test_arc_zero():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    # Zero-angle and zero-radius arcs have zero length, so they are not added.
    p.arc_left(0, radius=1)
    assert_equal(p.paper.paths, [])

    p.arc_left(90, radius=0)
    assert_equal(p.paper.paths, [])
Esempio n. 10
0
def test_arc_sweep_bug():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((3, 0))
    p.turn_to(90)
    p.arc_left(270, 3)

    assert_path_data(
        p, 0,
        'M2,0 L4,0 A 4,4 0 1 0 0,4 L0,2 A 2,2 0 1 1 2,0 z'
    )
Esempio n. 11
0
def test_arc_pie_slice():
    # Draw a "pie slice" arc that is wide enough to reach all the way to the
    # arc center.
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0.5, 0))
    p.turn_to(90)
    p.arc_left(90, 0.5)

    assert_path_data(
        p, 0,
        'M0,0 L1,0 A 1,1 0 0 0 0,-1 L0,0 z'
    )
Esempio n. 12
0
def test_arc_pie_slice():
    # Draw a "pie slice" arc that is wide enough to reach all the way to the
    # arc center.
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0.5, 0))
    p.turn_to(90)
    p.arc_left(90, 0.5)

    assert_path_data(
        p, 0,
        'M0,0 L1,0 A 1,1 0 0 0 0,-1 L0,0 z'
    )
Esempio n. 13
0
def test_stroke_fill_mode():
    p = Pen()
    p.set_mode(StrokeFillMode(0.2, 'black', 'red'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,0.0 A 5.0,5.0 0 0 0 0.0,-10.0" fill="#ff0000" />'
            '<path d="M0.0,-0.1 L0.0,0.1 A 5.1,5.1 0 0 0 0.0,-10.1 '
            'L0.0,-9.9 A 4.9,4.9 0 0 1 0.0,-0.1 z" fill="#000000" />'
        )
    )
Esempio n. 14
0
def test_arc_angle():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5, start_slant=45, end_slant=45)

    assert_path_data(
        p, 2,
        (
            'M0.53,-0.53 L-0.48,0.48 A 5.50,5.50 0 0 0 5.48,-5.48 '
            'L4.47,-4.47 A 4.50,4.50 0 0 1 0.53,-0.53 z'
        ),
    )
Esempio n. 15
0
def test_arc_angle():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5, start_slant=45, end_slant=45)

    assert_path_data(
        p, 2,
        (
            'M0.53,-0.53 L-0.48,0.48 A 5.50,5.50 0 0 0 5.48,-5.48 '
            'L4.47,-4.47 A 4.50,4.50 0 0 1 0.53,-0.53 z'
        ),
    )
Esempio n. 16
0
def test_stroke_fill_mode():
    p = Pen()
    p.set_mode(StrokeFillMode(0.2, 'black', 'red'))
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 5)
    assert_equal(
        p.paper.svg_elements(1)[0],
        (
            '<path d="M0.0,0.0 A 5.0,5.0 0 0 0 0.0,-10.0" fill="#ff0000" />'
            '<path d="M0.0,-0.1 L0.0,0.1 A 5.1,5.1 0 0 0 0.0,-10.1 '
            'L0.0,-9.9 A 4.9,4.9 0 0 1 0.0,-0.1 z" fill="#000000" />'
        )
    )
Esempio n. 17
0
def test_arc_line_joint():
    p = Pen()
    p.stroke_mode(1.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(3)
    p.turn_left(90)
    p.arc_left(180, 3)

    assert_path_data(
        p, 3,
        (
            'M0.000,-0.500 L0.000,0.500 L3.464,0.500 '
            'A 3.500,3.500 0 1 0 -3.500,0.000 L-2.500,0.000 '
            'A 2.500,2.500 0 0 1 2.449,-0.500 L0.000,-0.500 z'
        ),
    )
Esempio n. 18
0
def test_arc_line_joint():
    p = Pen()
    p.stroke_mode(1.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(3)
    p.turn_left(90)
    p.arc_left(180, 3)

    assert_path_data(
        p, 3,
        (
            'M0.000,-0.500 L0.000,0.500 L3.464,0.500 '
            'A 3.500,3.500 0 1 0 -3.500,0.000 L-2.500,0.000 '
            'A 2.500,2.500 0 0 1 2.449,-0.500 L0.000,-0.500 z'
        ),
    )
Esempio n. 19
0
def test_arc_arc_joint_off_radius():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 1)
    p.arc_left(90, 2)

    assert_path_data(
        p, 1,
        (
            'M0.0,-0.5 L0.0,0.5 '
            'A 1.5,1.5 0 0 0 0.0,-2.5 '
            'A 2.5,2.5 0 0 0 -2.5,0.0 '
            'L-1.5,0.0 '
            'A 1.5,1.5 0 0 1 0.0,-1.5 '
            'A 0.5,0.5 0 0 1 0.0,-0.5 z'
        )
    )
Esempio n. 20
0
def test_arc_arc_joint_off_radius():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(180, 1)
    p.arc_left(90, 2)

    assert_path_data(
        p, 1,
        (
            'M0.0,-0.5 L0.0,0.5 '
            'A 1.5,1.5 0 0 0 0.0,-2.5 '
            'A 2.5,2.5 0 0 0 -2.5,0.0 '
            'L-1.5,0.0 '
            'A 1.5,1.5 0 0 1 0.0,-1.5 '
            'A 0.5,0.5 0 0 1 0.0,-0.5 z'
        )
    )
Esempio n. 21
0
def test_various_joins():
    p = Pen()
    p.stroke_mode(0.5)
    p.move_to((-2, 0))
    p.turn_to(0)
    p.line_forward(1)
    p.turn_left(90)
    p.line_forward(1)
    p.turn_right(90)
    p.arc_right(90, 1)
    p.arc_left(90, 1)
    p.turn_left(90)
    p.line_forward(1)

    p.paper.override_bounds(-3, -3, 3, 3)

    assert_svg_file(
        p, 2,
        'test_various_joins.svg',
    )
Esempio n. 22
0
def test_arc_error():
    # Don't allow drawing an arc without a center or radius.
    p = Pen()
    assert_raises(
        TypeError,
        lambda: p.arc_left(90)
    )
    assert_raises(
        TypeError,
        lambda: p.arc_right(90)
    )
Esempio n. 23
0
def test_various_joins():
    p = Pen()
    p.stroke_mode(0.5)
    p.move_to((-2, 0))
    p.turn_to(0)
    p.line_forward(1)
    p.turn_left(90)
    p.line_forward(1)
    p.turn_right(90)
    p.arc_right(90, 1)
    p.arc_left(90, 1)
    p.turn_left(90)
    p.line_forward(1)

    p.paper.override_bounds(-3, -3, 3, 3)

    assert_svg_file(
        p, 2,
        'test_various_joins.svg',
    )
Esempio n. 24
0
def test_arc_error():
    # Don't allow drawing an arc without a center or radius.
    p = Pen()
    assert_raises(
        TypeError,
        lambda: p.arc_left(90)
    )
    assert_raises(
        TypeError,
        lambda: p.arc_right(90)
    )
Esempio n. 25
0
def test_close_loop_joint_error():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    p.line_forward(10)
    p.turn_right(90)
    p.line_forward(10)
    p.turn_right(180)
    p.arc_left(90, 10)

    arc = p.last_segment()
    assert arc.start_joint_illegal
    assert arc.end_joint_illegal

    assert_path_data(
        p, 2,
        ('M4.47,0.50 L9.50,0.50 L9.50,5.53 A 10.50,10.50 0 0 0 4.47,0.50 z '
         'M0.00,-0.50 L0.00,0.50 A 9.50,9.50 0 0 1 9.50,10.00 '
         'L10.50,10.00 L10.50,-0.50 L0.00,-0.50 z'))
Esempio n. 26
0
def test_repr():
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(1)
    p.arc_left(90, 1)

    path = p.paper.paths[0]
    line, arc = path.segments
    assert_equal(
        repr(line),
        'LineSegment(a=Point(x=0, y=0), b=Point(x=1.0, y=0.0))'
    )
    assert_equal(
        repr(arc),
        (
            'ArcSegment(a=Point(x=1.0, y=0.0), b=Point(x=2.0, y=0.9999999999999999), '
            'center=Point(x=1.0, y=1.0), radius=1, start_heading=0, end_heading=90)'
        )
    )
Esempio n. 27
0
def test_repr():
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(1)
    p.arc_left(90, 1)

    path = p.paper.paths[0]
    line, arc = path.segments
    assert_equal(
        repr(line),
        'LineSegment(a=Point(x=0, y=0), b=Point(x=1.0, y=0.0))'
    )
    assert_equal(
        repr(arc),
        (
            'ArcSegment(a=Point(x=1.0, y=0.0), b=Point(x=2.0, y=0.9999999999999999), '
            'center=Point(x=1.0, y=1.0), radius=1, start_heading=0, end_heading=90)'
        )
    )
Esempio n. 28
0
def test_arc_angle_error():
    # Endpoints with certain angles do not go all the way across the
    # stroke, and are disallowed.
    p = Pen()
    p.stroke_mode(1.0)
    p.arc_left(90, 10, start_slant=0)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert not seg.end_joint_illegal

    p = Pen()
    p.stroke_mode(1.0)
    p.arc_left(90, 10, end_slant=90)
    seg = p.last_segment()
    assert not seg.start_joint_illegal
    assert seg.end_joint_illegal

    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5, start_slant=25)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert not seg.end_joint_illegal

    # A combination of angles can also create a degenerate arc.
    p = Pen()
    p.stroke_mode(1.0)
    p.turn_toward((1, 0))
    p.turn_left(1)
    p.arc_to((1, 0), start_slant=40, end_slant=-40)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Esempio n. 29
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)
Esempio n. 30
0
def test_arc_angle_error():
    # Endpoints with certain angles do not go all the way across the
    # stroke, and are disallowed.
    p = Pen()
    p.stroke_mode(1.0)
    p.arc_left(90, 10, start_slant=0)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert not seg.end_joint_illegal

    p = Pen()
    p.stroke_mode(1.0)
    p.arc_left(90, 10, end_slant=90)
    seg = p.last_segment()
    assert not seg.start_joint_illegal
    assert seg.end_joint_illegal

    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5, start_slant=25)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert not seg.end_joint_illegal

    # A combination of angles can also create a degenerate arc.
    p = Pen()
    p.stroke_mode(1.0)
    p.turn_toward((1, 0))
    p.turn_left(1)
    p.arc_to((1, 0), start_slant=40, end_slant=-40)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Esempio n. 31
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)
Esempio n. 32
0
def test_arc():
    # Draw arcs with all four combinations of sweep and direction flags.
    p = Pen()
    p.fill_mode()

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5)
    p.arc_right(270, radius=5)

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_right(90, radius=5)
    p.arc_left(270, radius=5)

    assert_path_data(
        p, 0,
        (
            'M-5,0 A 5,5 0 0 0 0,-5 A 5,5 0 1 1 5,0 '
            'M-5,0 A 5,5 0 0 1 0,5 A 5,5 0 1 0 5,0'
        )
    )
Esempio n. 33
0
def test_arc_center():
    # Draw the same arcs as in test_arc, but using centers instead of radii.
    p = Pen()
    p.fill_mode()

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(90, center=(-5, 5))
    p.arc_right(270, center=(5, 5))

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_right(90, center=(-5, -5))
    p.arc_left(270, center=(5, -5))

    assert_path_data(
        p, 0,
        (
            'M-5,0 A 5,5 0 0 0 0,-5 A 5,5 0 1 1 5,0 '
            'M-5,0 A 5,5 0 0 1 0,5 A 5,5 0 1 0 5,0'
        ),
    )
Esempio n. 34
0
def test_arc():
    # Draw arcs with all four combinations of sweep and direction flags.
    p = Pen()
    p.fill_mode()

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(90, radius=5)
    p.arc_right(270, radius=5)

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_right(90, radius=5)
    p.arc_left(270, radius=5)

    assert_path_data(
        p, 0,
        (
            'M-5,0 A 5,5 0 0 0 0,-5 A 5,5 0 1 1 5,0 '
            'M-5,0 A 5,5 0 0 1 0,5 A 5,5 0 1 0 5,0'
        )
    )
Esempio n. 35
0
def test_arc_center():
    # Draw the same arcs as in test_arc, but using centers instead of radii.
    p = Pen()
    p.fill_mode()

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(90, center=(-5, 5))
    p.arc_right(270, center=(5, 5))

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_right(90, center=(-5, -5))
    p.arc_left(270, center=(5, -5))

    assert_path_data(
        p, 0,
        (
            'M-5,0 A 5,5 0 0 0 0,-5 A 5,5 0 1 1 5,0 '
            'M-5,0 A 5,5 0 0 1 0,5 A 5,5 0 1 0 5,0'
        ),
    )
Esempio n. 36
0
def test_close_loop_joint_error():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    p.line_forward(10)
    p.turn_right(90)
    p.line_forward(10)
    p.turn_right(180)
    p.arc_left(90, 10)

    arc = p.last_segment()
    assert arc.start_joint_illegal
    assert arc.end_joint_illegal

    assert_path_data(
        p, 2,
        (
            'M4.47,0.50 L9.50,0.50 L9.50,5.53 A 10.50,10.50 0 0 0 4.47,0.50 z '
            'M0.00,-0.50 L0.00,0.50 A 9.50,9.50 0 0 1 9.50,10.00 '
            'L10.50,10.00 L10.50,-0.50 L0.00,-0.50 z'
        )
    )