Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,7 +1360,8 @@ def _get_vector(self, segments3d):
num_faces = len(segments3d)
num_verts = np.fromiter(map(len, segments3d), dtype=np.intp)
max_verts = num_verts.max(initial=0)
segments = np.empty((num_faces, max_verts, 3))
# Pad with NaN so unused entries cannot overflow during projection (#32272).
segments = np.full((num_faces, max_verts, 3), np.nan)
for i, face in enumerate(segments3d):
segments[i, :len(face)] = face
self._faces = segments
Expand Down
16 changes: 16 additions & 0 deletions lib/mpl_toolkits/mplot3d/tests/test_art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,19 @@ def test_generate_normals():
ax = fig.add_subplot(projection='3d')
ax.add_collection3d(shape)
plt.draw()


def test_poly3dcollection_ragged_padding_no_overflow():
# Ragged faces pad to a rectangular array. Padding must not overflow when
# projected before _invalid_vertices is applied. See #32272.
square = np.zeros((4, 3))
triangle = np.zeros((3, 3))
collection = Poly3DCollection([square, triangle])
assert np.all(np.isnan(collection._faces[collection._invalid_vertices]))

fig = plt.figure()
ax = fig.add_subplot(projection="3d")
ax.add_collection(collection, autolim=False)
ax.set(xlim=(0, 1), ylim=(0, 1), zlim=(0, 1))
with np.errstate(over="raise"):
fig.canvas.draw()
Loading