Index: src/gfx.cpp =================================================================== --- src/gfx.cpp (revision 27323) +++ src/gfx.cpp (working copy) @@ -175,30 +175,24 @@ assert(width > 0); + /* Clipping rectangle. Slightly extended so we can ignore the width of the line. */ + uint extra = CeilDiv(3 * width, 4); // not less then "width * sqrt(2) / 2" + Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra }; + if (y2 == y) { /* Special case: horizontal line. */ - blitter->DrawLine(video, - Clamp(x, 0, screen_width), y, - Clamp(x2, 0, screen_width), y2, - screen_width, screen_height, colour, width, dash); + if (y >= clip.top && y <= clip.bottom) blitter->DrawLine(video, x, y, x2, y, screen_width, screen_height, colour, width, dash); return; } if (x2 == x) { /* Special case: vertical line. */ - blitter->DrawLine(video, - x, Clamp(y, 0, screen_height), - x2, Clamp(y2, 0, screen_height), - screen_width, screen_height, colour, width, dash); + if (x >= clip.left && x <= clip.right) blitter->DrawLine(video, x, y, x2, y, screen_width, screen_height, colour, width, dash); return; } int grade_y = y2 - y; int grade_x = x2 - x; - /* Clipping rectangle. Slightly extended so we can ignore the width of the line. */ - uint extra = CeilDiv(3 * width, 4); // not less then "width * sqrt(2) / 2" - Rect clip = { -extra, -extra, screen_width - 1 + extra, screen_height - 1 + extra }; - /* prevent integer overflows. */ int margin = 1; while (INT_MAX / abs(grade_y) < max(abs(clip.left - x), abs(clip.right - x))) {