private function _reduce( $points, $tolerance )
    {
        $distanceMax = $index = 0;
        // Can't user $this->lastkey, as this is a reclusive method.
        $pointsEnd = key(array_slice($points, -1, 1, true));
        for ( $i = 1; $i < $pointsEnd; $i++ ) {
            $distance = $this->shortestDistanceToSegment(
                $points[$i],
                $points[0],
                $points[$pointsEnd]
            );
            if ( $distance > $distanceMax ) {
                $index = $i;
                $distanceMax = $distance;
            }
        }

        if ( $distanceMax > $tolerance ) {
            $firstHalf = $this->_reduce(
                array_slice($points, 0, $index+1),
                $tolerance
            );
            $secondHalf = $this->_reduce(
                array_slice($points, $index),
                $tolerance
            );
            array_shift($secondHalf);
            $points = array_merge($firstHalf, $secondHalf);
        } else {
            $points = array($points[0], $points[$pointsEnd]);
        }
        return $points;
    }
private function _reduce( $points, $tolerance )
    {
        $distanceMax = $index = 0;
        // Can't user $this->lastkey, as this is a reclusive method.
        $pointsEnd = key(array_slice($points, -1, 1, true));
        for ( $i = 1; $i < $pointsEnd; $i++ ) {
            $distance = $this->shortestDistanceToSegment(
                $points[$i],
                $points[0],
                $points[$pointsEnd]
            );
            if ( $distance > $distanceMax ) {
                $index = $i;
                $distanceMax = $distance;
            }
        }

        if ( $distanceMax > $tolerance ) {
            $firstHalf = $this->_reduce(
                array_slice($points, 0, $index+1),
                $tolerance
            );
            $secondHalf = $this->_reduce(
                array_slice($points, $index),
                $tolerance
            );
            array_shift($secondHalf);
            $points = array_merge($firstHalf, $secondHalf);
        } else {
            $points = array($points[0], $points[$pointsEnd]);
        }
        return $points;
    }
private function _reduce ( $ points , $ tolerance ) { $ distanceMax = $ index = 0 ; // Can't user $this->lastkey, as this is a reclusive method. $ pointsEnd = key ( array_slice ( $ points , - 1 , 1 , true ) ) ; for ( $ i = 1 ; $ i < $ pointsEnd ; $ i ++ ) { $ distance = $ this -> shortestDistanceToSegment ( $ points [ $ i ] , $ points [ 0 ] , $ points [ $ pointsEnd ] ) ; if ( $ distance > $ distanceMax ) { $ index = $ i ; $ distanceMax = $ distance ; } } if ( $ distanceMax > $ tolerance ) { $ firstHalf = $ this -> _reduce ( array_slice ( $ points , 0 , $ index + 1 ) , $ tolerance ) ; $ secondHalf = $ this -> _reduce ( array_slice ( $ points , $ index ) , $ tolerance ) ; array_shift ( $ secondHalf ) ; $ points = array_merge ( $ firstHalf , $ secondHalf ) ; } else { $ points = array ( $ points [ 0 ] , $ points [ $ pointsEnd ] ) ; } return $ points ; }
Reduce points with Ramer-Douglas-Peucker algorithm.

@param array $points    Finite set of points
@param mixed $tolerance Defined threshold to reduce by

@return array            Reduced set of points
Reduce points with Ramer - Douglas - Peucker algorithm .