Skip to content

Commit

Permalink
Merge pull request #26767 from QuLogic/fix-gouraud-nan
Browse files Browse the repository at this point in the history
Trim Gouraud triangles that contain NaN
  • Loading branch information
greglucas committed Sep 14, 2023
2 parents 4c73219 + 1d7f094 commit 1b11a77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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

0 comments on commit 1b11a77

Please sign in to comment.