Skip to content

Commit ea75c4f

Browse files
greglucasanntzer
authored andcommitted
FIX: Skip any nan coordinates in quadmesh
Even though the coordinates of quadmesh are meant to be finite, a transform may make them nonfinite. This adds a check to avoid the nan quads in the quadmesh rendering routine.
1 parent 68b4558 commit ea75c4f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ext/_mplcairo.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,16 @@ void GraphicsContextRenderer::draw_quad_mesh(
14831483
if (ecs_raw.shape(0)) {
14841484
for (auto i = 0; i < mesh_height; ++i) {
14851485
for (auto j = 0; j < mesh_width; ++j) {
1486+
if (!(std::isfinite(coords_raw(i, j, 0))
1487+
&& std::isfinite(coords_raw(i, j, 1))
1488+
&& std::isfinite(coords_raw(i, j + 1, 0))
1489+
&& std::isfinite(coords_raw(i, j + 1, 1))
1490+
&& std::isfinite(coords_raw(i + 1, j, 0))
1491+
&& std::isfinite(coords_raw(i + 1, j, 1))
1492+
&& std::isfinite(coords_raw(i + 1, j + 1, 0))
1493+
&& std::isfinite(coords_raw(i + 1, j + 1, 1)))) {
1494+
continue;
1495+
}
14861496
cairo_move_to(
14871497
cr_, coords_raw(i, j, 0), coords_raw(i, j, 1));
14881498
cairo_line_to(
@@ -1506,6 +1516,16 @@ void GraphicsContextRenderer::draw_quad_mesh(
15061516
auto const& pattern = cairo_pattern_create_mesh();
15071517
for (auto i = 0; i < mesh_height; ++i) {
15081518
for (auto j = 0; j < mesh_width; ++j) {
1519+
if (!(std::isfinite(coords_raw(i, j, 0))
1520+
&& std::isfinite(coords_raw(i, j, 1))
1521+
&& std::isfinite(coords_raw(i, j + 1, 0))
1522+
&& std::isfinite(coords_raw(i, j + 1, 1))
1523+
&& std::isfinite(coords_raw(i + 1, j, 0))
1524+
&& std::isfinite(coords_raw(i + 1, j, 1))
1525+
&& std::isfinite(coords_raw(i + 1, j + 1, 0))
1526+
&& std::isfinite(coords_raw(i + 1, j + 1, 1)))) {
1527+
continue;
1528+
}
15091529
cairo_mesh_pattern_begin_patch(pattern);
15101530
cairo_mesh_pattern_move_to(
15111531
pattern, coords_raw(i, j, 0), coords_raw(i, j, 1));

0 commit comments

Comments
 (0)