From 6903d28c904d3b6768a91cbfbb4659ec794a99ca Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 17 Sep 2018 03:51:57 +0000 Subject: [PATCH] Swapped {dy,dx} variables in commutative operations for clarity, in all languages. --- c/qrcodegen.c | 8 ++++---- cpp/QrCode.cpp | 4 ++-- java/io/nayuki/qrcodegen/QrCode.java | 4 ++-- javascript/qrcodegen.js | 4 ++-- python/qrcodegen.py | 4 ++-- rust/src/lib.rs | 4 ++-- typescript/qrcodegen.ts | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 7ef34d0..c2823cd 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -361,9 +361,9 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) { // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules) 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); + int dist = abs(dx); + if (abs(dy) > dist) + dist = abs(dy); if (dist == 2 || dist == 4) { setModuleBounded(qrcode, 3 + dx, 3 + dy, false); setModuleBounded(qrcode, qrsize - 4 + dx, 3 + dy, false); @@ -381,7 +381,7 @@ static void drawWhiteFunctionModules(uint8_t qrcode[], int version) { continue; // Don't draw on the three finder corners 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); + setModule(qrcode, alignPatPos[i] + dx, alignPatPos[j] + dy, dx == 0 && dy == 0); } } } diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 77faed7..3a9b25a 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -272,7 +272,7 @@ void QrCode::drawVersion() { void QrCode::drawFinderPattern(int x, int y) { 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 dist = std::max(std::abs(dx), std::abs(dy)); // 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); @@ -284,7 +284,7 @@ void QrCode::drawFinderPattern(int x, int y) { void QrCode::drawAlignmentPattern(int x, int y) { 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); + setFunctionModule(x + dx, y + dy, std::max(std::abs(dx), std::abs(dy)) != 1); } } diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index ffc8a79..6e0669c 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -404,7 +404,7 @@ public final class QrCode { private void drawFinderPattern(int x, int y) { 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 dist = Math.max(Math.abs(dx), Math.abs(dy)); // 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); @@ -418,7 +418,7 @@ public final class QrCode { private void drawAlignmentPattern(int x, int y) { 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); + setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1); } } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 63d489d..0fd17ad 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -278,7 +278,7 @@ var qrcodegen = new function() { function drawFinderPattern(x, y) { 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 dist = Math.max(Math.abs(dx), Math.abs(dy)); // 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); @@ -292,7 +292,7 @@ var qrcodegen = new function() { function drawAlignmentPattern(x, y) { 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); + setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1); } } diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 15d9f7e..4327f65 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -327,7 +327,7 @@ class QrCode(object): 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(dy), abs(dx)) not in (2, 4)) + self._set_function_module(xx, yy, max(abs(dx), abs(dy)) not in (2, 4)) def _draw_alignment_pattern(self, x, y): @@ -335,7 +335,7 @@ class QrCode(object): at (x, y). All modules must be in bounds.""" 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) + self._set_function_module(x + dx, y + dy, max(abs(dx), abs(dy)) != 1) def _set_function_module(self, x, y, isblack): diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 3bbf56a..7e345e7 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -372,7 +372,7 @@ impl QrCode { 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(dy.abs(), dx.abs()); // Chebyshev/infinity norm + let dist: i32 = std::cmp::max(dx.abs(), dy.abs()); // Chebyshev/infinity norm self.set_function_module(xx, yy, dist != 2 && dist != 4); } } @@ -385,7 +385,7 @@ impl QrCode { fn draw_alignment_pattern(&mut self, x: i32, y: i32) { 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); + self.set_function_module(x + dx, y + dy, std::cmp::max(dx.abs(), dy.abs()) != 1); } } } diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 7d20e7d..b975987 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -347,7 +347,7 @@ namespace qrcodegen { private drawFinderPattern(x: int, y: int): void { 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 dist: int = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm let xx: int = x + dx; let yy: int = y + dy; if (0 <= xx && xx < this.size && 0 <= yy && yy < this.size) @@ -362,7 +362,7 @@ namespace qrcodegen { private drawAlignmentPattern(x: int, y: int): void { 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); + this.setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1); } }