Axis::find_division PHP Method

find_division() private method

Determine the axis divisions
private find_division ( $length, $min, &$count, &$neg_count, &$magnitude )
    private function find_division($length, $min, &$count, &$neg_count, &$magnitude)
    {
        if ($length / $count >= $min) {
            return;
        }
        $c = $count - 1;
        $inc = 0;
        while ($c > 1) {
            $m = ($count + $inc) / $c;
            $l = $length / $c;
            $test_below = $neg_count ? $c * $neg_count / $count : 1;
            if ($this->nice($m, $count + $inc)) {
                if ($l >= $min && $test_below - floor($test_below) == 0) {
                    $magnitude *= ($count + $inc) / $c;
                    $neg_count *= $c / $count;
                    $count = $c;
                    return;
                }
                --$c;
                $inc = 0;
            } elseif (!$this->fit && $count % 2 == 1 && $inc == 0) {
                $inc = 1;
            } else {
                --$c;
                $inc = 0;
            }
        }
        // try to balance the +ve and -ve a bit
        if ($neg_count) {
            $c = $count + 1;
            $p_count = $count - $neg_count;
            if ($p_count > $neg_count && ($neg_count == 1 || $c % $neg_count)) {
                ++$neg_count;
            }
            ++$count;
        }
    }