Inverted some if-else statements in QrCode.getPenaltyScore() without changing behavior, in all languages.

pull/40/head
Project Nayuki 6 years ago
parent 111b20b2b9
commit 5ac0e2a938

@ -635,15 +635,15 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
bool color = false;
int runX = 0;
for (int x = 0; x < qrsize; x++) {
if (getModule(qrcode, x, y) != color) {
color = getModule(qrcode, x, y);
runX = 1;
} else {
if (getModule(qrcode, x, y) == color) {
runX++;
if (runX == 5)
result += PENALTY_N1;
else if (runX > 5)
result++;
} else {
color = getModule(qrcode, x, y);
runX = 1;
}
}
}
@ -652,15 +652,15 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
bool color = false;
int runY = 0;
for (int y = 0; y < qrsize; y++) {
if (getModule(qrcode, x, y) != color) {
color = getModule(qrcode, x, y);
runY = 1;
} else {
if (getModule(qrcode, x, y) == color) {
runY++;
if (runY == 5)
result += PENALTY_N1;
else if (runY > 5)
result++;
} else {
color = getModule(qrcode, x, y);
runY = 1;
}
}
}

@ -433,15 +433,15 @@ long QrCode::getPenaltyScore() const {
bool color = false;
int runX = 0;
for (int x = 0; x < size; x++) {
if (module(x, y) != color) {
color = module(x, y);
runX = 1;
} else {
if (module(x, y) == color) {
runX++;
if (runX == 5)
result += PENALTY_N1;
else if (runX > 5)
result++;
} else {
color = module(x, y);
runX = 1;
}
}
}
@ -450,15 +450,15 @@ long QrCode::getPenaltyScore() const {
bool color = false;
int runY = 0;
for (int y = 0; y < size; y++) {
if (module(x, y) != color) {
color = module(x, y);
runY = 1;
} else {
if (module(x, y) == color) {
runY++;
if (runY == 5)
result += PENALTY_N1;
else if (runY > 5)
result++;
} else {
color = module(x, y);
runY = 1;
}
}
}

@ -600,15 +600,15 @@ public final class QrCode {
boolean color = false;
int runX = 0;
for (int x = 0; x < size; x++) {
if (modules[y][x] != color) {
color = modules[y][x];
runX = 1;
} else {
if (modules[y][x] == color) {
runX++;
if (runX == 5)
result += PENALTY_N1;
else if (runX > 5)
result++;
} else {
color = modules[y][x];
runX = 1;
}
}
}
@ -617,15 +617,15 @@ public final class QrCode {
boolean color = false;
int runY = 0;
for (int y = 0; y < size; y++) {
if (modules[y][x] != color) {
color = modules[y][x];
runY = 1;
} else {
if (modules[y][x] == color) {
runY++;
if (runY == 5)
result += PENALTY_N1;
else if (runY > 5)
result++;
} else {
color = modules[y][x];
runY = 1;
}
}
}

@ -432,15 +432,15 @@ var qrcodegen = new function() {
var color = false;
var runX = 0;
for (var x = 0; x < size; x++) {
if (modules[y][x] != color) {
color = modules[y][x];
runX = 1;
} else {
if (modules[y][x] == color) {
runX++;
if (runX == 5)
result += QrCode.PENALTY_N1;
else if (runX > 5)
result++;
} else {
color = modules[y][x];
runX = 1;
}
}
}
@ -449,15 +449,15 @@ var qrcodegen = new function() {
var color = false;
var runY = 0;
for (var y = 0; y < size; y++) {
if (modules[y][x] != color) {
color = modules[y][x];
runY = 1;
} else {
if (modules[y][x] == color) {
runY++;
if (runY == 5)
result += QrCode.PENALTY_N1;
else if (runY > 5)
result++;
} else {
color = modules[y][x];
runY = 1;
}
}
}

@ -467,29 +467,29 @@ class QrCode(object):
color = False
runx = 0
for x in range(size):
if modules[y][x] != color:
color = modules[y][x]
runx = 1
else:
if modules[y][x] == color:
runx += 1
if runx == 5:
result += QrCode._PENALTY_N1
elif runx > 5:
result += 1
else:
color = modules[y][x]
runx = 1
# Adjacent modules in column having same color
for x in range(size):
color = False
runy = 0
for y in range(size):
if modules[y][x] != color:
color = modules[y][x]
runy = 1
else:
if modules[y][x] == color:
runy += 1
if runy == 5:
result += QrCode._PENALTY_N1
elif runy > 5:
result += 1
else:
color = modules[y][x]
runy = 1
# 2*2 blocks of modules having same color
for y in range(size - 1):

@ -650,16 +650,16 @@ impl QrCode {
let mut color = false;
let mut runx: i32 = 0;
for x in 0 .. size {
if self.module(x, y) != color {
color = self.module(x, y);
runx = 1;
} else {
if self.module(x, y) == color {
runx += 1;
if runx == 5 {
result += PENALTY_N1;
} else if runx > 5 {
result += 1;
}
} else {
color = self.module(x, y);
runx = 1;
}
}
}
@ -668,16 +668,16 @@ impl QrCode {
let mut color = false;
let mut runy: i32 = 0;
for y in 0 .. size {
if self.module(x, y) != color {
color = self.module(x, y);
runy = 1;
} else {
if self.module(x, y) == color {
runy += 1;
if runy == 5 {
result += PENALTY_N1;
} else if runy > 5 {
result += 1;
}
} else {
color = self.module(x, y);
runy = 1;
}
}
}

@ -515,15 +515,15 @@ namespace qrcodegen {
let color = false;
let runX = 0;
for (let x = 0; x < this.size; x++) {
if (this.modules[y][x] != color) {
color = this.modules[y][x];
runX = 1;
} else {
if (this.modules[y][x] == color) {
runX++;
if (runX == 5)
result += QrCode.PENALTY_N1;
else if (runX > 5)
result++;
} else {
color = this.modules[y][x];
runX = 1;
}
}
}
@ -532,15 +532,15 @@ namespace qrcodegen {
let color = false;
let runY = 0;
for (let y = 0; y < this.size; y++) {
if (this.modules[y][x] != color) {
color = this.modules[y][x];
runY = 1;
} else {
if (this.modules[y][x] == color) {
runY++;
if (runY == 5)
result += QrCode.PENALTY_N1;
else if (runY > 5)
result++;
} else {
color = this.modules[y][x];
runY = 1;
}
}
}

Loading…
Cancel
Save