public function testGetRow() { $matrix = new BitMatrix(102, 5); for ($x = 0; $x < 102; $x++) { if ($x & 3 === 0) { $matrix->set($x, 2); } } $array1 = $matrix->getRow(2, null); $this->assertEquals(102, $array1->getSize()); $array2 = new BitArray(60); $array2 = $matrix->getRow(2, $array2); $this->assertEquals(102, $array2->getSize()); $array3 = new BitArray(200); $array3 = $matrix->getRow(2, $array3); $this->assertEquals(200, $array3->getSize()); for ($x = 0; $x < 102; $x++) { $on = $x & 3 === 0; $this->assertEquals($on, $array1->get($x)); $this->assertEquals($on, $array2->get($x)); $this->assertEquals($on, $array3->get($x)); } }
/** * Builds the function pattern for the current version. * * @return BitMatrix */ public function buildFunctionPattern() { $dimension = $this->getDimensionForVersion(); $bitMatrix = new BitMatrix($dimension); // Top left finder pattern + separator + format $bitMatrix->setRegion(0, 0, 9, 9); // Top right finder pattern + separator + format $bitMatrix->setRegion($dimension - 8, 0, 8, 9); // Bottom left finder pattern + separator + format $bitMatrix->setRegion(0, $dimension - 8, 9, 8); // Alignment patterns $max = count($this->alignmentPatternCenters); for ($x = 0; $x < $max; $x++) { $i = $this->alignmentPatternCenters[$x] - 2; for ($y = 0; $y < $max; $y++) { if ($x === 0 && ($y === 0 || $y === $max - 1) || $x === $max - 1 && $y === 0) { // No alignment patterns near the three finder paterns continue; } $bitMatrix->setRegion($this->alignmentPatternCenters[$y] - 2, $i, 5, 5); } } // Vertical timing pattern $bitMatrix->setRegion(6, 9, 1, $dimension - 17); // Horizontal timing pattern $bitMatrix->setRegion(9, 6, $dimension - 17, 1); if ($this->versionNumber > 6) { // Version info, top right $bitMatrix->setRegion($dimension - 11, 0, 3, 6); // Version info, bottom left $bitMatrix->setRegion(0, $dimension - 11, 6, 3); } return $bitMatrix; }