diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 44c041a..76876cf 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -619,8 +619,7 @@ static long getPenaltyScore(const uint8_t qrcode[]) { black++; } } - // Note that size is odd, so black/total != 1/2 - int total = qrsize * qrsize; + int total = qrsize * qrsize; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% int k = (int)((labs(black * 20L - total * 10L) + total - 1) / total) - 1; result += k * PENALTY_N4; diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 61d583b..bb8e979 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -485,8 +485,7 @@ long QrCode::getPenaltyScore() const { black++; } } - // Note that size is odd, so black/total != 1/2 - int total = size * size; + int total = size * size; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% int k = static_cast((std::abs(black * 20L - total * 10L) + total - 1) / total) - 1; result += k * PENALTY_N4; diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 80a4ee9..f558770 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -632,8 +632,7 @@ public final class QrCode { black++; } } - // Note that size is odd, so black/total != 1/2 - int total = size * size; + int total = size * size; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% int k = (Math.abs(black * 20 - total * 10) + total - 1) / total - 1; result += k * PENALTY_N4; diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 0288aaa..27cbc0c 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -480,8 +480,7 @@ var qrcodegen = new function() { black++; }); }); - // Note that size is odd, so black/total != 1/2 - var total = size * size; + var total = size * size; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% var k = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1; result += k * QrCode.PENALTY_N4; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 22c2252..130f832 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -476,8 +476,7 @@ class QrCode(object): # Balance of black and white modules black = sum((1 if cell else 0) for row in modules for cell in row) - # Note that size is odd, so black/total != 1/2 - total = size**2 + total = size**2 # Note that size is odd, so black/total != 1/2 # Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% k = (abs(black * 20 - total * 10) + total - 1) // total - 1 result += k * QrCode._PENALTY_N4 diff --git a/rust/src/lib.rs b/rust/src/lib.rs index ee24836..486896f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -609,8 +609,7 @@ impl QrCode { for color in &self.modules { black += *color as i32; } - // Note that size is odd, so black/total != 1/2 - let total: i32 = size * size; + let total: i32 = size * size; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% let k: i32 = ((black * 20 - total * 10).abs() + total - 1) / total - 1; result += k * PENALTY_N4; diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index d67ccd5..2d59569 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -548,8 +548,7 @@ namespace qrcodegen { black++; }); }); - // Note that size is odd, so black/total != 1/2 - let total: int = this.size * this.size; + let total: int = this.size * this.size; // Note that size is odd, so black/total != 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% let k: int = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1; result += k * QrCode.PENALTY_N4;