/**
  * Calculates the cost between 2 nodes
  * @param zibo\library\diagram\path\Node $node1 The first node
  * @param zibo\library\diagram\path\Node $node2 The second node
  * @param integer $orthogonalCost Cost for a non-diagonal move
  * @param integer $diagonalCost Cost for a diagonal move
  * @return integer
  */
 public function calculateCost(Node $node1, Node $node2, $orthogonalCost, $diagonalCost)
 {
     $p1 = $node1->getPoint();
     $x1 = $p1->getX();
     $y1 = $p1->getY();
     $p2 = $node2->getPoint();
     $x2 = $p2->getX();
     $y2 = $p2->getY();
     if ($x1 != $x2 && $y1 != $y2) {
         return $diagonalCost;
     }
     return $orthogonalCost;
 }
 /**
  * Calculates the cost between 2 nodes
  * @param zibo\library\diagram\path\Node $node1 The first node
  * @param zibo\library\diagram\path\Node $node2 The second node
  * @param integer $orthogonalCost Cost for a non-diagonal move
  * @param integer $diagonalCost Cost for a diagonal move
  * @return integer
  */
 public function calculateCost(Node $node1, Node $node2, $orthogonalCost, $diagonalCost)
 {
     $p1 = $node1->getPoint();
     $x1 = $p1->getX();
     $y1 = $p1->getY();
     $p2 = $node2->getPoint();
     $x2 = $p2->getX();
     $y2 = $p2->getY();
     $cost = 0;
     if ($x1 == $x2 && $y1 == $y2) {
         return $cost;
     }
     $diffX = $this->getDifference($x1, $x2);
     $diffY = $this->getDifference($y1, $y2);
     $min = min($diffX, $diffY);
     $max = max($diffX, $diffY);
     $cost += $min * $diagonalCost;
     $cost += ($max - $min) * $orthogonalCost;
     return $cost;
 }
 /**
  * Calculates the cost between 2 nodes
  * @param zibo\library\diagram\path\Node $node1 The first node
  * @param zibo\library\diagram\path\Node $node2 The second node
  * @param integer $orthogonalCost Cost for a non-diagonal move
  * @param integer $diagonalCost Cost for a diagonal move
  * @return integer
  */
 public function calculateCost(Node $node1, Node $node2, $orthogonalCost, $diagonalCost)
 {
     $p1 = $node1->getPoint();
     $x1 = $p1->getX();
     $y1 = $p1->getY();
     $p2 = $node2->getPoint();
     $x2 = $p2->getX();
     $y2 = $p2->getY();
     $cost = 0;
     if ($x1 == $x2 && $y1 == $y2) {
         return $cost;
     }
     $cost += $this->getDifference($x1, $x2);
     $cost += $this->getDifference($y1, $y2);
     $cost *= $orthogonalCost;
     if ($x1 == $x2 || $y1 == $y2) {
         $cost -= round($orthogonalCost / 2);
     }
     return $cost;
 }
Пример #4
0
 /**
  * Adds a node to the closed list and removed it from the opened list
  * @param Node $node Node to add to the closed list
  * @return null
  */
 protected function addNodeToClosed(Node $node)
 {
     $id = $node->getId();
     $this->closed[$id] = $node;
     unset($this->opened[$id]);
 }