Exemplo n.º 1
0
def test_custom_cap():

    def circle_cap(pen, end):
        pen.arc_to(end)

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().end_cap = circle_cap
    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L5,1 A 1,1 0 0 0 5,-1 L0,-1 z'
    )

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().start_cap = circle_cap
    assert_path_data(
        p, 0,
        'M0,-1 A 1,1 0 1 0 0,1 L5,1 L5,-1 L0,-1 z'
    )
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
def test_custom_cap():
    def circle_cap(pen, end):
        pen.arc_to(end)

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().end_cap = circle_cap
    assert_path_data(p, 0, 'M0,-1 L0,1 L5,1 A 1,1 0 0 0 5,-1 L0,-1 z')

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().start_cap = circle_cap
    assert_path_data(p, 0, 'M0,-1 A 1,1 0 1 0 0,1 L5,1 L5,-1 L0,-1 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_slant_error():
    # Creating a slant angle close to 0 is not allowed.
    p = Pen()
    p.stroke_mode(1.0)
    p.line_forward(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.line_forward(10, end_slant=0)
    seg = p.last_segment()
    assert not seg.start_joint_illegal
    assert seg.end_joint_illegal

    # A combination of angles can also create a degenerate segment.
    p = Pen()
    p.stroke_mode(1.0)
    p.line_forward(1, start_slant=40, end_slant=-40)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Exemplo n.º 8
0
def test_slant_error():
    # Creating a slant angle close to 0 is not allowed.
    p = Pen()
    p.stroke_mode(1.0)
    p.line_forward(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.line_forward(10, end_slant=0)
    seg = p.last_segment()
    assert not seg.start_joint_illegal
    assert seg.end_joint_illegal

    # A combination of angles can also create a degenerate segment.
    p = Pen()
    p.stroke_mode(1.0)
    p.line_forward(1, start_slant=40, end_slant=-40)
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Exemplo n.º 9
0
def test_degenerate_arc():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_to(
        (5, 0),
        center=(0, -200),
        start_slant=-5,
        end_slant=5,
    )
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Exemplo n.º 10
0
def test_degenerate_arc():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_to(
        (5, 0),
        center=(0, -200),
        start_slant=-5,
        end_slant=5,
    )
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
Exemplo n.º 11
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'))
Exemplo n.º 12
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'
        )
    )