Grafika\Gd\DrawingObject\QuadraticBezier::plotSegment PHP Method

plotSegment() protected method

Draw an limited anti-aliased quadratic Bezier segment.
protected plotSegment ( $gd, $x0, $y0, $x1, $y1, $x2, $y2 )
$gd
$x0
$y0
$x1
$y1
$x2
$y2
    protected function plotSegment($gd, $x0, $y0, $x1, $y1, $x2, $y2)
    {
        $sx = $x2 - $x1;
        $sy = $y2 - $y1;
        $xx = $x0 - $x1;
        $yy = $y0 - $y1;
        $cur = $xx * $sy - $yy * $sx;
        /* $curvature */
        assert($xx * $sx <= 0 && $yy * $sy <= 0);
        if ($sx * (int) $sx + $sy * (int) $sy > $xx * $xx + $yy * $yy) {
            /* begin with longer part */
            $x2 = $x0;
            $x0 = $sx + $x1;
            $y2 = $y0;
            $y0 = $sy + $y1;
            $cur = -$cur;
            /* swap P0 P2 */
        }
        if ($cur != 0) {
            /* no straight line */
            $xx += $sx;
            $xx *= $sx = $x0 < $x2 ? 1 : -1;
            /* x step direction */
            $yy += $sy;
            $yy *= $sy = $y0 < $y2 ? 1 : -1;
            /* y step direction */
            $xy = 2 * $xx * $yy;
            $xx *= $xx;
            $yy *= $yy;
            /* differences 2nd degree */
            if ($cur * $sx * $sy < 0) {
                /* negat$ed $curvature? */
                $xx = -$xx;
                $yy = -$yy;
                $xy = -$xy;
                $cur = -$cur;
            }
            $dx = 4.0 * $sy * ($x1 - $x0) * $cur + $xx - $xy;
            /* differences 1st degree */
            $dy = 4.0 * $sx * ($y0 - $y1) * $cur + $yy - $xy;
            $xx += $xx;
            $yy += $yy;
            $err = $dx + $dy + $xy;
            /* $error 1st step */
            do {
                $cur = min($dx + $xy, -$xy - $dy);
                $ed = max($dx + $xy, -$xy - $dy);
                /* approximate $error distance */
                $ed += 2 * $ed * $cur * $cur / (4 * $ed * $ed + $cur * $cur);
                $this->setPixel($gd, $x0, $y0, abs($err - $dx - $dy - $xy) / $ed);
                /* plot $curve */
                if ($x0 == $x2 || $y0 == $y2) {
                    break;
                }
                /* $curve finish$ed */
                $x1 = $x0;
                $cur = $dx - $err;
                $y1 = 2 * $err + $dy < 0;
                if (2 * $err + $dx > 0) {
                    /* x step */
                    if ($err - $dy < $ed) {
                        $this->setPixel($gd, $x0, $y0 + $sy, abs($err - $dy) / $ed);
                    }
                    $x0 += $sx;
                    $dx -= $xy;
                    $err += $dy += $yy;
                }
                if ($y1) {
                    /* y step */
                    if ($cur < $ed) {
                        $this->setPixel($gd, $x1 + $sx, $y0, abs($cur) / $ed);
                    }
                    $y0 += $sy;
                    $dy -= $xy;
                    $err += $dx += $xx;
                }
            } while ($dy < $dx);
            /* gradient negates -> close curves */
        }
        $this->plotLine($gd, $x0, $y0, $x2, $y2);
        /* plot remaining needle to end */
    }