Simplified a small bit of variables and logic of QrCode.getPenaltyScore() in all language versions, but in a subtly different way per language.

pull/11/head
Project Nayuki 8 years ago
parent e28c1d718e
commit 0482a1ec5b

@ -716,9 +716,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
// Adjacent modules in row having same color
for (int y = 0; y < qrsize; y++) {
bool colorX = getModule(qrcode, 0, y);
for (int x = 1, runX = 1; x < qrsize; x++) {
if (getModule(qrcode, x, y) != colorX) {
bool colorX;
for (int x = 0, runX; x < qrsize; x++) {
if (x == 0 || getModule(qrcode, x, y) != colorX) {
colorX = getModule(qrcode, x, y);
runX = 1;
} else {
@ -732,9 +732,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
}
// Adjacent modules in column having same color
for (int x = 0; x < qrsize; x++) {
bool colorY = getModule(qrcode, x, 0);
for (int y = 1, runY = 1; y < qrsize; y++) {
if (getModule(qrcode, x, y) != colorY) {
bool colorY;
for (int y = 0, runY; y < qrsize; y++) {
if (y == 0 || getModule(qrcode, x, y) != colorY) {
colorY = getModule(qrcode, x, y);
runY = 1;
} else {

@ -422,9 +422,9 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in row having same color
for (int y = 0; y < size; y++) {
bool colorX = modules.at(y).at(0);
for (int x = 1, runX = 1; x < size; x++) {
if (modules.at(y).at(x) != colorX) {
bool colorX;
for (int x = 0, runX; x < size; x++) {
if (x == 0 || modules.at(y).at(x) != colorX) {
colorX = modules.at(y).at(x);
runX = 1;
} else {
@ -438,9 +438,9 @@ long QrCode::getPenaltyScore() const {
}
// Adjacent modules in column having same color
for (int x = 0; x < size; x++) {
bool colorY = modules.at(0).at(x);
for (int y = 1, runY = 1; y < size; y++) {
if (modules.at(y).at(x) != colorY) {
bool colorY;
for (int y = 0, runY; y < size; y++) {
if (y == 0 || modules.at(y).at(x) != colorY) {
colorY = modules.at(y).at(x);
runY = 1;
} else {

@ -579,9 +579,9 @@ public final class QrCode {
// Adjacent modules in row having same color
for (int y = 0; y < size; y++) {
boolean colorX = modules[y][0];
for (int x = 1, runX = 1; x < size; x++) {
if (modules[y][x] != colorX) {
boolean colorX = false;
for (int x = 0, runX = 0; x < size; x++) {
if (x == 0 || modules[y][x] != colorX) {
colorX = modules[y][x];
runX = 1;
} else {
@ -595,9 +595,9 @@ public final class QrCode {
}
// Adjacent modules in column having same color
for (int x = 0; x < size; x++) {
boolean colorY = modules[0][x];
for (int y = 1, runY = 1; y < size; y++) {
if (modules[y][x] != colorY) {
boolean colorY = false;
for (int y = 0, runY = 0; y < size; y++) {
if (y == 0 || modules[y][x] != colorY) {
colorY = modules[y][x];
runY = 1;
} else {

@ -455,9 +455,8 @@ var qrcodegen = new function() {
// Adjacent modules in row having same color
for (var y = 0; y < size; y++) {
var colorX = modules[y][0];
for (var x = 1, runX = 1; x < size; x++) {
if (modules[y][x] != colorX) {
for (var x = 0, runX, colorX; x < size; x++) {
if (x == 0 || modules[y][x] != colorX) {
colorX = modules[y][x];
runX = 1;
} else {
@ -471,9 +470,8 @@ var qrcodegen = new function() {
}
// Adjacent modules in column having same color
for (var x = 0; x < size; x++) {
var colorY = modules[0][x];
for (var y = 1, runY = 1; y < size; y++) {
if (modules[y][x] != colorY) {
for (var y = 0, runY, colorY; y < size; y++) {
if (y == 0 || modules[y][x] != colorY) {
colorY = modules[y][x];
runY = 1;
} else {

@ -436,10 +436,8 @@ class QrCode(object):
# Adjacent modules in row having same color
for y in range(size):
colorx = modules[y][0]
runx = 1
for x in range(1, size):
if modules[y][x] != colorx:
for x in range(size):
if x == 0 or modules[y][x] != colorx:
colorx = modules[y][x]
runx = 1
else:
@ -450,10 +448,8 @@ class QrCode(object):
result += 1
# Adjacent modules in column having same color
for x in range(size):
colory = modules[0][x]
runy = 1
for y in range(1, size):
if modules[y][x] != colory:
for y in range(size):
if y == 0 or modules[y][x] != colory:
colory = modules[y][x]
runy = 1
else:

Loading…
Cancel
Save