@@ -151,18 +151,15 @@ public function initFunctionalPatterns():self{
151
151
* @return int[][]|bool[][]
152
152
*/
153
153
public function getMatrix (bool $ boolean = null ):array {
154
-
155
- if (!$ boolean ){
156
- return $ this ->matrix ;
157
- }
158
-
159
154
$ matrix = [];
160
155
161
156
foreach ($ this ->matrix as $ y => $ row ){
162
157
$ matrix [$ y ] = [];
163
158
164
159
foreach ($ row as $ x => $ val ){
165
- $ matrix [$ y ][$ x ] = ($ val & $ this ::IS_DARK ) === $ this ::IS_DARK ;
160
+ $ matrix [$ y ][$ x ] = $ boolean === true
161
+ ? $ this ->checkType ($ x , $ y , $ this ::IS_DARK )
162
+ : $ this ->get ($ x , $ y );
166
163
}
167
164
}
168
165
@@ -303,12 +300,13 @@ public function flip(int $x, int $y):self{
303
300
* true => $value & $M_TYPE === $M_TYPE
304
301
*/
305
302
public function checkType (int $ x , int $ y , int $ M_TYPE ):bool {
303
+ $ val = $ this ->get ($ x , $ y );
306
304
307
- if (! isset ( $ this -> matrix [ $ y ][ $ x ]) ){
305
+ if ($ val === - 1 ){
308
306
return false ;
309
307
}
310
308
311
- return ($ this -> matrix [ $ y ][ $ x ] & $ M_TYPE ) === $ M_TYPE ;
309
+ return ($ val & $ M_TYPE ) === $ M_TYPE ;
312
310
}
313
311
314
312
/**
@@ -343,21 +341,21 @@ public function check(int $x, int $y):bool{
343
341
* 8 # 4
344
342
* 7 6 5
345
343
*/
346
- public function checkNeighbours (int $ x , int $ y , int $ M_TYPE_VALUE = null ):int {
344
+ public function checkNeighbours (int $ x , int $ y , int $ M_TYPE = null ):int {
347
345
$ bits = 0 ;
348
346
349
347
foreach ($ this ::neighbours as $ bit => $ coord ){
350
348
[$ ix , $ iy ] = $ coord ;
351
349
352
- // check if the field is the same type
353
- if (
354
- $ M_TYPE_VALUE !== null
355
- && ( $ this -> get (( $ x + $ ix ), ( $ y + $ iy )) | $ this :: IS_DARK ) !== ( $ M_TYPE_VALUE | $ this :: IS_DARK )
356
- ){
350
+ $ ix += $ x ;
351
+ $ iy += $ y ;
352
+
353
+ // $M_TYPE is given, skip if the field is not the same type
354
+ if ( $ M_TYPE !== null && ! $ this -> checkType ( $ ix , $ iy , $ M_TYPE ) ){
357
355
continue ;
358
356
}
359
357
360
- if ($ this ->checkType (( $ x + $ ix ), ( $ y + $ iy ) , $ this ::IS_DARK )){
358
+ if ($ this ->checkType ($ ix , $ iy , $ this ::IS_DARK )){
361
359
$ bits |= $ bit ;
362
360
}
363
361
}
0 commit comments