Skip to content

Commit

Permalink
prevent drawLine from drawing out of bounds
Browse files Browse the repository at this point in the history
the "smooth" variant was sometimes producing XY positions outside the canvas.
  • Loading branch information
softhack007 committed Oct 24, 2024
1 parent fe5eaed commit 05adb7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,13 @@ void Segment::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint3
int y = int(intersectY);
if (steep) std::swap(x,y); // temporarily swap if steep
// pixel coverage is determined by fractional part of y co-ordinate
setPixelColorXY(x, y, color_blend(c, getPixelColorXY(x, y), keep, true));
setPixelColorXY(x+int(steep), y+int(!steep), color_blend(c, getPixelColorXY(x+int(steep), y+int(!steep)), seep, true));

// WLEDMM added out-of-bounds check: "unsigned(x) < cols" catches negative numbers _and_ too large values
if ((unsigned(x) < unsigned(cols)) && (unsigned(y) < unsigned(rows))) setPixelColorXY(x, y, color_blend(c, getPixelColorXY(x, y), keep, true));
int xx = x+int(steep);
int yy = y+int(!steep);
if ((unsigned(xx) < unsigned(cols)) && (unsigned(yy) < unsigned(rows))) setPixelColorXY(xx, yy, color_blend(c, getPixelColorXY(xx, yy), seep, true));

intersectY += gradient;
if (steep) std::swap(x,y); // restore if steep
}
Expand Down

0 comments on commit 05adb7d

Please sign in to comment.