Skip to content

Commit

Permalink
Handle case where path count is zero
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jan 1, 2022
1 parent 1e09241 commit c48271a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions Tests/test_imagepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_path_odd_number_of_coordinates():
[
([0, 1, 2, 3], (0.0, 1.0, 2.0, 3.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)),
],
)
Expand Down
33 changes: 19 additions & 14 deletions src/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,26 @@ path_getbbox(PyPathObject *self, PyObject *args) {

xy = self->xy;

x0 = x1 = xy[0];
y0 = y1 = xy[1];
if (self->count == 0) {
x0 = x1 = 0;
y0 = y1 = 0;
} else {
x0 = x1 = xy[0];
y0 = y1 = xy[1];

for (i = 1; i < self->count; i++) {
if (xy[i + i] < x0) {
x0 = xy[i + i];
}
if (xy[i + i] > x1) {
x1 = xy[i + i];
}
if (xy[i + i + 1] < y0) {
y0 = xy[i + i + 1];
}
if (xy[i + i + 1] > y1) {
y1 = xy[i + i + 1];
for (i = 1; i < self->count; i++) {
if (xy[i + i] < x0) {
x0 = xy[i + i];
}
if (xy[i + i] > x1) {
x1 = xy[i + i];
}
if (xy[i + i + 1] < y0) {
y0 = xy[i + i + 1];
}
if (xy[i + i + 1] > y1) {
y1 = xy[i + i + 1];
}
}
}

Expand Down

0 comments on commit c48271a

Please sign in to comment.