in libs/screen/image.cpp [954:1030]
void drawLine(Image_ img, int x0, int y0, int x1, int y1, int c) {
if (x1 < x0) {
drawLine(img, x1, y1, x0, y0, c);
return;
}
int w = x1 - x0;
int h = y1 - y0;
if (h == 0) {
if (w == 0)
setPixel(img, x0, y0, c);
else
fillRect(img, x0, y0, w + 1, 1, c);
return;
}
if (w == 0) {
if (h > 0)
fillRect(img, x0, y0, 1, h + 1, c);
else
fillRect(img, x0, y1, 1, -h + 1, c);
return;
}
if (x1 < 0 || x0 >= img->width())
return;
if (x0 < 0) {
y0 -= (h * x0 / w);
x0 = 0;
}
if (x1 >= img->width()) {
int d = (img->width() - 1) - x1;
y1 += (h * d / w);
x1 = img->width() - 1;
}
if (y0 < y1) {
if (y0 >= img->height() || y1 < 0)
return;
if (y0 < 0) {
x0 -= (w * y0 / h);
y0 = 0;
}
if (y1 >= img->height()) {
int d = (img->height() - 1) - y1;
x1 += (w * d / h);
y1 = img->height() - 1;
}
} else {
if (y1 >= img->height() || y0 < 0)
return;
if (y1 < 0) {
x1 -= (w * y1 / h);
y1 = 0;
}
if (y0 >= img->height()) {
int d = (img->height() - 1) - y0;
x0 += (w * d / h);
y0 = img->height() - 1;
}
}
img->makeWritable();
if (h < 0) {
h = -h;
if (h < w)
drawLineLow(img, x0, y0, x1, y1, c);
else
drawLineHigh(img, x1, y1, x0, y0, c);
} else {
if (h < w)
drawLineLow(img, x0, y0, x1, y1, c);
else
drawLineHigh(img, x0, y0, x1, y1, c);
}
}