File tree 2 files changed +23
-2
lines changed 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -1066,13 +1066,27 @@ def set_xy(self, xy):
1066
1066
----------
1067
1067
xy : (N, 2) array-like
1068
1068
The coordinates of the vertices.
1069
+
1070
+ Notes
1071
+ -----
1072
+ Unlike `~.path.Path`, we do not ignore the last input vertex. If the
1073
+ polygon is meant to be closed, and the last point of the polygon is not
1074
+ equal to the first, we assume that the user has not explicitly passed a
1075
+ ``CLOSEPOLY`` vertex, and add it ourselves.
1069
1076
"""
1070
1077
xy = np .asarray (xy )
1078
+ nverts , _ = xy .shape
1071
1079
if self ._closed :
1072
- if len (xy ) and (xy [0 ] != xy [- 1 ]).any ():
1080
+ # if the first and last vertex are the "same", then we assume that
1081
+ # the user explicitly passed the CLOSEPOLY vertex. Otherwise, we
1082
+ # have to append one since the last vertex will be "ignored" by
1083
+ # Path
1084
+ if nverts == 1 or nverts > 1 and (xy [0 ] != xy [- 1 ]).any ():
1073
1085
xy = np .concatenate ([xy , [xy [0 ]]])
1074
1086
else :
1075
- if len (xy ) > 2 and (xy [0 ] == xy [- 1 ]).all ():
1087
+ # if we aren't closed, and the last vertex matches the first, then
1088
+ # we assume we have an unecessary CLOSEPOLY vertex and remove it
1089
+ if nverts > 2 and (xy [0 ] == xy [- 1 ]).all ():
1076
1090
xy = xy [:- 1 ]
1077
1091
self ._path = Path (xy , closed = self ._closed )
1078
1092
self .stale = True
Original file line number Diff line number Diff line change 7
7
8
8
from matplotlib .patches import Polygon , Rectangle , FancyArrowPatch
9
9
from matplotlib .testing .decorators import image_comparison , check_figures_equal
10
+ from matplotlib .transforms import Bbox
10
11
import matplotlib .pyplot as plt
11
12
from matplotlib import (
12
13
collections as mcollections , colors as mcolors , patches as mpatches ,
@@ -556,3 +557,9 @@ def test_rotated_arcs():
556
557
ax .axvline (0 , color = "k" )
557
558
ax .set_axis_off ()
558
559
ax .set_aspect ("equal" )
560
+
561
+
562
+ def test_degenerate_polygon ():
563
+ point = [0 , 0 ]
564
+ correct_extents = Bbox ([point , point ]).extents
565
+ assert np .all (Polygon ([point ]).get_extents ().extents == correct_extents )
You can’t perform that action at this time.
0 commit comments