diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index 16b895570..c32675cc8 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -151,18 +151,15 @@ class QRMatrix{ * @return int[][]|bool[][] */ public function getMatrix(bool $boolean = null):array{ - - if(!$boolean){ - return $this->matrix; - } - $matrix = []; foreach($this->matrix as $y => $row){ $matrix[$y] = []; foreach($row as $x => $val){ - $matrix[$y][$x] = ($val & $this::IS_DARK) === $this::IS_DARK; + $matrix[$y][$x] = $boolean === true + ? $this->checkType($x, $y, $this::IS_DARK) + : $this->get($x, $y); } } @@ -303,12 +300,13 @@ class QRMatrix{ * true => $value & $M_TYPE === $M_TYPE */ public function checkType(int $x, int $y, int $M_TYPE):bool{ + $val = $this->get($x, $y); - if(!isset($this->matrix[$y][$x])){ + if($val === -1){ return false; } - return ($this->matrix[$y][$x] & $M_TYPE) === $M_TYPE; + return ($val & $M_TYPE) === $M_TYPE; } /** @@ -343,21 +341,21 @@ class QRMatrix{ * 8 # 4 * 7 6 5 */ - public function checkNeighbours(int $x, int $y, int $M_TYPE_VALUE = null):int{ + public function checkNeighbours(int $x, int $y, int $M_TYPE = null):int{ $bits = 0; foreach($this::neighbours as $bit => $coord){ [$ix, $iy] = $coord; - // check if the field is the same type - if( - $M_TYPE_VALUE !== null - && ($this->get(($x + $ix), ($y + $iy)) | $this::IS_DARK) !== ($M_TYPE_VALUE | $this::IS_DARK) - ){ + $ix += $x; + $iy += $y; + + // $M_TYPE is given, skip if the field is not the same type + if($M_TYPE !== null && !$this->checkType($ix, $iy, $M_TYPE)){ continue; } - if($this->checkType(($x + $ix), ($y + $iy), $this::IS_DARK)){ + if($this->checkType($ix, $iy, $this::IS_DARK)){ $bits |= $bit; } } diff --git a/tests/Data/QRMatrixTest.php b/tests/Data/QRMatrixTest.php index 9cabb0c16..8c921ee26 100755 --- a/tests/Data/QRMatrixTest.php +++ b/tests/Data/QRMatrixTest.php @@ -118,7 +118,7 @@ final class QRMatrixTest extends TestCase{ * Tests if size() returns the actual matrix size/count */ public function testSize():void{ - $this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix()); + $this::assertCount($this->matrix->getSize(), $this->matrix->getMatrix(true)); } /** @@ -341,8 +341,8 @@ final class QRMatrixTest extends TestCase{ $s = ($size + 2 * $quietZoneSize); - $this::assertCount($s, $matrix->getMatrix()); - $this::assertCount($s, $matrix->getMatrix()[($size - 1)]); + $this::assertCount($s, $matrix->getMatrix(true)); + $this::assertCount($s, $matrix->getMatrix(true)[($size - 1)]); $size = $matrix->getSize();