Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
12 / 12 |
CRAP | |
100.00% |
1 / 1 |
JumpPointNode | |
100.00% |
12 / 12 |
|
100.00% |
12 / 12 |
12 | |
100.00% |
1 / 1 |
isClosed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isOpened | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isTested | |
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 | |||
setTested | |
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 JumpPointNode 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 | * The node was already tested? |
69 | * |
70 | * @var bool |
71 | * @since 1.0.0 |
72 | */ |
73 | private bool $isTested = false; |
74 | |
75 | /** |
76 | * Is checked? |
77 | * |
78 | * @return bool |
79 | * |
80 | * @since 1.0.0 |
81 | */ |
82 | public function isClosed() : bool |
83 | { |
84 | return $this->isClosed; |
85 | } |
86 | |
87 | /** |
88 | * Is potential candidate |
89 | * |
90 | * @return bool |
91 | * |
92 | * @since 1.0.0 |
93 | */ |
94 | public function isOpened() : bool |
95 | { |
96 | return $this->isOpened; |
97 | } |
98 | |
99 | /** |
100 | * Is already tested |
101 | * |
102 | * @return bool |
103 | * |
104 | * @since 1.0.0 |
105 | */ |
106 | public function isTested() : bool |
107 | { |
108 | return $this->isTested; |
109 | } |
110 | |
111 | /** |
112 | * Set check status |
113 | * |
114 | * @param bool $isClosed Is closed |
115 | * |
116 | * @return void |
117 | * |
118 | * @since 1.0.0 |
119 | */ |
120 | public function setClosed(bool $isClosed) : void |
121 | { |
122 | $this->isClosed = $isClosed; |
123 | } |
124 | |
125 | /** |
126 | * Set potential candidate |
127 | * |
128 | * @param bool $isOpened Is potential candidate |
129 | * |
130 | * @return void |
131 | * |
132 | * @since 1.0.0 |
133 | */ |
134 | public function setOpened(bool $isOpened) : void |
135 | { |
136 | $this->isOpened = $isOpened; |
137 | } |
138 | |
139 | /** |
140 | * Set tested |
141 | * |
142 | * @param bool $isTested Node tested? |
143 | * |
144 | * @return void |
145 | * |
146 | * @since 1.0.0 |
147 | */ |
148 | public function setTested(bool $isTested) : void |
149 | { |
150 | $this->isTested = $isTested; |
151 | } |
152 | |
153 | /** |
154 | * Set the g score |
155 | * |
156 | * @param float $g G score |
157 | * |
158 | * @return void |
159 | * |
160 | * @since 1.0.0 |
161 | */ |
162 | public function setG(float $g) : void |
163 | { |
164 | $this->g = $g; |
165 | } |
166 | |
167 | /** |
168 | * Set the heuristic distance |
169 | * |
170 | * @param float $h H distance |
171 | * |
172 | * @return void |
173 | * |
174 | * @since 1.0.0 |
175 | */ |
176 | public function setH(?float $h) : void |
177 | { |
178 | $this->h = $h; |
179 | } |
180 | |
181 | /** |
182 | * Set the f score |
183 | * |
184 | * @param float $f F score |
185 | * |
186 | * @return void |
187 | * |
188 | * @since 1.0.0 |
189 | */ |
190 | public function setF(float $f) : void |
191 | { |
192 | $this->f = $f; |
193 | } |
194 | |
195 | /** |
196 | * Get the g score |
197 | * |
198 | * @return float |
199 | * |
200 | * @since 1.0.0 |
201 | */ |
202 | public function getG() : float |
203 | { |
204 | return $this->g; |
205 | } |
206 | |
207 | /** |
208 | * Get the heuristic distance |
209 | * |
210 | * @return float |
211 | * |
212 | * @since 1.0.0 |
213 | */ |
214 | public function getH() : ?float |
215 | { |
216 | return $this->h; |
217 | } |
218 | |
219 | /** |
220 | * Get the f score |
221 | * |
222 | * @return float |
223 | * |
224 | * @since 1.0.0 |
225 | */ |
226 | public function getF() : float |
227 | { |
228 | return $this->f; |
229 | } |
230 | } |