Simplified some code in QrCode.getAlignmentPatternPositions() in most language versions.

This commit is contained in:
Project Nayuki 2016-06-14 17:28:32 +00:00
parent ff9fbba9cf
commit 1d5e77d4fc
3 changed files with 10 additions and 12 deletions

View File

@ -506,11 +506,11 @@ std::vector<int> qrcodegen::QrCode::getAlignmentPatternPositions(int ver) {
else // C-C-C-Combo breaker!
step = 26;
std::vector<int> result(numAlign);
std::vector<int> result;
int size = ver * 4 + 17;
result.at(0) = 6;
for (int i = numAlign - 1, pos = size - 7; i >= 1; i--, pos -= step)
result.at(i) = pos;
for (int i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step)
result.insert(result.begin(), pos);
result.insert(result.begin(), 6);
return result;
}
}

View File

@ -639,11 +639,9 @@ var qrcodegen = new function() {
else // C-C-C-Combo breaker!
step = 26;
var result = [];
for (var i = numAlign - 1, pos = size - 7; i >= 1; i--, pos -= step)
result.push(pos);
result.push(6);
result.reverse();
var result = [6];
for (var i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step)
result.splice(1, 0, pos);
return result;
}
};

View File

@ -519,10 +519,10 @@ class QrCode(object):
step = (ver * 4 + numalign * 2 + 1) // (2 * numalign - 2) * 2 # ceil((size - 13) / (2*numalign - 2)) * 2
else: # C-C-C-Combo breaker!
step = 26
result = [6] + [None] * (numalign - 1)
result = [6]
pos = ver * 4 + 10
for i in reversed(range(1, numalign)):
result[i] = pos
for i in range(numalign - 1):
result.insert(1, pos)
pos -= step
return result