Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim Gouraud triangles that contain NaN #26767

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ def test_pcolormesh_pre_transform_limits():
assert_almost_equal(expected, ax.dataLim.get_points())


def test_pcolormesh_gouraud_nans():
np.random.seed(19680801)

values = np.linspace(0, 180, 3)
radii = np.linspace(100, 1000, 10)
z, y = np.meshgrid(values, radii)
x = np.radians(np.random.rand(*z.shape) * 100)

fig = plt.figure()
ax = fig.add_subplot(111, projection="polar")
# Setting the limit to cause clipping of the r values causes NaN to be
# introduced; these should not crash but be ignored as in other path
# operations.
ax.set_rlim(101, 1000)
ax.pcolormesh(x, y, z, shading="gouraud")

fig.canvas.draw()


def test_Affine2D_from_values():
points = np.array([[0, 0],
[10, 20],
Expand Down
3 changes: 3 additions & 0 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,9 @@ inline void RendererAgg::_draw_gouraud_triangle(PointArray &points,
tpoints[i][j] = points(i, j);
}
trans.transform(&tpoints[i][0], &tpoints[i][1]);
if(std::isnan(tpoints[i][0]) || std::isnan(tpoints[i][1])) {
return;
}
}

span_alloc_t span_alloc;
Expand Down