File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,23 @@ def __init__(self, vertices=None):
49
49
.. note:: The polygon is represented by a Matplotlib ``Path``
50
50
"""
51
51
52
- if vertices is not None :
53
- vertices = np .array (vertices )
54
- self .path = Path (vertices .T , closed = False )
55
- self .path0 = self .path
52
+ if isinstance (vertices , (list , tuple )):
53
+ vertices = np .array (vertices ).T
54
+ elif isinstance (vertices , np .ndarray ):
55
+ if vertices .shape [0 ] != 2 :
56
+ raise ValueError ('ndarray must be 2xN' )
57
+ elif vertices is None :
58
+ return
59
+ else :
60
+ raise TypeError ('expecting list of 2-tuples or ndarray(2,N)' )
61
+
62
+ # replicate the first vertex to make it closed.
63
+ # setting closed=False and codes=None leads to a different
64
+ # path which gives incorrect intersection results
65
+ vertices = np .hstack ((vertices , vertices [:, 0 :1 ]))
66
+
67
+ self .path = Path (vertices .T , closed = True )
68
+ self .path0 = self .path
56
69
57
70
def __str__ (self ):
58
71
"""
You can’t perform that action at this time.
0 commit comments