Skip to content

Commit 0554f6e

Browse files
committed
Test redrawing from one point
1 parent c289c42 commit 0554f6e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,29 @@ def test_polygon_selector_remove_first_point():
598598
polygon_place_vertex(*verts[0]) +
599599
polygon_remove_vertex(*verts[0]))
600600
check_polygon_selector(event_sequence, verts[1:], 2)
601+
602+
603+
def test_polygon_selector_redraw():
604+
verts = [(50, 50), (150, 50), (50, 150)]
605+
event_sequence = (polygon_place_vertex(*verts[0]) +
606+
polygon_place_vertex(*verts[1]) +
607+
polygon_place_vertex(*verts[2]) +
608+
polygon_place_vertex(*verts[0]) +
609+
# Polygon completed, now remove first two verts
610+
polygon_remove_vertex(*verts[1]) +
611+
polygon_remove_vertex(*verts[2]) +
612+
# At this point the tool should be reset so we can add
613+
# more vertices
614+
polygon_place_vertex(*verts[1]))
615+
616+
ax = get_ax()
617+
618+
def onselect(vertices):
619+
pass
620+
621+
tool = widgets.PolygonSelector(ax, onselect)
622+
for (etype, event_args) in event_sequence:
623+
do_event(tool, etype, **event_args)
624+
# After removing two verts, only one remains, and the
625+
# selector should be automatically resete
626+
assert tool.verts == verts[0:2]

lib/matplotlib/widgets.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2795,6 +2795,12 @@ class PolygonSelector(_SelectorWidget):
27952795
Examples
27962796
--------
27972797
:doc:`/gallery/widgets/polygon_selector_demo`
2798+
2799+
Notes
2800+
-----
2801+
If only one point remains after removing points, the selector reverts to an
2802+
incomplete state and you can start drawing a new polygon from the existing
2803+
point.
27982804
"""
27992805

28002806
def __init__(self, ax, onselect, useblit=False,

0 commit comments

Comments
 (0)