Skip to content

Commit a2da564

Browse files
committed
:octocat:
1 parent fd4d208 commit a2da564

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

src/Data/QRMatrix.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,15 @@ public function initFunctionalPatterns():self{
151151
* @return int[][]|bool[][]
152152
*/
153153
public function getMatrix(bool $boolean = null):array{
154-
155-
if(!$boolean){
156-
return $this->matrix;
157-
}
158-
159154
$matrix = [];
160155

161156
foreach($this->matrix as $y => $row){
162157
$matrix[$y] = [];
163158

164159
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);
166163
}
167164
}
168165

@@ -303,12 +300,13 @@ public function flip(int $x, int $y):self{
303300
* true => $value & $M_TYPE === $M_TYPE
304301
*/
305302
public function checkType(int $x, int $y, int $M_TYPE):bool{
303+
$val = $this->get($x, $y);
306304

307-
if(!isset($this->matrix[$y][$x])){
305+
if($val === -1){
308306
return false;
309307
}
310308

311-
return ($this->matrix[$y][$x] & $M_TYPE) === $M_TYPE;
309+
return ($val & $M_TYPE) === $M_TYPE;
312310
}
313311

314312
/**
@@ -343,21 +341,21 @@ public function check(int $x, int $y):bool{
343341
* 8 # 4
344342
* 7 6 5
345343
*/
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{
347345
$bits = 0;
348346

349347
foreach($this::neighbours as $bit => $coord){
350348
[$ix, $iy] = $coord;
351349

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)){
357355
continue;
358356
}
359357

360-
if($this->checkType(($x + $ix), ($y + $iy), $this::IS_DARK)){
358+
if($this->checkType($ix, $iy, $this::IS_DARK)){
361359
$bits |= $bit;
362360
}
363361
}

tests/Data/QRMatrixTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testInstance():void{
118118
* Tests if size() returns the actual matrix size/count
119119
*/
120120
public function testSize():void{
121-
$this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix());
121+
$this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true));
122122
}
123123

124124
/**
@@ -341,8 +341,8 @@ public function testSetQuietZone(QRMatrix $matrix):void{
341341

342342
$s = ($size + 2 * $quietZoneSize);
343343

344-
$this::assertCount($s, $matrix->getMatrix());
345-
$this::assertCount($s, $matrix->getMatrix()[($size - 1)]);
344+
$this::assertCount($s, $matrix->getMatrix(true));
345+
$this::assertCount($s, $matrix->getMatrix(true)[($size - 1)]);
346346

347347
$size = $matrix->getSize();
348348

0 commit comments

Comments
 (0)