You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored)
Horizontal lines (and I suspect vertical ones too) are not drawn. The Bresenham algorithm is not fully / correctly implemented for the Arduino files that use edppaint.cpp
Never mind that I can test before calling to see if the line is Horz. or Vert. and then call the appropriate routine as this one should handle all edge cases. Below is my code correction. It also alters the duplicate "2 * err" code to execute only once.
`void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored) {
/* Corrected Bresenham algorithm */
int dx = x1 - x0 >= 0 ? x1 - x0 : x0 - x1;
int sx = x0 < x1 ? 1 : -1;
int dy = y1 - y0 <= 0 ? y1 - y0 : y0 - y1;
int sy = y0 < y1 ? 1 : -1;
int err = dx + dy;
int e2;
while(true)
{
if ((x0 == x1) && (y0 == y1)) break;
DrawPixel(x0, y0 , colored);
e2 = 2 * err;
if (e2 >= dy) {
if (x0 == x1) break;
err += dy;
x0 += sx;
}
if (e2 <= dx) {
if (y0 == y1) break;
err += dx;
y0 += sy;
}
}
}
`
The text was updated successfully, but these errors were encountered:
void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored)
Horizontal lines (and I suspect vertical ones too) are not drawn. The Bresenham algorithm is not fully / correctly implemented for the Arduino files that use edppaint.cpp
Never mind that I can test before calling to see if the line is Horz. or Vert. and then call the appropriate routine as this one should handle all edge cases. Below is my code correction. It also alters the duplicate "2 * err" code to execute only once.
`void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored) {
}
`
The text was updated successfully, but these errors were encountered: