static function line($pointList, $epsilon) { // Find the point with the maximum distance $dmax = 0; $index = 0; $totalPoints = count($pointList); for ($i = 1; $i < $totalPoints - 1; $i++) { $d = Simplify::perpendicularDistance($pointList[$i]['x'], $pointList[$i]['y'], $pointList[0]['x'], $pointList[0]['y'], $pointList[$totalPoints - 1]['x'], $pointList[$totalPoints - 1]['y']); if ($d > $dmax) { $index = $i; $dmax = $d; } } $resultList = array(); // If max distance is greater than epsilon, recursively simplify if ($dmax >= $epsilon) { // Recursive call $recResults1 = Simplify::line(array_slice($pointList, 0, $index + 1), $epsilon); $recResults2 = Simplify::line(array_slice($pointList, $index, $totalPoints - $index), $epsilon); // Build the result list $resultList = array_merge(array_slice($recResults1, 0, count($recResults1) - 1), array_slice($recResults2, 0, count($recResults2))); } else { $resultList = array($pointList[0], $pointList[$totalPoints - 1]); } // Return the result return $resultList; }