コード例 #1
0
ファイル: MyAStarTest.php プロジェクト: AlexKex/php-a-star
 /**
  * @param MyNode $needle
  * @param MyNode[] $haystack
  */
 private function assertContainsMyNode(MyNode $needle, array $haystack)
 {
     foreach ($haystack as $node) {
         if ($needle->getID() === $node->getID()) {
             return;
         }
     }
     $this->fail('Failed asserting that the array ' . print_r($haystack, true) . 'contains the specified node ' . print_r($needle, true));
 }
コード例 #2
0
ファイル: MyNodeTest.php プロジェクト: AlexKex/php-a-star
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Invalid node
  */
 public function testShouldNotCreateNewInstanceFromInvalidNode()
 {
     $nodeID = 'foo';
     $node = $this->getMock('JMGQ\\AStar\\Node');
     $node->expects($this->once())->method('getID')->will($this->returnValue($nodeID));
     MyNode::fromNode($node);
 }
コード例 #3
0
ファイル: MyAStar.php プロジェクト: AlexKex/php-a-star
 /**
  * @inheritdoc
  */
 public function calculateEstimatedCost(Node $start, Node $end)
 {
     $myStartNode = MyNode::fromNode($start);
     $myEndNode = MyNode::fromNode($end);
     $xFactor = pow($myStartNode->getX() - $myEndNode->getX(), 2);
     $yFactor = pow($myStartNode->getY() - $myEndNode->getY(), 2);
     $euclideanDistance = sqrt($xFactor + $yFactor);
     return $euclideanDistance;
 }