@@ -1090,28 +1090,41 @@ 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
1094
+ # This is much faster than having Path do it one at a time.
1093
1095
if isinstance (verts , np .ma .MaskedArray ):
1094
1096
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 [0 :1 ]])
1102
- else :
1103
- xy = np .asarray (xy )
1104
- xy = np .concatenate ([xy , xy [0 :1 ]])
1105
- codes = np .empty (xy .shape [0 ], dtype = mpath .Path .code_type )
1106
- codes [:] = mpath .Path .LINETO
1107
- codes [0 ] = mpath .Path .MOVETO
1108
- codes [- 1 ] = mpath .Path .CLOSEPOLY
1109
- self ._paths .append (mpath .Path (xy , codes ))
1110
- else :
1111
- self ._paths .append (mpath .Path (xy ))
1112
- else :
1097
+
1098
+ # No need to do anything fancy if the path isn't closed.
1099
+ if not closed :
1113
1100
self ._paths = [mpath .Path (xy ) for xy in verts ]
1114
- self .stale = True
1101
+ return
1102
+
1103
+ # Fast path for arrays
1104
+ if isinstance (verts , np .ndarray ):
1105
+ verts_pad = np .concatenate ((verts , verts [:, - 1 :]), axis = 1 )
1106
+ codes = np .empty (verts_pad .shape [1 ], dtype = mpath .Path .code_type )
1107
+ codes [:] = mpath .Path .LINETO
1108
+ codes [0 ] = mpath .Path .MOVETO
1109
+ codes [- 1 ] = mpath .Path .CLOSEPOLY
1110
+ self ._paths = [mpath .Path (xy , codes ) for xy in verts_pad ]
1111
+ return
1112
+
1113
+ self ._paths = []
1114
+ for xy in verts :
1115
+ if len (xy ):
1116
+ if isinstance (xy , np .ma .MaskedArray ):
1117
+ xy = np .ma .concatenate ([xy , xy [0 :1 ]])
1118
+ else :
1119
+ xy = np .asarray (xy )
1120
+ xy = np .concatenate ([xy , xy [0 :1 ]])
1121
+ codes = np .empty (xy .shape [0 ], dtype = mpath .Path .code_type )
1122
+ codes [:] = mpath .Path .LINETO
1123
+ codes [0 ] = mpath .Path .MOVETO
1124
+ codes [- 1 ] = mpath .Path .CLOSEPOLY
1125
+ self ._paths .append (mpath .Path (xy , codes ))
1126
+ else :
1127
+ self ._paths .append (mpath .Path (xy ))
1115
1128
1116
1129
set_paths = set_verts
1117
1130
0 commit comments