@@ -1090,23 +1090,37 @@ def set_verts(self, verts, closed=True):
1090
1090
Whether the polygon should be closed by adding a CLOSEPOLY
1091
1091
connection at the end.
1092
1092
"""
1093
+ self .stale = True
1093
1094
if isinstance (verts , np .ma .MaskedArray ):
1094
1095
verts = verts .astype (float ).filled (np .nan )
1095
- # This is much faster than having Path do it one at a time.
1096
- if closed :
1097
- self ._paths = []
1098
- for xy in verts :
1099
- if len (xy ):
1100
- if isinstance (xy , np .ma .MaskedArray ):
1101
- xy = np .ma .concatenate ([xy , xy [:1 ]])
1102
- else :
1103
- xy = np .concatenate ([xy , xy [:1 ]])
1104
- self ._paths .append (mpath .Path (xy , closed = True ))
1105
- else :
1106
- self ._paths .append (mpath .Path (xy ))
1107
- else :
1096
+
1097
+ # No need to do anything fancy if the path isn't closed.
1098
+ if not closed :
1108
1099
self ._paths = [mpath .Path (xy ) for xy in verts ]
1109
- self .stale = True
1100
+ return
1101
+
1102
+ # Fast path for arrays
1103
+ if isinstance (verts , np .ndarray ):
1104
+ verts_pad = np .concatenate ((verts , verts [:, :1 ]), axis = 1 )
1105
+ # Creating the codes once is much faster than having Path do it
1106
+ # separately each time by passing closed=True.
1107
+ codes = np .empty (verts_pad .shape [1 ], dtype = mpath .Path .code_type )
1108
+ codes [:] = mpath .Path .LINETO
1109
+ codes [0 ] = mpath .Path .MOVETO
1110
+ codes [- 1 ] = mpath .Path .CLOSEPOLY
1111
+ self ._paths = [mpath .Path (xy , codes ) for xy in verts_pad ]
1112
+ return
1113
+
1114
+ self ._paths = []
1115
+ for xy in verts :
1116
+ if len (xy ):
1117
+ if isinstance (xy , np .ma .MaskedArray ):
1118
+ xy = np .ma .concatenate ([xy , xy [:1 ]])
1119
+ else :
1120
+ xy = np .concatenate ([xy , xy [:1 ]])
1121
+ self ._paths .append (mpath .Path (xy , closed = True ))
1122
+ else :
1123
+ self ._paths .append (mpath .Path (xy ))
1110
1124
1111
1125
set_paths = set_verts
1112
1126
0 commit comments