From 16f504be67776da269d68150d280b32bc8b45d3b Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 18 Aug 2017 00:44:24 +0000 Subject: [PATCH] Inlined the 'size' variable in getAlignmentPatternPositions() in 3 language versions. --- c/qrcodegen.c | 5 ++--- cpp/QrCode.cpp | 3 +-- java/io/nayuki/qrcodegen/QrCode.java | 3 +-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 081b29a..e162d1b 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -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; diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 5180789..6a2178d 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -514,8 +514,7 @@ vector QrCode::getAlignmentPatternPositions(int ver) { step = 26; vector 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; diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index c20324d..7aae596 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -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; }