Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
| AStarNode | |
100.00% |
10 / 10 |
|
100.00% |
10 / 10 |
10 | |
100.00% |
1 / 1 |
| isClosed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isOpened | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setClosed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setOpened | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setG | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setH | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setF | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getG | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getH | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getF | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Algorithm\PathFinding |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Algorithm\PathFinding; |
| 16 | |
| 17 | /** |
| 18 | * Node on grid. |
| 19 | * |
| 20 | * @package phpOMS\Algorithm\PathFinding |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | class AStarNode extends Node |
| 26 | { |
| 27 | /** |
| 28 | * The g score is cost of the path |
| 29 | * |
| 30 | * @var float |
| 31 | * @since 1.0.0 |
| 32 | */ |
| 33 | private float $g = 0.0; |
| 34 | |
| 35 | /** |
| 36 | * The heuristic distance is the cost to the end node |
| 37 | * |
| 38 | * @var float |
| 39 | * @since 1.0.0 |
| 40 | */ |
| 41 | private ?float $h = null; |
| 42 | |
| 43 | /** |
| 44 | * The f score is defined as f(n) = g(n) + h(n) |
| 45 | * |
| 46 | * @var float |
| 47 | * @since 1.0.0 |
| 48 | */ |
| 49 | private float $f = 0.0; |
| 50 | |
| 51 | /** |
| 52 | * Define as checked node |
| 53 | * |
| 54 | * @var bool |
| 55 | * @since 1.0.0 |
| 56 | */ |
| 57 | private bool $isClosed = false; |
| 58 | |
| 59 | /** |
| 60 | * Define as potential candidate |
| 61 | * |
| 62 | * @var bool |
| 63 | * @since 1.0.0 |
| 64 | */ |
| 65 | private bool $isOpened = false; |
| 66 | |
| 67 | /** |
| 68 | * Is checked? |
| 69 | * |
| 70 | * @return bool |
| 71 | * |
| 72 | * @since 1.0.0 |
| 73 | */ |
| 74 | public function isClosed() : bool |
| 75 | { |
| 76 | return $this->isClosed; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Is potential candidate |
| 81 | * |
| 82 | * @return bool |
| 83 | * |
| 84 | * @since 1.0.0 |
| 85 | */ |
| 86 | public function isOpened() : bool |
| 87 | { |
| 88 | return $this->isOpened; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Set check status |
| 93 | * |
| 94 | * @param bool $isClosed Is closed |
| 95 | * |
| 96 | * @return void |
| 97 | * |
| 98 | * @since 1.0.0 |
| 99 | */ |
| 100 | public function setClosed(bool $isClosed) : void |
| 101 | { |
| 102 | $this->isClosed = $isClosed; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Set potential candidate |
| 107 | * |
| 108 | * @param bool $isOpened Is potential candidate |
| 109 | * |
| 110 | * @return void |
| 111 | * |
| 112 | * @since 1.0.0 |
| 113 | */ |
| 114 | public function setOpened(bool $isOpened) : void |
| 115 | { |
| 116 | $this->isOpened = $isOpened; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Set the g score |
| 121 | * |
| 122 | * @param float $g G score |
| 123 | * |
| 124 | * @return void |
| 125 | * |
| 126 | * @since 1.0.0 |
| 127 | */ |
| 128 | public function setG(float $g) : void |
| 129 | { |
| 130 | $this->g = $g; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Set the heuristic distance |
| 135 | * |
| 136 | * @param float $h H distance |
| 137 | * |
| 138 | * @return void |
| 139 | * |
| 140 | * @since 1.0.0 |
| 141 | */ |
| 142 | public function setH(?float $h) : void |
| 143 | { |
| 144 | $this->h = $h; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Set the f score |
| 149 | * |
| 150 | * @param float $f F score |
| 151 | * |
| 152 | * @return void |
| 153 | * |
| 154 | * @since 1.0.0 |
| 155 | */ |
| 156 | public function setF(float $f) : void |
| 157 | { |
| 158 | $this->f = $f; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Get the g score |
| 163 | * |
| 164 | * @return float |
| 165 | * |
| 166 | * @since 1.0.0 |
| 167 | */ |
| 168 | public function getG() : float |
| 169 | { |
| 170 | return $this->g; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Get the heuristic distance |
| 175 | * |
| 176 | * @return float |
| 177 | * |
| 178 | * @since 1.0.0 |
| 179 | */ |
| 180 | public function getH() : ?float |
| 181 | { |
| 182 | return $this->h; |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Get the f score |
| 187 | * |
| 188 | * @return float |
| 189 | * |
| 190 | * @since 1.0.0 |
| 191 | */ |
| 192 | public function getF() : float |
| 193 | { |
| 194 | return $this->f; |
| 195 | } |
| 196 | } |