@@ -1441,22 +1441,36 @@ def polygon_remove_vertex(ax, xy):
14411441 ]
14421442
14431443
1444+ def polygon_complete_chain (ax , closed , xy ):
1445+ if closed :
1446+ return [
1447+ * polygon_place_vertex (ax , xy )
1448+ ]
1449+ else :
1450+ return [
1451+ KeyEvent ("key_press_event" , ax .figure .canvas , "enter" ),
1452+ KeyEvent ("key_release_event" , ax .figure .canvas , "enter" ),
1453+ ]
1454+
1455+
14441456@pytest .mark .parametrize ('draw_bounding_box' , [False , True ])
1445- def test_polygon_selector (ax , draw_bounding_box ):
1446- check_selector = functools .partial (
1447- check_polygon_selector , draw_bounding_box = draw_bounding_box )
1457+ @pytest .mark .parametrize ('closed' , [False , True ])
1458+ def test_polygon_selector (ax , draw_bounding_box , closed ):
1459+ check_selector = functools .partial (check_polygon_selector ,
1460+ draw_bounding_box = draw_bounding_box ,
1461+ closed = closed )
14481462
1449- # Simple polygon
1463+ # Simple polygonal chain.
14501464 expected_result = [(50 , 50 ), (150 , 50 ), (50 , 150 )]
14511465 event_sequence = [
14521466 * polygon_place_vertex (ax , (50 , 50 )),
14531467 * polygon_place_vertex (ax , (150 , 50 )),
14541468 * polygon_place_vertex (ax , (50 , 150 )),
1455- * polygon_place_vertex (ax , (50 , 50 )),
1469+ * polygon_complete_chain (ax , closed , (50 , 50 )),
14561470 ]
14571471 check_selector (event_sequence , expected_result , 1 )
14581472
1459- # Move first vertex before completing the polygon .
1473+ # Move first vertex before completing the polygonal chain .
14601474 expected_result = [(75 , 50 ), (150 , 50 ), (50 , 150 )]
14611475 event_sequence = [
14621476 * polygon_place_vertex (ax , (50 , 50 )),
@@ -1468,11 +1482,11 @@ def test_polygon_selector(ax, draw_bounding_box):
14681482 MouseEvent ._from_ax_coords ("button_release_event" , ax , (75 , 50 ), 1 ),
14691483 KeyEvent ("key_release_event" , ax .figure .canvas , "control" ),
14701484 * polygon_place_vertex (ax , (50 , 150 )),
1471- * polygon_place_vertex (ax , (75 , 50 )),
1485+ * polygon_complete_chain (ax , closed , (75 , 50 )),
14721486 ]
14731487 check_selector (event_sequence , expected_result , 1 )
14741488
1475- # Move first two vertices at once before completing the polygon .
1489+ # Move first two vertices at once before completing the polygonal chain .
14761490 expected_result = [(50 , 75 ), (150 , 75 ), (50 , 150 )]
14771491 event_sequence = [
14781492 * polygon_place_vertex (ax , (50 , 50 )),
@@ -1484,31 +1498,31 @@ def test_polygon_selector(ax, draw_bounding_box):
14841498 MouseEvent ._from_ax_coords ("button_release_event" , ax , (100 , 125 ), 1 ),
14851499 KeyEvent ("key_release_event" , ax .figure .canvas , "shift" ),
14861500 * polygon_place_vertex (ax , (50 , 150 )),
1487- * polygon_place_vertex (ax , (50 , 75 )),
1501+ * polygon_complete_chain (ax , closed , (50 , 75 )),
14881502 ]
14891503 check_selector (event_sequence , expected_result , 1 )
14901504
1491- # Move first vertex after completing the polygon .
1505+ # Move first vertex after completing the polygonal chain .
14921506 expected_result = [(85 , 50 ), (150 , 50 ), (50 , 150 )]
14931507 event_sequence = [
14941508 * polygon_place_vertex (ax , (60 , 50 )),
14951509 * polygon_place_vertex (ax , (150 , 50 )),
14961510 * polygon_place_vertex (ax , (50 , 150 )),
1497- * polygon_place_vertex (ax , (60 , 50 )),
1511+ * polygon_complete_chain (ax , closed , (60 , 50 )),
14981512 MouseEvent ._from_ax_coords ("motion_notify_event" , ax , (60 , 50 )),
14991513 MouseEvent ._from_ax_coords ("button_press_event" , ax , (60 , 50 ), 1 ),
15001514 MouseEvent ._from_ax_coords ("motion_notify_event" , ax , (85 , 50 )),
15011515 MouseEvent ._from_ax_coords ("button_release_event" , ax , (85 , 50 ), 1 ),
15021516 ]
15031517 check_selector (event_sequence , expected_result , 2 )
15041518
1505- # Move all vertices after completing the polygon .
1519+ # Move all vertices after completing the polygonal chain .
15061520 expected_result = [(75 , 75 ), (175 , 75 ), (75 , 175 )]
15071521 event_sequence = [
15081522 * polygon_place_vertex (ax , (50 , 50 )),
15091523 * polygon_place_vertex (ax , (150 , 50 )),
15101524 * polygon_place_vertex (ax , (50 , 150 )),
1511- * polygon_place_vertex (ax , (50 , 50 )),
1525+ * polygon_complete_chain (ax , closed , (50 , 50 )),
15121526 KeyEvent ("key_press_event" , ax .figure .canvas , "shift" ),
15131527 MouseEvent ._from_ax_coords ("motion_notify_event" , ax , (100 , 100 )),
15141528 MouseEvent ._from_ax_coords ("button_press_event" , ax , (100 , 100 ), 1 ),
@@ -1536,11 +1550,11 @@ def test_polygon_selector(ax, draw_bounding_box):
15361550 * polygon_place_vertex (ax , (50 , 50 )),
15371551 * polygon_place_vertex (ax , (150 , 50 )),
15381552 * polygon_place_vertex (ax , (50 , 150 )),
1539- * polygon_place_vertex (ax , (50 , 50 )),
1553+ * polygon_complete_chain (ax , closed , (50 , 50 )),
15401554 ]
15411555 check_selector (event_sequence , expected_result , 1 )
15421556
1543- # Try to place vertex out-of-bounds, then reset, and start a new polygon .
1557+ # Try to place vertex out-of-bounds, then reset, and start a new polygonal chain .
15441558 expected_result = [(50 , 50 ), (150 , 50 ), (50 , 150 )]
15451559 event_sequence = [
15461560 * polygon_place_vertex (ax , (50 , 50 )),
@@ -1550,7 +1564,7 @@ def test_polygon_selector(ax, draw_bounding_box):
15501564 * polygon_place_vertex (ax , (50 , 50 )),
15511565 * polygon_place_vertex (ax , (150 , 50 )),
15521566 * polygon_place_vertex (ax , (50 , 150 )),
1553- * polygon_place_vertex (ax , (50 , 50 )),
1567+ * polygon_complete_chain (ax , closed , (50 , 50 )),
15541568 ]
15551569 check_selector (event_sequence , expected_result , 1 )
15561570
@@ -1599,35 +1613,37 @@ def test_rect_visibility(fig_test, fig_ref):
15991613# Change the order that the extra point is inserted in
16001614@pytest .mark .parametrize ('idx' , [1 , 2 , 3 ])
16011615@pytest .mark .parametrize ('draw_bounding_box' , [False , True ])
1602- def test_polygon_selector_remove (ax , idx , draw_bounding_box ):
1616+ @pytest .mark .parametrize ('closed' , [False , True ])
1617+ def test_polygon_selector_remove (ax , idx , draw_bounding_box , closed ):
16031618 verts = [(50 , 50 ), (150 , 50 ), (50 , 150 )]
16041619 event_sequence = [polygon_place_vertex (ax , verts [0 ]),
16051620 polygon_place_vertex (ax , verts [1 ]),
16061621 polygon_place_vertex (ax , verts [2 ]),
16071622 # Finish the polygon
1608- polygon_place_vertex (ax , verts [0 ])]
1623+ polygon_complete_chain (ax , closed , verts [0 ])]
16091624 # Add an extra point
16101625 event_sequence .insert (idx , polygon_place_vertex (ax , (200 , 200 )))
16111626 # Remove the extra point
16121627 event_sequence .append (polygon_remove_vertex (ax , (200 , 200 )))
16131628 # Flatten list of lists
16141629 event_sequence = functools .reduce (operator .iadd , event_sequence , [])
16151630 check_polygon_selector (event_sequence , verts , 2 ,
1616- draw_bounding_box = draw_bounding_box )
1631+ draw_bounding_box = draw_bounding_box , closed = closed )
16171632
16181633
16191634@pytest .mark .parametrize ('draw_bounding_box' , [False , True ])
1620- def test_polygon_selector_remove_first_point (ax , draw_bounding_box ):
1635+ @pytest .mark .parametrize ('closed' , [False , True ])
1636+ def test_polygon_selector_remove_first_point (ax , draw_bounding_box , closed ):
16211637 verts = [(50 , 50 ), (150 , 50 ), (50 , 150 )]
16221638 event_sequence = [
16231639 * polygon_place_vertex (ax , verts [0 ]),
16241640 * polygon_place_vertex (ax , verts [1 ]),
16251641 * polygon_place_vertex (ax , verts [2 ]),
1626- * polygon_place_vertex (ax , verts [0 ]),
1642+ * polygon_complete_chain (ax , closed , verts [0 ]),
16271643 * polygon_remove_vertex (ax , verts [0 ]),
16281644 ]
16291645 check_polygon_selector (event_sequence , verts [1 :], 2 ,
1630- draw_bounding_box = draw_bounding_box )
1646+ draw_bounding_box = draw_bounding_box , closed = closed )
16311647
16321648
16331649@pytest .mark .parametrize ('draw_bounding_box' , [False , True ])
0 commit comments