protected function plotLine($gd, $x0, $y0, $x1, $y1)
{
/* draw a black (0) anti-aliased line on white (255) background */
$dx = abs($x1 - $x0);
$sx = $x0 < $x1 ? 1 : -1;
$dy = -abs($y1 - $y0);
$sy = $y0 < $y1 ? 1 : -1;
$err = $dx + $dy;
$e2 = $x2 = 0;
/* $error value e_xy */
$ed = $dx - $dy == 0 ? 1 : sqrt((double) $dx * $dx + (double) $dy * $dy);
for (;;) {
/* pixel loop */
$this->setPixel($gd, $x0, $y0, abs($err - $dx - $dy) / $ed);
$e2 = $err;
$x2 = $x0;
if (2 * $e2 + $dx >= 0) {
/* x step */
if ($x0 == $x1) {
break;
}
if ($e2 - $dy < $ed) {
$this->setPixel($gd, $x0, $y0 + $sy, ($e2 - $dy) / $ed);
}
$err += $dy;
$x0 += $sx;
}
if (2 * $e2 + $dy <= 0) {
/* y step */
if ($y0 == $y1) {
break;
}
if ($dx - $e2 < $ed) {
$this->setPixel($gd, $x2 + $sx, $y0, ($dx - $e2) / $ed);
}
$err += $dx;
$y0 += $sy;
}
}
}