Tweaked logic in QrCode.getPenaltyScore() for future expansion, without changing behavior, in all languages.

This commit is contained in:
Project Nayuki 2018-10-26 05:21:34 +00:00
parent a14de3d959
commit 111b20b2b9
7 changed files with 42 additions and 24 deletions

View File

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

View File

@ -431,8 +431,9 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in row having same color
for (int y = 0; y < size; y++) {
bool color = false;
for (int x = 0, runX = -1; x < size; x++) {
if (x == 0 || module(x, y) != color) {
int runX = 0;
for (int x = 0; x < size; x++) {
if (module(x, y) != color) {
color = module(x, y);
runX = 1;
} else {
@ -447,8 +448,9 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in column having same color
for (int x = 0; x < size; x++) {
bool color = false;
for (int y = 0, runY = -1; y < size; y++) {
if (y == 0 || module(x, y) != color) {
int runY = 0;
for (int y = 0; y < size; y++) {
if (module(x, y) != color) {
color = module(x, y);
runY = 1;
} else {

View File

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

View File

@ -429,8 +429,10 @@ var qrcodegen = new function() {
// Adjacent modules in row having same color
for (var y = 0; y < size; y++) {
for (var x = 0, runX, color; x < size; x++) {
if (x == 0 || modules[y][x] != color) {
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 {
@ -444,8 +446,10 @@ var qrcodegen = new function() {
}
// Adjacent modules in column having same color
for (var x = 0; x < size; x++) {
for (var y = 0, runY, color; y < size; y++) {
if (y == 0 || modules[y][x] != color) {
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 {

View File

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

View File

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

View File

@ -512,8 +512,10 @@ namespace qrcodegen {
// Adjacent modules in row having same color
for (let y = 0; y < this.size; y++) {
for (let x = 0, runX = 0, color = false; x < this.size; x++) {
if (x == 0 || this.modules[y][x] != color) {
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 {
@ -527,8 +529,10 @@ namespace qrcodegen {
}
// Adjacent modules in column having same color
for (let x = 0; x < this.size; x++) {
for (let y = 0, runY = 0, color = false; y < this.size; y++) {
if (y == 0 || this.modules[y][x] != color) {
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 {