/**
  * Gets the surrounding nodes of the provided Node.
  * @param Node $node
  * @return array Surrounding nodeswhich are free in the grid and not on the closed list
  */
 protected function getSurroundingNodes(Node $node)
 {
     $thresholdCost = 3 * $this->orthogonalCost;
     $movementCost = $node->getMovementCost();
     $estimatedMovementCost = $node->getEstimatedMovementCost();
     if ($movementCost < $thresholdCost || $estimatedMovementCost < $thresholdCost) {
         $threshold = 0;
     } elseif ($movementCost < $thresholdCost * 5 || $estimatedMovementCost < $thresholdCost * 5) {
         $threshold = 1;
     } else {
         $threshold = 2;
     }
     $x = $node->getPoint()->getX();
     $y = $node->getPoint()->getY();
     $minX = min(max($this->gridMinX, $x - 1), $this->gridMaxX);
     $maxX = min(max($this->gridMinX, $x + 1), $this->gridMaxX);
     $minY = min(max($this->gridMinY, $y - 1), $this->gridMaxY);
     $maxY = min(max($this->gridMinY, $y + 1), $this->gridMaxY);
     $surroundingNodes = array();
     for ($i = $minX; $i <= $maxX; $i++) {
         for ($j = $minY; $j <= $maxY; $j++) {
             if ($i == $x && $j == $y) {
                 continue;
             }
             $point = new Point($i, $j);
             $node = new Node($point);
             $id = $node->getId();
             if (array_key_exists($id, $this->closed)) {
                 continue;
             }
             if (!$this->grid->isFree($point, $threshold)) {
                 continue;
             }
             $surroundingNodes[$id] = $node;
         }
     }
     return $surroundingNodes;
 }