copy() public method

public copy ( )
Beispiel #1
0
 /**
  * @covers ColorThief\VBox::copy
  */
 public function testCopy()
 {
     $this->vbox->histo = array(25 => 8);
     $copy = $this->vbox->copy();
     $this->assertInstanceOf('ColorThief\\VBox', $copy);
     $this->assertSame($this->vbox->r1, $copy->r1);
     $this->assertSame($this->vbox->r2, $copy->r2);
     $this->assertSame($this->vbox->g1, $copy->g1);
     $this->assertSame($this->vbox->g2, $copy->g2);
     $this->assertSame($this->vbox->b1, $copy->b1);
     $this->assertSame($this->vbox->b2, $copy->b2);
     $this->assertSame($this->vbox->histo, $copy->histo);
 }
 /**
  * @param array $histo
  * @param VBox $vBox
  * @return array|void
  */
 private static function medianCutApply($histo, $vBox)
 {
     if (!$vBox->count()) {
         return;
     }
     // If the vbox occupies just one element in color space, it can't be split
     if ($vBox->count() == 1) {
         return array($vBox->copy());
     }
     // Select the longest axis for splitting
     $cutColor = $vBox->longestAxis();
     // Find the partial sum arrays along the selected axis.
     list($total, $partialSum) = static::sumColors($cutColor, $histo, $vBox);
     return static::doCut($cutColor, $vBox, $partialSum, $total);
 }
 /**
  * @param array $histo
  * @param VBox $vBox
  * @return array|void
  */
 private static function medianCutApply($histo, $vBox)
 {
     if (!$vBox->count()) {
         return;
     }
     // If the vbox occupies just one element in color space, it can't be split
     if ($vBox->count() == 1) {
         return array($vBox->copy());
     }
     // Select the longest axis for splitting
     $redWidth = $vBox->r2 - $vBox->r1 + 1;
     $greenWidth = $vBox->g2 - $vBox->g1 + 1;
     $blueWidth = $vBox->b2 - $vBox->b1 + 1;
     $maxWidth = max($redWidth, $greenWidth, $blueWidth);
     // Determine the cut planes
     switch ($maxWidth) {
         case $redWidth:
             list($total, $partialSum, $favorColor) = self::sumColors(self::favorRed(), $histo, $vBox);
             break;
         case $greenWidth:
             list($total, $partialSum, $favorColor) = self::sumColors(self::favorGreen(), $histo, $vBox);
             break;
         case $blueWidth:
         default:
             list($total, $partialSum, $favorColor) = self::sumColors(self::favorBlue(), $histo, $vBox);
             break;
     }
     return static::doCut($favorColor, $vBox, $partialSum, $total);
 }