Example #1
0
 private static function removeMinimalTrrianglePoint(&$points, &$minimalAreaKey, &$listOfAreas)
 {
     //Recalculate new left triangle
     if ($minimalAreaKey > 1) {
         $leftPointKey = $minimalAreaKey - 1;
         $listOfAreas[$leftPointKey] = PointsService::getAreaTriangle($points[$leftPointKey - 1], $points[$leftPointKey], $points[$leftPointKey + 1]);
     }
     //Recalculate new right triangle
     if ($minimalAreaKey < count($minimalAreaKey) - 2) {
         $rightPointKey = $minimalAreaKey - 1;
         $listOfAreas[$rightPointKey] = PointsService::getAreaTriangle($points[$rightPointKey - 1], $points[$rightPointKey], $points[$rightPointKey + 1]);
     }
     //Remove old point and their area of trangle
     unset($points[$minimalAreaKey]);
     unset($listOfAreas[$minimalAreaKey]);
     //flush keys
     // TODO: need replace it to more faster logic
     $points = array_values($points);
     $listOfAreas = array_values($listOfAreas);
     //        print_r($listOfAreas);
     $minimalArea = $listOfAreas[1];
     $minimalAreaKey = 1;
     for ($i = 2, $size = count($listOfAreas); $i < $size; $i++) {
         if ($minimalArea > $listOfAreas[$i]) {
             $minimalArea = $listOfAreas[$i];
             $minimalAreaKey = $i;
         }
     }
 }