diff --git a/lib/matplotlib/tests/test_path.py b/lib/matplotlib/tests/test_path.py index 8250e37b9f88..090409a608da 100644 --- a/lib/matplotlib/tests/test_path.py +++ b/lib/matplotlib/tests/test_path.py @@ -61,6 +61,15 @@ def test_path_clipping(): xy, facecolor='none', edgecolor='red', closed=True)) +def test_point_in_path_nan(): + box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]) + p = Path(box) + test = np.array([[np.nan, 0.5]]) + contains = p.contains_points(test) + assert len(contains) == 1 + assert not contains[0] + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) diff --git a/src/_path.cpp b/src/_path.cpp index 783aee0654f9..f9c77719f383 100644 --- a/src/_path.cpp +++ b/src/_path.cpp @@ -165,10 +165,12 @@ point_in_path_impl(const void* const points_, const size_t s0, for (i = 0; i < n; ++i) { ty = *(double *)(points + s0 * i + s1); - // get test bit for above/below X axis - yflag0[i] = (vty0 >= ty); + if (MPL_isfinite64(ty)) { + // get test bit for above/below X axis + yflag0[i] = (vty0 >= ty); - subpath_flag[i] = 0; + subpath_flag[i] = 0; + } } do @@ -191,6 +193,10 @@ point_in_path_impl(const void* const points_, const size_t s0, tx = *(double *)(points + s0 * i); ty = *(double *)(points + s0 * i + s1); + if (MPL_notisfinite64(tx) || MPL_notisfinite64(ty)) { + continue; + } + yflag1 = (vty1 >= ty); // Check if endpoints straddle (are on opposite sides) of // X axis (i.e. the Y's differ); if so, +X ray could @@ -237,6 +243,10 @@ point_in_path_impl(const void* const points_, const size_t s0, tx = *(double *)(points + s0 * i); ty = *(double *)(points + s0 * i + s1); + if (MPL_notisfinite64(tx) || MPL_notisfinite64(ty)) { + continue; + } + yflag1 = (vty1 >= ty); if (yflag0[i] != yflag1) { if (((vty1 - ty) * (vtx0 - vtx1) >=