Simplified code in QrCode.drawFunctionPatterns() in all language versions, but differently in Python.

This commit is contained in:
Project Nayuki 2018-08-26 01:49:27 +00:00
parent 0ee6c41c9c
commit c9553ead71
7 changed files with 14 additions and 20 deletions

View File

@ -341,9 +341,8 @@ testable void initializeFunctionModules(int version, uint8_t qrcode[]) {
int numAlign = getAlignmentPatternPositions(version, alignPatPos); int numAlign = getAlignmentPatternPositions(version, alignPatPos);
for (int i = 0; i < numAlign; i++) { for (int i = 0; i < numAlign; i++) {
for (int j = 0; j < numAlign; j++) { for (int j = 0; j < numAlign; j++) {
if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)) // Don't draw on the three finder corners
continue; // Skip the three finder corners if (!((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)))
else
fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode); fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode);
} }
} }

View File

@ -203,9 +203,8 @@ void QrCode::drawFunctionPatterns() {
int numAlign = alignPatPos.size(); int numAlign = alignPatPos.size();
for (int i = 0; i < numAlign; i++) { for (int i = 0; i < numAlign; i++) {
for (int j = 0; j < numAlign; j++) { for (int j = 0; j < numAlign; j++) {
if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)) // Don't draw on the three finder corners
continue; // Skip the three finder corners if (!((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)))
else
drawAlignmentPattern(alignPatPos.at(i), alignPatPos.at(j)); drawAlignmentPattern(alignPatPos.at(i), alignPatPos.at(j));
} }
} }

View File

@ -335,9 +335,8 @@ public final class QrCode {
int numAlign = alignPatPos.length; int numAlign = alignPatPos.length;
for (int i = 0; i < numAlign; i++) { for (int i = 0; i < numAlign; i++) {
for (int j = 0; j < numAlign; j++) { for (int j = 0; j < numAlign; j++) {
if (i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0) // Don't draw on the three finder corners
continue; // Skip the three finder corners if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
else
drawAlignmentPattern(alignPatPos[i], alignPatPos[j]); drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
} }
} }

View File

@ -206,9 +206,8 @@ var qrcodegen = new function() {
var numAlign = alignPatPos.length; var numAlign = alignPatPos.length;
for (var i = 0; i < numAlign; i++) { for (var i = 0; i < numAlign; i++) {
for (var j = 0; j < numAlign; j++) { for (var j = 0; j < numAlign; j++) {
if (i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0) // Don't draw on the three finder corners
continue; // Skip the three finder corners if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
else
drawAlignmentPattern(alignPatPos[i], alignPatPos[j]); drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
} }
} }

View File

@ -255,10 +255,10 @@ class QrCode(object):
# Draw numerous alignment patterns # Draw numerous alignment patterns
alignpatpos = QrCode._get_alignment_pattern_positions(self._version) alignpatpos = QrCode._get_alignment_pattern_positions(self._version)
numalign = len(alignpatpos) numalign = len(alignpatpos)
skips = ((0, 0), (0, numalign - 1), (numalign - 1, 0)) # Skip the three finder corners skips = ((0, 0), (0, numalign - 1), (numalign - 1, 0))
for i in range(numalign): for i in range(numalign):
for j in range(numalign): for j in range(numalign):
if (i, j) not in skips: if (i, j) not in skips: # Don't draw on the three finder corners
self._draw_alignment_pattern(alignpatpos[i], alignpatpos[j]) self._draw_alignment_pattern(alignpatpos[i], alignpatpos[j])
# Draw configuration data # Draw configuration data

View File

@ -288,9 +288,8 @@ impl QrCode {
let numalign: usize = alignpatpos.len(); let numalign: usize = alignpatpos.len();
for i in 0 .. numalign { for i in 0 .. numalign {
for j in 0 .. numalign { for j in 0 .. numalign {
if i == 0 && j == 0 || i == 0 && j == numalign - 1 || i == numalign - 1 && j == 0 { // Don't draw on the three finder corners
continue; // Skip the three finder corners if !(i == 0 && j == 0 || i == 0 && j == numalign - 1 || i == numalign - 1 && j == 0) {
} else {
self.draw_alignment_pattern(alignpatpos[i], alignpatpos[j]); self.draw_alignment_pattern(alignpatpos[i], alignpatpos[j]);
} }
} }

View File

@ -269,9 +269,8 @@ namespace qrcodegen {
let numAlign: int = alignPatPos.length; let numAlign: int = alignPatPos.length;
for (let i = 0; i < numAlign; i++) { for (let i = 0; i < numAlign; i++) {
for (let j = 0; j < numAlign; j++) { for (let j = 0; j < numAlign; j++) {
if (i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0) // Don't draw on the three finder corners
continue; // Skip the three finder corners if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
else
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]); this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
} }
} }