src/Distances/Chebyshev.php 1 location
|
@@ 8-17 (lines=10) @@
|
5 |
|
use Letournel\PathFinder\Core\Node; |
6 |
|
use Letournel\PathFinder\Distance; |
7 |
|
|
8 |
|
class Chebyshev implements Distance |
9 |
|
{ |
10 |
|
public function compute(Node $a, Node $b) |
11 |
|
{ |
12 |
|
$dx = abs($a->getX() - $b->getX()); |
13 |
|
$dy = abs($a->getY() - $b->getY()); |
14 |
|
|
15 |
|
return max($dx, $dy); |
16 |
|
} |
17 |
|
} |
18 |
|
|
src/Distances/Euclidean.php 1 location
|
@@ 8-17 (lines=10) @@
|
5 |
|
use Letournel\PathFinder\Core\Node; |
6 |
|
use Letournel\PathFinder\Distance; |
7 |
|
|
8 |
|
class Euclidean implements Distance |
9 |
|
{ |
10 |
|
public function compute(Node $a, Node $b) |
11 |
|
{ |
12 |
|
$dx = abs($a->getX() - $b->getX()); |
13 |
|
$dy = abs($a->getY() - $b->getY()); |
14 |
|
|
15 |
|
return sqrt($dx * $dx + $dy * $dy); |
16 |
|
} |
17 |
|
} |
18 |
|
|
src/Distances/Manhattan.php 1 location
|
@@ 8-17 (lines=10) @@
|
5 |
|
use Letournel\PathFinder\Core\Node; |
6 |
|
use Letournel\PathFinder\Distance; |
7 |
|
|
8 |
|
class Manhattan implements Distance |
9 |
|
{ |
10 |
|
public function compute(Node $a, Node $b) |
11 |
|
{ |
12 |
|
$dx = abs($a->getX() - $b->getX()); |
13 |
|
$dy = abs($a->getY() - $b->getY()); |
14 |
|
|
15 |
|
return $dx + $dy; |
16 |
|
} |
17 |
|
} |
18 |
|
|