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' ), )
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' )
def test_arc_joint_numerical(): # Sometimes arc joints can miss the mark if they have odd float numbers. p = Pen() p.stroke_mode(0.5) p.move_to((-26.685559703113075, 65.00539003547281)) p.turn_to(202.85281173472714) p.arc_right(180, 1) # This shouldn't error: p.arc_right(50.443252846269075, center=(0.5, 0.5))
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', )
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) )
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' ), )
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' ) )