From 1d5e77d4fc40062c30b60398272f7e2bd60ca154 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Tue, 14 Jun 2016 17:28:32 +0000 Subject: [PATCH] Simplified some code in QrCode.getAlignmentPatternPositions() in most language versions. --- cpp/QrCode.cpp | 8 ++++---- javascript/qrcodegen.js | 8 +++----- python/qrcodegen.py | 6 +++--- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 51e6dad..cab7433 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -506,11 +506,11 @@ std::vector qrcodegen::QrCode::getAlignmentPatternPositions(int ver) { else // C-C-C-Combo breaker! step = 26; - std::vector result(numAlign); + std::vector 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; } } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index e1dda5c..298349e 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -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; } }; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 7113cf6..b0d618a 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -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