static private function simplifyInternal( &$points, $epsilon, $start, $end )
{
$firstPoint = $points[$start];
$lastPoint = $points[$end];
$index = -1;
$dist = 0;
if ( $end - $start < 2 ) {
return;
}
for ( $i = $start + 1; $i < $end; $i++ ) {
if ( !isset( $points[$i] ) ) {
continue;
}
$cDist = self::findPerpendicularDistance( $points[ $i ], $firstPoint, $lastPoint );
if ( $cDist > $dist ) {
$dist = $cDist;
$index = $i;
}
}
if ( $dist > $epsilon ) {
self::simplifyInternal( $points, $epsilon, $start, $index );
self::simplifyInternal( $points, $epsilon, $index, $end );
return;
} else {
for ( $i = $start + 1; $i < $end; $i++ ) {
unset( $points[$i] );
}
return;
}
}