Handle case where path count is zero

This commit is contained in:
Andrew Murray 2021-12-06 22:25:14 +11:00
parent 1e092419b6
commit c48271ab35
2 changed files with 20 additions and 14 deletions

View File

@ -90,6 +90,7 @@ def test_path_odd_number_of_coordinates():
[ [
([0, 1, 2, 3], (0.0, 1.0, 2.0, 3.0)), ([0, 1, 2, 3], (0.0, 1.0, 2.0, 3.0)),
([3, 2, 1, 0], (1.0, 0.0, 3.0, 2.0)), ([3, 2, 1, 0], (1.0, 0.0, 3.0, 2.0)),
(0, (0.0, 0.0, 0.0, 0.0)),
(1, (0.0, 0.0, 0.0, 0.0)), (1, (0.0, 0.0, 0.0, 0.0)),
], ],
) )

View File

@ -327,6 +327,10 @@ path_getbbox(PyPathObject *self, PyObject *args) {
xy = self->xy; xy = self->xy;
if (self->count == 0) {
x0 = x1 = 0;
y0 = y1 = 0;
} else {
x0 = x1 = xy[0]; x0 = x1 = xy[0];
y0 = y1 = xy[1]; y0 = y1 = xy[1];
@ -344,6 +348,7 @@ path_getbbox(PyPathObject *self, PyObject *args) {
y1 = xy[i + i + 1]; y1 = xy[i + i + 1];
} }
} }
}
return Py_BuildValue("dddd", x0, y0, x1, y1); return Py_BuildValue("dddd", x0, y0, x1, y1);
} }