From 87868d792053f6335c9f71fb6f6b364e80bf9e88 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 17 Sep 2018 03:47:58 +0000 Subject: [PATCH] Renamed loop variables in QrCode.{drawFinderPattern(),drawAlignmentPattern()} for clarity, in all languages (but somewhat differently in C). --- c/qrcodegen.c | 22 +++++++++++----------- cpp/QrCode.cpp | 14 +++++++------- java/io/nayuki/qrcodegen/QrCode.java | 14 +++++++------- javascript/qrcodegen.js | 14 +++++++------- python/qrcodegen.py | 14 +++++++------- rust/src/lib.rs | 16 ++++++++-------- typescript/qrcodegen.ts | 16 ++++++++-------- 7 files changed, 55 insertions(+), 55 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 289b581..7ef34d0 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -359,15 +359,15 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) { } // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules) - for (int i = -4; i <= 4; i++) { - for (int j = -4; j <= 4; j++) { - int dist = abs(i); - if (abs(j) > dist) - dist = abs(j); + for (int dy = -4; dy <= 4; dy++) { + for (int dx = -4; dx <= 4; dx++) { + int dist = abs(dy); + if (abs(dx) > dist) + dist = abs(dx); if (dist == 2 || dist == 4) { - setModuleBounded(qrcode, 3 + j, 3 + i, false); - setModuleBounded(qrcode, qrsize - 4 + j, 3 + i, false); - setModuleBounded(qrcode, 3 + j, qrsize - 4 + i, false); + setModuleBounded(qrcode, 3 + dx, 3 + dy, false); + setModuleBounded(qrcode, qrsize - 4 + dx, 3 + dy, false); + setModuleBounded(qrcode, 3 + dx, qrsize - 4 + dy, false); } } } @@ -379,9 +379,9 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) { for (int j = 0; j < numAlign; j++) { if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0)) continue; // Don't draw on the three finder corners - for (int k = -1; k <= 1; k++) { - for (int l = -1; l <= 1; l++) - setModule(qrcode, alignPatPos[i] + l, alignPatPos[j] + k, k == 0 && l == 0); + for (int dy = -1; dy <= 1; dy++) { + for (int dx = -1; dx <= 1; dx++) + setModule(qrcode, alignPatPos[i] + dx, alignPatPos[j] + dy, dy == 0 && dx == 0); } } } diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 9c4db53..77faed7 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -270,10 +270,10 @@ void QrCode::drawVersion() { void QrCode::drawFinderPattern(int x, int y) { - for (int i = -4; i <= 4; i++) { - for (int j = -4; j <= 4; j++) { - int dist = std::max(std::abs(i), std::abs(j)); // Chebyshev/infinity norm - int xx = x + j, yy = y + i; + for (int dy = -4; dy <= 4; dy++) { + for (int dx = -4; dx <= 4; dx++) { + int dist = std::max(std::abs(dy), std::abs(dx)); // Chebyshev/infinity norm + int xx = x + dx, yy = y + dy; if (0 <= xx && xx < size && 0 <= yy && yy < size) setFunctionModule(xx, yy, dist != 2 && dist != 4); } @@ -282,9 +282,9 @@ void QrCode::drawFinderPattern(int x, int y) { void QrCode::drawAlignmentPattern(int x, int y) { - for (int i = -2; i <= 2; i++) { - for (int j = -2; j <= 2; j++) - setFunctionModule(x + j, y + i, std::max(std::abs(i), std::abs(j)) != 1); + for (int dy = -2; dy <= 2; dy++) { + for (int dx = -2; dx <= 2; dx++) + setFunctionModule(x + dx, y + dy, std::max(std::abs(dy), std::abs(dx)) != 1); } } diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index 47b7195..ffc8a79 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -402,10 +402,10 @@ public final class QrCode { // Draws a 9*9 finder pattern including the border separator, // with the center module at (x, y). Modules can be out of bounds. private void drawFinderPattern(int x, int y) { - for (int i = -4; i <= 4; i++) { - for (int j = -4; j <= 4; j++) { - int dist = Math.max(Math.abs(i), Math.abs(j)); // Chebyshev/infinity norm - int xx = x + j, yy = y + i; + for (int dy = -4; dy <= 4; dy++) { + for (int dx = -4; dx <= 4; dx++) { + int dist = Math.max(Math.abs(dy), Math.abs(dx)); // Chebyshev/infinity norm + int xx = x + dx, yy = y + dy; if (0 <= xx && xx < size && 0 <= yy && yy < size) setFunctionModule(xx, yy, dist != 2 && dist != 4); } @@ -416,9 +416,9 @@ public final class QrCode { // Draws a 5*5 alignment pattern, with the center module // at (x, y). All modules must be in bounds. private void drawAlignmentPattern(int x, int y) { - for (int i = -2; i <= 2; i++) { - for (int j = -2; j <= 2; j++) - setFunctionModule(x + j, y + i, Math.max(Math.abs(i), Math.abs(j)) != 1); + for (int dy = -2; dy <= 2; dy++) { + for (int dx = -2; dx <= 2; dx++) + setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dy), Math.abs(dx)) != 1); } } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 1492733..63d489d 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -276,10 +276,10 @@ var qrcodegen = new function() { // Draws a 9*9 finder pattern including the border separator, // with the center module at (x, y). Modules can be out of bounds. function drawFinderPattern(x, y) { - for (var i = -4; i <= 4; i++) { - for (var j = -4; j <= 4; j++) { - var dist = Math.max(Math.abs(i), Math.abs(j)); // Chebyshev/infinity norm - var xx = x + j, yy = y + i; + for (var dy = -4; dy <= 4; dy++) { + for (var dx = -4; dx <= 4; dx++) { + var dist = Math.max(Math.abs(dy), Math.abs(dx)); // Chebyshev/infinity norm + var xx = x + dx, yy = y + dy; if (0 <= xx && xx < size && 0 <= yy && yy < size) setFunctionModule(xx, yy, dist != 2 && dist != 4); } @@ -290,9 +290,9 @@ var qrcodegen = new function() { // Draws a 5*5 alignment pattern, with the center module // at (x, y). All modules must be in bounds. function drawAlignmentPattern(x, y) { - for (var i = -2; i <= 2; i++) { - for (var j = -2; j <= 2; j++) - setFunctionModule(x + j, y + i, Math.max(Math.abs(i), Math.abs(j)) != 1); + for (var dy = -2; dy <= 2; dy++) { + for (var dx = -2; dx <= 2; dx++) + setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dy), Math.abs(dx)) != 1); } } diff --git a/python/qrcodegen.py b/python/qrcodegen.py index e1326b8..15d9f7e 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -322,20 +322,20 @@ class QrCode(object): def _draw_finder_pattern(self, x, y): """Draws a 9*9 finder pattern including the border separator, with the center module at (x, y). Modules can be out of bounds.""" - for i in range(-4, 5): - for j in range(-4, 5): - xx, yy = x + j, y + i + for dy in range(-4, 5): + for dx in range(-4, 5): + xx, yy = x + dx, y + dy if (0 <= xx < self._size) and (0 <= yy < self._size): # Chebyshev/infinity norm - self._set_function_module(xx, yy, max(abs(i), abs(j)) not in (2, 4)) + self._set_function_module(xx, yy, max(abs(dy), abs(dx)) not in (2, 4)) def _draw_alignment_pattern(self, x, y): """Draws a 5*5 alignment pattern, with the center module at (x, y). All modules must be in bounds.""" - for i in range(-2, 3): - for j in range(-2, 3): - self._set_function_module(x + j, y + i, max(abs(i), abs(j)) != 1) + for dy in range(-2, 3): + for dx in range(-2, 3): + self._set_function_module(x + dx, y + dy, max(abs(dy), abs(dx)) != 1) def _set_function_module(self, x, y, isblack): diff --git a/rust/src/lib.rs b/rust/src/lib.rs index a37a533..3bbf56a 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -367,12 +367,12 @@ impl QrCode { // Draws a 9*9 finder pattern including the border separator, // with the center module at (x, y). Modules can be out of bounds. fn draw_finder_pattern(&mut self, x: i32, y: i32) { - for i in -4 .. 5 { - for j in -4 .. 5 { - let xx: i32 = x + j; - let yy: i32 = y + i; + for dy in -4 .. 5 { + for dx in -4 .. 5 { + let xx: i32 = x + dx; + let yy: i32 = y + dy; if 0 <= xx && xx < self.size && 0 <= yy && yy < self.size { - let dist: i32 = std::cmp::max(i.abs(), j.abs()); // Chebyshev/infinity norm + let dist: i32 = std::cmp::max(dy.abs(), dx.abs()); // Chebyshev/infinity norm self.set_function_module(xx, yy, dist != 2 && dist != 4); } } @@ -383,9 +383,9 @@ impl QrCode { // Draws a 5*5 alignment pattern, with the center module // at (x, y). All modules must be in bounds. fn draw_alignment_pattern(&mut self, x: i32, y: i32) { - for i in -2 .. 3 { - for j in -2 .. 3 { - self.set_function_module(x + j, y + i, std::cmp::max(i.abs(), j.abs()) != 1); + for dy in -2 .. 3 { + for dx in -2 .. 3 { + self.set_function_module(x + dx, y + dy, std::cmp::max(dy.abs(), dx.abs()) != 1); } } } diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 420407d..7d20e7d 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -345,11 +345,11 @@ namespace qrcodegen { // Draws a 9*9 finder pattern including the border separator, // with the center module at (x, y). Modules can be out of bounds. private drawFinderPattern(x: int, y: int): void { - for (let i = -4; i <= 4; i++) { - for (let j = -4; j <= 4; j++) { - let dist: int = Math.max(Math.abs(i), Math.abs(j)); // Chebyshev/infinity norm - let xx: int = x + j; - let yy: int = y + i; + for (let dy = -4; dy <= 4; dy++) { + for (let dx = -4; dx <= 4; dx++) { + let dist: int = Math.max(Math.abs(dy), Math.abs(dx)); // Chebyshev/infinity norm + let xx: int = x + dx; + let yy: int = y + dy; if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size) this.setFunctionModule(xx, yy, dist != 2 && dist != 4); } @@ -360,9 +360,9 @@ namespace qrcodegen { // Draws a 5*5 alignment pattern, with the center module // at (x, y). All modules must be in bounds. private drawAlignmentPattern(x: int, y: int): void { - for (let i = -2; i <= 2; i++) { - for (let j = -2; j <= 2; j++) - this.setFunctionModule(x + j, y + i, Math.max(Math.abs(i), Math.abs(j)) != 1); + for (let dy = -2; dy <= 2; dy++) { + for (let dx = -2; dx <= 2; dx++) + this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dy), Math.abs(dx)) != 1); } }