Reordered calls to applyMask()/drawFormatBits() for conceptual clarity, without changing output (because masks don't affect format bits), in all language versions.

This commit is contained in:
Project Nayuki 2018-11-04 19:26:33 +00:00
parent 22319bf90f
commit fd083f70e8
7 changed files with 14 additions and 14 deletions

View File

@ -264,8 +264,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
long minPenalty = LONG_MAX;
for (int i = 0; i < 8; i++) {
enum qrcodegen_Mask msk = (enum qrcodegen_Mask)i;
drawFormatBits(ecl, msk, qrcode);
applyMask(tempBuffer, qrcode, msk);
drawFormatBits(ecl, msk, qrcode);
long penalty = getPenaltyScore(qrcode);
if (penalty < minPenalty) {
mask = msk;
@ -275,8 +275,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
}
}
assert(0 <= (int)mask && (int)mask <= 7);
drawFormatBits(ecl, mask, qrcode);
applyMask(tempBuffer, qrcode, mask);
drawFormatBits(ecl, mask, qrcode);
return true;
}

View File

@ -148,8 +148,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
if (mask == -1) { // Automatically choose best mask
long minPenalty = LONG_MAX;
for (int i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
drawFormatBits(i);
long penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
@ -161,8 +161,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
if (mask < 0 || mask > 7)
throw std::logic_error("Assertion error");
this->mask = mask;
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
drawFormatBits(mask); // Overwrite old format bits
isFunction.clear();
isFunction.shrink_to_fit();

View File

@ -573,8 +573,8 @@ public final class QrCode {
if (mask == -1) { // Automatically choose best mask
int minPenalty = Integer.MAX_VALUE;
for (int i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
drawFormatBits(i);
int penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
@ -584,8 +584,8 @@ public final class QrCode {
}
}
assert 0 <= mask && mask <= 7;
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
drawFormatBits(mask); // Overwrite old format bits
return mask; // The caller shall assign this value to the final-declared field
}

View File

@ -113,8 +113,8 @@ var qrcodegen = new function() {
if (mask == -1) { // Automatically choose best mask
var minPenalty = Infinity;
for (var i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
drawFormatBits(i);
var penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
@ -125,8 +125,8 @@ var qrcodegen = new function() {
}
if (mask < 0 || mask > 7)
throw "Assertion error";
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
drawFormatBits(mask); // Overwrite old format bits
isFunction = null;

View File

@ -209,16 +209,16 @@ class QrCode(object):
if mask == -1: # Automatically choose best mask
minpenalty = 1 << 32
for i in range(8):
self._draw_format_bits(i)
self._apply_mask(i)
self._draw_format_bits(i)
penalty = self._get_penalty_score()
if penalty < minpenalty:
mask = i
minpenalty = penalty
self._apply_mask(i) # Undoes the mask due to XOR
assert 0 <= mask <= 7
self._draw_format_bits(mask) # Overwrite old format bits
self._apply_mask(mask) # Apply the final choice of mask
self._draw_format_bits(mask) # Overwrite old format bits
# The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
# Even if a QR Code is created with automatic masking requested (mask = -1),

View File

@ -302,8 +302,8 @@ impl QrCode {
let mut minpenalty: i32 = std::i32::MAX;
for i in 0u8 .. 8 {
let newmask = Mask::new(i);
result.draw_format_bits(newmask);
result.apply_mask(newmask);
result.draw_format_bits(newmask);
let penalty: i32 = result.get_penalty_score();
if penalty < minpenalty {
mask = Some(newmask);
@ -314,8 +314,8 @@ impl QrCode {
}
let mask: Mask = mask.unwrap();
result.mask = mask;
result.draw_format_bits(mask); // Overwrite old format bits
result.apply_mask(mask); // Apply the final choice of mask
result.draw_format_bits(mask); // Overwrite old format bits
result.isfunction.clear();
result.isfunction.shrink_to_fit();

View File

@ -209,8 +209,8 @@ namespace qrcodegen {
if (mask == -1) { // Automatically choose best mask
let minPenalty: int = 1000000000;
for (let i = 0; i < 8; i++) {
this.drawFormatBits(i);
this.applyMask(i);
this.drawFormatBits(i);
const penalty: int = this.getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
@ -222,8 +222,8 @@ namespace qrcodegen {
if (mask < 0 || mask > 7)
throw "Assertion error";
this.mask = mask;
this.drawFormatBits(mask); // Overwrite old format bits
this.applyMask(mask); // Apply the final choice of mask
this.drawFormatBits(mask); // Overwrite old format bits
this.isFunction = [];
}