private function drawFilledTriangleHorizontally(awGradient $gradient, awPolygon $polygon) { list($xMin, $xMax) = $polygon->getBoxXRange(); $this->init($gradient, $xMax - $xMin); // Get the triangle line we will draw our lines from $fromLine = NULL; $lines = $polygon->getLines(); $count = count($lines); // Pick the side of the triangle going all the way // from the left side to the right side of the surrounding box for ($i = 0; $i < $count; $i++) { if ($lines[$i]->isLeftToRight($polygon)) { list($fromLine) = array_splice($lines, $i, 1); break; } } // If for some reason the three points are aligned, // $fromLine will still be NULL if ($fromLine === NULL) { return; } $fillLine = NULL; for ($x = round($xMin); $x < round($xMax); $x++) { $fromY = floor($fromLine->getYFrom($x)); $toY = array(); foreach ($lines as $line) { $yValue = $line->getYFrom($x); if (!is_null($yValue)) { $toY[] = floor($yValue); } } if (count($toY) === 1) { $fillLine = new Line(new Point($x, $fromY), new Point($x, $toY[0])); } else { $line1 = new Line(new Point($x, $fromY), new Point($x, $toY[0])); $line2 = new Line(new Point($x, $fromY), new Point($x, $toY[1])); if ($line1->getSize() < $line2->getSize()) { $fillLine = $line1; } else { $fillLine = $line2; } } $color = $this->color($x - $xMin); if ($fillLine->isPoint()) { $this->driver->point($color, $fillLine->p1); } elseif ($fillLine->getSize() >= 1) { $this->driver->line($color, $fillLine); } unset($color); } }