ColorThief\ColorThief::doCut PHP 메소드

doCut() 개인적인 정적인 메소드

private static doCut ( string $color, VBox $vBox, array $partialSum, integer $total ) : array
$color string
$vBox VBox
$partialSum array
$total integer
리턴 array
    private static function doCut($color, $vBox, $partialSum, $total)
    {
        $dim1 = $color . '1';
        $dim2 = $color . '2';
        for ($i = $vBox->{$dim1}; $i <= $vBox->{$dim2}; $i++) {
            if ($partialSum[$i] > $total / 2) {
                $vBox1 = $vBox->copy();
                $vBox2 = $vBox->copy();
                $left = $i - $vBox->{$dim1};
                $right = $vBox->{$dim2} - $i;
                // Choose the cut plane within the greater of the (left, right) sides
                // of the bin in which the median pixel resides
                if ($left <= $right) {
                    $d2 = min($vBox->{$dim2} - 1, ~~($i + $right / 2));
                } else {
                    /* left > right */
                    $d2 = max($vBox->{$dim1}, ~~($i - 1 - $left / 2));
                }
                while (empty($partialSum[$d2])) {
                    $d2++;
                }
                // Avoid 0-count boxes
                while ($partialSum[$d2] >= $total && !empty($partialSum[$d2 - 1])) {
                    --$d2;
                }
                // set dimensions
                $vBox1->{$dim2} = $d2;
                $vBox2->{$dim1} = $d2 + 1;
                return array($vBox1, $vBox2);
            }
        }
    }