diff --git a/c/qrcodegen.c b/c/qrcodegen.c index e662341..30f0bfc 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -465,12 +465,8 @@ testable int getAlignmentPatternPositions(int version, uint8_t result[7]) { if (version == 1) return 0; int numAlign = version / 7 + 2; - int step; - if (version != 32) { - // 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; + int step = (version == 32) ? 26 : + (version*4 + numAlign*2 + 1) / (numAlign*2 - 2) * 2; for (int i = numAlign - 1, pos = version * 4 + 10; i >= 1; i--, pos -= step) result[i] = pos; result[0] = 6; diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 5c3bbc2..09f93c0 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -497,12 +497,8 @@ vector QrCode::getAlignmentPatternPositions(int ver) { return vector(); else { int numAlign = ver / 7 + 2; - int step; - if (ver != 32) { - // ceil((size - 13) / (2*numAlign - 2)) * 2 - step = (ver * 4 + numAlign * 2 + 1) / (2 * numAlign - 2) * 2; - } else // C-C-C-Combo breaker! - step = 26; + int step = (ver == 32) ? 26 : + (ver*4 + numAlign*2 + 1) / (numAlign*2 - 2) * 2; vector result; for (int i = 0, pos = ver * 4 + 10; i < numAlign - 1; i++, pos -= step) diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 6ca2167..985c930 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -653,11 +653,10 @@ public final class QrCode { else { int numAlign = ver / 7 + 2; int step; - if (ver != 32) { - // ceil((size - 13) / (2*numAlign - 2)) * 2 - step = (ver * 4 + numAlign * 2 + 1) / (2 * numAlign - 2) * 2; - } else // C-C-C-Combo breaker! + if (ver == 32) // Special snowflake step = 26; + else // step = ceil[(size - 13) / (numAlign*2 - 2)] * 2 + step = (ver*4 + numAlign*2 + 1) / (numAlign*2 - 2) * 2; int[] result = new int[numAlign]; result[0] = 6; diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index e2d9bdc..f0fa2b5 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -604,11 +604,8 @@ var qrcodegen = new function() { else { var size = ver * 4 + 17; var numAlign = Math.floor(ver / 7) + 2; - var step; - if (ver != 32) - step = Math.ceil((size - 13) / (2 * numAlign - 2)) * 2; - else // C-C-C-Combo breaker! - step = 26; + var step = (ver == 32) ? 26 : + Math.ceil((size - 13) / (numAlign*2 - 2)) * 2; var result = [6]; for (var i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step) diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 3c5bc29..833807e 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -496,11 +496,8 @@ class QrCode(object): return [] else: numalign = ver // 7 + 2 - if ver != 32: - # ceil((size - 13) / (2*numalign - 2)) * 2 - step = (ver * 4 + numalign * 2 + 1) // (2 * numalign - 2) * 2 - else: # C-C-C-Combo breaker! - step = 26 + step = 26 if (ver == 32) else \ + (ver*4 + numalign*2 + 1) // (numalign*2 - 2) * 2 start = ver * 4 + 10 result = [(start - i * step) for i in range(numalign - 1)] + [6] return list(reversed(result)) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index ce68e6f..7d9cdd8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -629,12 +629,8 @@ impl QrCode { vec![] } else { let numalign: i32 = (ver as i32) / 7 + 2; - let step: i32 = if ver != 32 { - // ceil((size - 13) / (2*numAlign - 2)) * 2 - ((ver as i32) * 4 + numalign * 2 + 1) / (2 * numalign - 2) * 2 - } else { // C-C-C-Combo breaker! - 26 - }; + let step: i32 = if ver == 32 { 26 } else + {((ver as i32)*4 + numalign*2 + 1) / (numalign*2 - 2) * 2}; let start = (ver as i32) * 4 + 10; let mut result: Vec = (0 .. numalign - 1).map(|i| start - i * step).collect(); result.push(6); diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index a31605a..1e140bb 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -567,11 +567,8 @@ namespace qrcodegen { else { let size: int = ver * 4 + 17; let numAlign: int = Math.floor(ver / 7) + 2; - let step: int; - if (ver != 32) - step = Math.ceil((size - 13) / (2 * numAlign - 2)) * 2; - else // C-C-C-Combo breaker! - step = 26; + let step: int = (ver == 32) ? 26 : + Math.ceil((size - 13) / (numAlign*2 - 2)) * 2; let result: Array = [6]; for (let i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step)