Renamed a local variable in all language versions (although the Java version has different logic).

pull/62/head
Project Nayuki 6 years ago
parent b2ff7ce765
commit 1ca214499b

@ -635,10 +635,10 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
for (int y = 0; y < qrsize; y++) { for (int y = 0; y < qrsize; y++) {
unsigned char runHistory[7] = {0}; unsigned char runHistory[7] = {0};
bool color = false; bool runColor = false;
unsigned char runX = 0; unsigned char runX = 0;
for (int x = 0; x < qrsize; x++) { for (int x = 0; x < qrsize; x++) {
if (getModule(qrcode, x, y) == color) { if (getModule(qrcode, x, y) == runColor) {
runX++; runX++;
if (runX == 5) if (runX == 5)
result += PENALTY_N1; result += PENALTY_N1;
@ -646,14 +646,14 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
result++; result++;
} else { } else {
addRunToHistory(runX, runHistory); addRunToHistory(runX, runHistory);
if (!color && hasFinderLikePattern(runHistory)) if (!runColor && hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
color = getModule(qrcode, x, y); runColor = getModule(qrcode, x, y);
runX = 1; runX = 1;
} }
} }
addRunToHistory(runX, runHistory); addRunToHistory(runX, runHistory);
if (color) if (runColor)
addRunToHistory(0, runHistory); // Dummy run of white addRunToHistory(0, runHistory); // Dummy run of white
if (hasFinderLikePattern(runHistory)) if (hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
@ -661,10 +661,10 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for (int x = 0; x < qrsize; x++) { for (int x = 0; x < qrsize; x++) {
unsigned char runHistory[7] = {0}; unsigned char runHistory[7] = {0};
bool color = false; bool runColor = false;
unsigned char runY = 0; unsigned char runY = 0;
for (int y = 0; y < qrsize; y++) { for (int y = 0; y < qrsize; y++) {
if (getModule(qrcode, x, y) == color) { if (getModule(qrcode, x, y) == runColor) {
runY++; runY++;
if (runY == 5) if (runY == 5)
result += PENALTY_N1; result += PENALTY_N1;
@ -672,14 +672,14 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
result++; result++;
} else { } else {
addRunToHistory(runY, runHistory); addRunToHistory(runY, runHistory);
if (!color && hasFinderLikePattern(runHistory)) if (!runColor && hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
color = getModule(qrcode, x, y); runColor = getModule(qrcode, x, y);
runY = 1; runY = 1;
} }
} }
addRunToHistory(runY, runHistory); addRunToHistory(runY, runHistory);
if (color) if (runColor)
addRunToHistory(0, runHistory); // Dummy run of white addRunToHistory(0, runHistory); // Dummy run of white
if (hasFinderLikePattern(runHistory)) if (hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;

@ -428,10 +428,10 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
std::deque<int> runHistory(7, 0); std::deque<int> runHistory(7, 0);
bool color = false; bool runColor = false;
int runX = 0; int runX = 0;
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
if (module(x, y) == color) { if (module(x, y) == runColor) {
runX++; runX++;
if (runX == 5) if (runX == 5)
result += PENALTY_N1; result += PENALTY_N1;
@ -439,14 +439,14 @@ long QrCode::getPenaltyScore() const {
result++; result++;
} else { } else {
addRunToHistory(runX, runHistory); addRunToHistory(runX, runHistory);
if (!color && hasFinderLikePattern(runHistory)) if (!runColor && hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
color = module(x, y); runColor = module(x, y);
runX = 1; runX = 1;
} }
} }
addRunToHistory(runX, runHistory); addRunToHistory(runX, runHistory);
if (color) if (runColor)
addRunToHistory(0, runHistory); // Dummy run of white addRunToHistory(0, runHistory); // Dummy run of white
if (hasFinderLikePattern(runHistory)) if (hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
@ -454,10 +454,10 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
std::deque<int> runHistory(7, 0); std::deque<int> runHistory(7, 0);
bool color = false; bool runColor = false;
int runY = 0; int runY = 0;
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
if (module(x, y) == color) { if (module(x, y) == runColor) {
runY++; runY++;
if (runY == 5) if (runY == 5)
result += PENALTY_N1; result += PENALTY_N1;
@ -465,14 +465,14 @@ long QrCode::getPenaltyScore() const {
result++; result++;
} else { } else {
addRunToHistory(runY, runHistory); addRunToHistory(runY, runHistory);
if (!color && hasFinderLikePattern(runHistory)) if (!runColor && hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;
color = module(x, y); runColor = module(x, y);
runY = 1; runY = 1;
} }
} }
addRunToHistory(runY, runHistory); addRunToHistory(runY, runHistory);
if (color) if (runColor)
addRunToHistory(0, runHistory); // Dummy run of white addRunToHistory(0, runHistory); // Dummy run of white
if (hasFinderLikePattern(runHistory)) if (hasFinderLikePattern(runHistory))
result += PENALTY_N3; result += PENALTY_N3;

@ -598,41 +598,41 @@ public final class QrCode {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
FinderPatternDetector det = new FinderPatternDetector(); FinderPatternDetector det = new FinderPatternDetector();
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
boolean color = false; boolean runClor = false;
int runX = 0; int runX = 0;
det.reset(); det.reset();
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
if (modules[y][x] == color) { if (modules[y][x] == runClor) {
runX++; runX++;
if (runX == 5) if (runX == 5)
result += PENALTY_N1; result += PENALTY_N1;
else if (runX > 5) else if (runX > 5)
result++; result++;
} else { } else {
color = modules[y][x]; runClor = modules[y][x];
runX = 1; runX = 1;
} }
result += det.addModuleAndMatch(color) * PENALTY_N3; result += det.addModuleAndMatch(runClor) * PENALTY_N3;
} }
result += det.terminateAndMatch() * PENALTY_N3; result += det.terminateAndMatch() * PENALTY_N3;
} }
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
det.reset(); det.reset();
boolean color = false; boolean runColor = false;
int runY = 0; int runY = 0;
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
if (modules[y][x] == color) { if (modules[y][x] == runColor) {
runY++; runY++;
if (runY == 5) if (runY == 5)
result += PENALTY_N1; result += PENALTY_N1;
else if (runY > 5) else if (runY > 5)
result++; result++;
} else { } else {
color = modules[y][x]; runColor = modules[y][x];
runY = 1; runY = 1;
} }
result += det.addModuleAndMatch(color) * PENALTY_N3; result += det.addModuleAndMatch(runColor) * PENALTY_N3;
} }
result += det.terminateAndMatch() * PENALTY_N3; result += det.terminateAndMatch() * PENALTY_N3;
} }

@ -430,10 +430,10 @@ var qrcodegen = new function() {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
for (var y = 0; y < size; y++) { for (var y = 0; y < size; y++) {
var runHistory = [0,0,0,0,0,0,0]; var runHistory = [0,0,0,0,0,0,0];
var color = false; var runColor = false;
var runX = 0; var runX = 0;
for (var x = 0; x < size; x++) { for (var x = 0; x < size; x++) {
if (modules[y][x] == color) { if (modules[y][x] == runColor) {
runX++; runX++;
if (runX == 5) if (runX == 5)
result += QrCode.PENALTY_N1; result += QrCode.PENALTY_N1;
@ -441,14 +441,14 @@ var qrcodegen = new function() {
result++; result++;
} else { } else {
QrCode.addRunToHistory(runX, runHistory); QrCode.addRunToHistory(runX, runHistory);
if (!color && QrCode.hasFinderLikePattern(runHistory)) if (!runColor && QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
color = modules[y][x]; runColor = modules[y][x];
runX = 1; runX = 1;
} }
} }
QrCode.addRunToHistory(runX, runHistory); QrCode.addRunToHistory(runX, runHistory);
if (color) if (runColor)
QrCode.addRunToHistory(0, runHistory); // Dummy run of white QrCode.addRunToHistory(0, runHistory); // Dummy run of white
if (QrCode.hasFinderLikePattern(runHistory)) if (QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
@ -456,10 +456,10 @@ var qrcodegen = new function() {
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for (var x = 0; x < size; x++) { for (var x = 0; x < size; x++) {
var runHistory = [0,0,0,0,0,0,0]; var runHistory = [0,0,0,0,0,0,0];
var color = false; var runColor = false;
var runY = 0; var runY = 0;
for (var y = 0; y < size; y++) { for (var y = 0; y < size; y++) {
if (modules[y][x] == color) { if (modules[y][x] == runColor) {
runY++; runY++;
if (runY == 5) if (runY == 5)
result += QrCode.PENALTY_N1; result += QrCode.PENALTY_N1;
@ -467,14 +467,14 @@ var qrcodegen = new function() {
result++; result++;
} else { } else {
QrCode.addRunToHistory(runY, runHistory); QrCode.addRunToHistory(runY, runHistory);
if (!color && QrCode.hasFinderLikePattern(runHistory)) if (!runColor && QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
color = modules[y][x]; runColor = modules[y][x];
runY = 1; runY = 1;
} }
} }
QrCode.addRunToHistory(runY, runHistory); QrCode.addRunToHistory(runY, runHistory);
if (color) if (runColor)
QrCode.addRunToHistory(0, runHistory); // Dummy run of white QrCode.addRunToHistory(0, runHistory); // Dummy run of white
if (QrCode.hasFinderLikePattern(runHistory)) if (QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;

@ -465,10 +465,10 @@ class QrCode(object):
# Adjacent modules in row having same color, and finder-like patterns # Adjacent modules in row having same color, and finder-like patterns
for y in range(size): for y in range(size):
runhistory = collections.deque([0] * 7, 7) runhistory = collections.deque([0] * 7, 7)
color = False runcolor = False
runx = 0 runx = 0
for x in range(size): for x in range(size):
if modules[y][x] == color: if modules[y][x] == runcolor:
runx += 1 runx += 1
if runx == 5: if runx == 5:
result += QrCode._PENALTY_N1 result += QrCode._PENALTY_N1
@ -476,22 +476,22 @@ class QrCode(object):
result += 1 result += 1
else: else:
runhistory.appendleft(runx) runhistory.appendleft(runx)
if not color and QrCode.has_finder_like_pattern(runhistory): if not runcolor and QrCode.has_finder_like_pattern(runhistory):
result += QrCode._PENALTY_N3 result += QrCode._PENALTY_N3
color = modules[y][x] runcolor = modules[y][x]
runx = 1 runx = 1
runhistory.appendleft(runx) runhistory.appendleft(runx)
if color: if runcolor:
runhistory.appendleft(0) # Dummy run of white runhistory.appendleft(0) # Dummy run of white
if QrCode.has_finder_like_pattern(runhistory): if QrCode.has_finder_like_pattern(runhistory):
result += QrCode._PENALTY_N3 result += QrCode._PENALTY_N3
# Adjacent modules in column having same color, and finder-like patterns # Adjacent modules in column having same color, and finder-like patterns
for x in range(size): for x in range(size):
runhistory = collections.deque([0] * 7, 7) runhistory = collections.deque([0] * 7, 7)
color = False runcolor = False
runy = 0 runy = 0
for y in range(size): for y in range(size):
if modules[y][x] == color: if modules[y][x] == runcolor:
runy += 1 runy += 1
if runy == 5: if runy == 5:
result += QrCode._PENALTY_N1 result += QrCode._PENALTY_N1
@ -499,12 +499,12 @@ class QrCode(object):
result += 1 result += 1
else: else:
runhistory.appendleft(runy) runhistory.appendleft(runy)
if not color and QrCode.has_finder_like_pattern(runhistory): if not runcolor and QrCode.has_finder_like_pattern(runhistory):
result += QrCode._PENALTY_N3 result += QrCode._PENALTY_N3
color = modules[y][x] runcolor = modules[y][x]
runy = 1 runy = 1
runhistory.appendleft(runy) runhistory.appendleft(runy)
if color: if runcolor:
runhistory.appendleft(0) # Dummy run of white runhistory.appendleft(0) # Dummy run of white
if QrCode.has_finder_like_pattern(runhistory): if QrCode.has_finder_like_pattern(runhistory):
result += QrCode._PENALTY_N3 result += QrCode._PENALTY_N3

@ -643,10 +643,10 @@ impl QrCode {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
for y in 0 .. size { for y in 0 .. size {
let mut runhistory = RunHistory::new(); let mut runhistory = RunHistory::new();
let mut color = false; let mut runcolor = false;
let mut runx: i32 = 0; let mut runx: i32 = 0;
for x in 0 .. size { for x in 0 .. size {
if self.module(x, y) == color { if self.module(x, y) == runcolor {
runx += 1; runx += 1;
if runx == 5 { if runx == 5 {
result += PENALTY_N1; result += PENALTY_N1;
@ -655,15 +655,15 @@ impl QrCode {
} }
} else { } else {
runhistory.add_run(runx); runhistory.add_run(runx);
if !color && runhistory.has_finder_like_pattern() { if !runcolor && runhistory.has_finder_like_pattern() {
result += PENALTY_N3; result += PENALTY_N3;
} }
color = self.module(x, y); runcolor = self.module(x, y);
runx = 1; runx = 1;
} }
} }
runhistory.add_run(runx); runhistory.add_run(runx);
if color { if runcolor {
runhistory.add_run(0); // Dummy run of white runhistory.add_run(0); // Dummy run of white
} }
if runhistory.has_finder_like_pattern() { if runhistory.has_finder_like_pattern() {
@ -673,10 +673,10 @@ impl QrCode {
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for x in 0 .. size { for x in 0 .. size {
let mut runhistory = RunHistory::new(); let mut runhistory = RunHistory::new();
let mut color = false; let mut runcolor = false;
let mut runy: i32 = 0; let mut runy: i32 = 0;
for y in 0 .. size { for y in 0 .. size {
if self.module(x, y) == color { if self.module(x, y) == runcolor {
runy += 1; runy += 1;
if runy == 5 { if runy == 5 {
result += PENALTY_N1; result += PENALTY_N1;
@ -685,15 +685,15 @@ impl QrCode {
} }
} else { } else {
runhistory.add_run(runy); runhistory.add_run(runy);
if !color && runhistory.has_finder_like_pattern() { if !runcolor && runhistory.has_finder_like_pattern() {
result += PENALTY_N3; result += PENALTY_N3;
} }
color = self.module(x, y); runcolor = self.module(x, y);
runy = 1; runy = 1;
} }
} }
runhistory.add_run(runy); runhistory.add_run(runy);
if color { if runcolor {
runhistory.add_run(0); // Dummy run of white runhistory.add_run(0); // Dummy run of white
} }
if runhistory.has_finder_like_pattern() { if runhistory.has_finder_like_pattern() {

@ -513,10 +513,10 @@ namespace qrcodegen {
// Adjacent modules in row having same color, and finder-like patterns // Adjacent modules in row having same color, and finder-like patterns
for (let y = 0; y < this.size; y++) { for (let y = 0; y < this.size; y++) {
let runHistory = [0,0,0,0,0,0,0]; let runHistory = [0,0,0,0,0,0,0];
let color = false; let runColor = false;
let runX = 0; let runX = 0;
for (let x = 0; x < this.size; x++) { for (let x = 0; x < this.size; x++) {
if (this.modules[y][x] == color) { if (this.modules[y][x] == runColor) {
runX++; runX++;
if (runX == 5) if (runX == 5)
result += QrCode.PENALTY_N1; result += QrCode.PENALTY_N1;
@ -524,14 +524,14 @@ namespace qrcodegen {
result++; result++;
} else { } else {
QrCode.addRunToHistory(runX, runHistory); QrCode.addRunToHistory(runX, runHistory);
if (!color && QrCode.hasFinderLikePattern(runHistory)) if (!runColor && QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
color = this.modules[y][x]; runColor = this.modules[y][x];
runX = 1; runX = 1;
} }
} }
QrCode.addRunToHistory(runX, runHistory); QrCode.addRunToHistory(runX, runHistory);
if (color) if (runColor)
QrCode.addRunToHistory(0, runHistory); // Dummy run of white QrCode.addRunToHistory(0, runHistory); // Dummy run of white
if (QrCode.hasFinderLikePattern(runHistory)) if (QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
@ -539,10 +539,10 @@ namespace qrcodegen {
// Adjacent modules in column having same color, and finder-like patterns // Adjacent modules in column having same color, and finder-like patterns
for (let x = 0; x < this.size; x++) { for (let x = 0; x < this.size; x++) {
let runHistory = [0,0,0,0,0,0,0]; let runHistory = [0,0,0,0,0,0,0];
let color = false; let runColor = false;
let runY = 0; let runY = 0;
for (let y = 0; y < this.size; y++) { for (let y = 0; y < this.size; y++) {
if (this.modules[y][x] == color) { if (this.modules[y][x] == runColor) {
runY++; runY++;
if (runY == 5) if (runY == 5)
result += QrCode.PENALTY_N1; result += QrCode.PENALTY_N1;
@ -550,14 +550,14 @@ namespace qrcodegen {
result++; result++;
} else { } else {
QrCode.addRunToHistory(runY, runHistory); QrCode.addRunToHistory(runY, runHistory);
if (!color && QrCode.hasFinderLikePattern(runHistory)) if (!runColor && QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;
color = this.modules[y][x]; runColor = this.modules[y][x];
runY = 1; runY = 1;
} }
} }
QrCode.addRunToHistory(runY, runHistory); QrCode.addRunToHistory(runY, runHistory);
if (color) if (runColor)
QrCode.addRunToHistory(0, runHistory); // Dummy run of white QrCode.addRunToHistory(0, runHistory); // Dummy run of white
if (QrCode.hasFinderLikePattern(runHistory)) if (QrCode.hasFinderLikePattern(runHistory))
result += QrCode.PENALTY_N3; result += QrCode.PENALTY_N3;

Loading…
Cancel
Save