Inlined the 'size' variable in getAlignmentPatternPositions() in 3 language versions.

pull/16/head
Project Nayuki 7 years ago
parent 49f6538682
commit 16f504be67

@ -627,15 +627,14 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin
testable int getAlignmentPatternPositions(int version, uint8_t result[7]) {
if (version == 1)
return 0;
int qrsize = version * 4 + 17;
int numAlign = version / 7 + 2;
int step;
if (version != 32) {
// ceil((qrsize - 13) / (2*numAlign - 2)) * 2
// ceil((size - 13) / (2*numAlign - 2)) * 2
step = (version * 4 + numAlign * 2 + 1) / (2 * numAlign - 2) * 2;
} else // C-C-C-Combo breaker!
step = 26;
for (int i = numAlign - 1, pos = qrsize - 7; i >= 1; i--, pos -= step)
for (int i = numAlign - 1, pos = version * 4 + 10; i >= 1; i--, pos -= step)
result[i] = pos;
result[0] = 6;
return numAlign;

@ -514,8 +514,7 @@ vector<int> QrCode::getAlignmentPatternPositions(int ver) {
step = 26;
vector<int> result;
int size = ver * 4 + 17;
for (int i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step)
for (int i = 0, pos = ver * 4 + 10; i < numAlign - 1; i++, pos -= step)
result.insert(result.begin(), pos);
result.insert(result.begin(), 6);
return result;

@ -675,9 +675,8 @@ public final class QrCode {
step = 26;
int[] result = new int[numAlign];
int size = ver * 4 + 17;
result[0] = 6;
for (int i = result.length - 1, pos = size - 7; i >= 1; i--, pos -= step)
for (int i = result.length - 1, pos = ver * 4 + 10; i >= 1; i--, pos -= step)
result[i] = pos;
return result;
}

Loading…
Cancel
Save