Updated and added 5 comments in all language versions except C.

pull/39/merge
Project Nayuki 7 years ago
parent d1f53e6e7d
commit 62930ef455

@ -164,6 +164,7 @@ class QrCode final {
/*---- Private helper methods for constructor: Drawing function modules ----*/ /*---- Private helper methods for constructor: Drawing function modules ----*/
// Reads this object's version field, and draws and marks all function modules.
private: void drawFunctionPatterns(); private: void drawFunctionPatterns();
@ -173,20 +174,22 @@ class QrCode final {
// Draws two copies of the version bits (with its own error correction code), // Draws two copies of the version bits (with its own error correction code),
// based on this object's version field (which only has an effect for 7 <= version <= 40). // based on this object's version field, iff 7 <= version <= 40.
private: void drawVersion(); private: void drawVersion();
// Draws a 9*9 finder pattern including the border separator, with the center module at (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.
private: void drawFinderPattern(int x, int y); private: void drawFinderPattern(int x, int y);
// Draws a 5*5 alignment pattern, with the center module at (x, y). // 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); private: void drawAlignmentPattern(int x, int y);
// Sets the color of a module and marks it as a function module. // Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in range. // Only used by the constructor. Coordinates must be in bounds.
private: void setFunctionModule(int x, int y, bool isBlack); private: void setFunctionModule(int x, int y, bool isBlack);

@ -312,6 +312,7 @@ public final class QrCode {
/*---- Private helper methods for constructor: Drawing function modules ----*/ /*---- Private helper methods for constructor: Drawing function modules ----*/
// Reads this object's version field, and draws and marks all function modules.
private void drawFunctionPatterns() { private void drawFunctionPatterns() {
// Draw horizontal and vertical timing patterns // Draw horizontal and vertical timing patterns
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
@ -373,7 +374,7 @@ public final class QrCode {
// Draws two copies of the version bits (with its own error correction code), // Draws two copies of the version bits (with its own error correction code),
// based on this object's version field (which only has an effect for 7 <= version <= 40). // based on this object's version field, iff 7 <= version <= 40.
private void drawVersion() { private void drawVersion() {
if (version < 7) if (version < 7)
return; return;
@ -395,7 +396,8 @@ public final class QrCode {
} }
// Draws a 9*9 finder pattern including the border separator, with the center module at (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.
private void drawFinderPattern(int x, int y) { private void drawFinderPattern(int x, int y) {
for (int i = -4; i <= 4; i++) { for (int i = -4; i <= 4; i++) {
for (int j = -4; j <= 4; j++) { for (int j = -4; j <= 4; j++) {
@ -408,7 +410,8 @@ public final class QrCode {
} }
// Draws a 5*5 alignment pattern, with the center module at (x, y). // 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) { private void drawAlignmentPattern(int x, int y) {
for (int i = -2; i <= 2; i++) { for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) for (int j = -2; j <= 2; j++)
@ -418,7 +421,7 @@ public final class QrCode {
// Sets the color of a module and marks it as a function module. // Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in range. // Only used by the constructor. Coordinates must be in bounds.
private void setFunctionModule(int x, int y, boolean isBlack) { private void setFunctionModule(int x, int y, boolean isBlack) {
modules[y][x] = isBlack; modules[y][x] = isBlack;
isFunction[y][x] = true; isFunction[y][x] = true;

@ -188,6 +188,7 @@ var qrcodegen = new function() {
/*---- Private helper methods for constructor: Drawing function modules ----*/ /*---- Private helper methods for constructor: Drawing function modules ----*/
// Reads this object's version field, and draws and marks all function modules.
function drawFunctionPatterns() { function drawFunctionPatterns() {
// Draw horizontal and vertical timing patterns // Draw horizontal and vertical timing patterns
for (var i = 0; i < size; i++) { for (var i = 0; i < size; i++) {
@ -250,7 +251,7 @@ var qrcodegen = new function() {
// Draws two copies of the version bits (with its own error correction code), // Draws two copies of the version bits (with its own error correction code),
// based on this object's version field (which only has an effect for 7 <= version <= 40). // based on this object's version field, iff 7 <= version <= 40.
function drawVersion() { function drawVersion() {
if (version < 7) if (version < 7)
return; return;
@ -273,7 +274,8 @@ var qrcodegen = new function() {
} }
// Draws a 9*9 finder pattern including the border separator, with the center module at (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.
function drawFinderPattern(x, y) { function drawFinderPattern(x, y) {
for (var i = -4; i <= 4; i++) { for (var i = -4; i <= 4; i++) {
for (var j = -4; j <= 4; j++) { for (var j = -4; j <= 4; j++) {
@ -286,7 +288,8 @@ var qrcodegen = new function() {
} }
// Draws a 5*5 alignment pattern, with the center module at (x, y). // Draws a 5*5 alignment pattern, with the center module
// at (x, y). All modules must be in bounds.
function drawAlignmentPattern(x, y) { function drawAlignmentPattern(x, y) {
for (var i = -2; i <= 2; i++) { for (var i = -2; i <= 2; i++) {
for (var j = -2; j <= 2; j++) for (var j = -2; j <= 2; j++)
@ -296,7 +299,7 @@ var qrcodegen = new function() {
// Sets the color of a module and marks it as a function module. // Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in range. // Only used by the constructor. Coordinates must be in bounds.
function setFunctionModule(x, y, isBlack) { function setFunctionModule(x, y, isBlack) {
modules[y][x] = isBlack; modules[y][x] = isBlack;
isFunction[y][x] = true; isFunction[y][x] = true;

@ -241,6 +241,7 @@ class QrCode(object):
# ---- Private helper methods for constructor: Drawing function modules ---- # ---- Private helper methods for constructor: Drawing function modules ----
def _draw_function_patterns(self): def _draw_function_patterns(self):
"""Reads this object's version field, and draws and marks all function modules."""
# Draw horizontal and vertical timing patterns # Draw horizontal and vertical timing patterns
for i in range(self._size): for i in range(self._size):
self._set_function_module(6, i, i % 2 == 0) self._set_function_module(6, i, i % 2 == 0)
@ -296,7 +297,7 @@ class QrCode(object):
def _draw_version(self): def _draw_version(self):
"""Draws two copies of the version bits (with its own error correction code), """Draws two copies of the version bits (with its own error correction code),
based on this object's version field (which only has an effect for 7 <= version <= 40).""" based on this object's version field, iff 7 <= version <= 40."""
if self._version < 7: if self._version < 7:
return return
@ -316,7 +317,8 @@ class QrCode(object):
def _draw_finder_pattern(self, x, y): def _draw_finder_pattern(self, x, y):
"""Draws a 9*9 finder pattern including the border separator, with the center module at (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 i in range(-4, 5):
for j in range(-4, 5): for j in range(-4, 5):
xx, yy = x + j, y + i xx, yy = x + j, y + i
@ -326,7 +328,8 @@ class QrCode(object):
def _draw_alignment_pattern(self, x, y): def _draw_alignment_pattern(self, x, y):
"""Draws a 5*5 alignment pattern, with the center module at (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 i in range(-2, 3):
for j in range(-2, 3): for j in range(-2, 3):
self._set_function_module(x + j, y + i, max(abs(i), abs(j)) != 1) self._set_function_module(x + j, y + i, max(abs(i), abs(j)) != 1)
@ -334,7 +337,7 @@ class QrCode(object):
def _set_function_module(self, x, y, isblack): def _set_function_module(self, x, y, isblack):
"""Sets the color of a module and marks it as a function module. """Sets the color of a module and marks it as a function module.
Only used by the constructor. Coordinates must be in range.""" Only used by the constructor. Coordinates must be in bounds."""
assert type(isblack) is bool assert type(isblack) is bool
self._modules[y][x] = isblack self._modules[y][x] = isblack
self._isfunction[y][x] = True self._isfunction[y][x] = True

@ -269,6 +269,7 @@ impl QrCode {
/*---- Private helper methods for constructor: Drawing function modules ----*/ /*---- Private helper methods for constructor: Drawing function modules ----*/
// Reads this object's version field, and draws and marks all function modules.
fn draw_function_patterns(&mut self) { fn draw_function_patterns(&mut self) {
// Draw horizontal and vertical timing patterns // Draw horizontal and vertical timing patterns
let size: i32 = self.size; let size: i32 = self.size;
@ -339,7 +340,7 @@ impl QrCode {
// Draws two copies of the version bits (with its own error correction code), // Draws two copies of the version bits (with its own error correction code),
// based on this object's version field (which only has an effect for 7 <= version <= 40). // based on this object's version field, iff 7 <= version <= 40.
fn draw_version(&mut self) { fn draw_version(&mut self) {
if self.version.value() < 7 { if self.version.value() < 7 {
return; return;
@ -364,7 +365,8 @@ impl QrCode {
} }
// Draws a 9*9 finder pattern including the border separator, with the center module at (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.
fn draw_finder_pattern(&mut self, x: i32, y: i32) { fn draw_finder_pattern(&mut self, x: i32, y: i32) {
for i in -4 .. 5 { for i in -4 .. 5 {
for j in -4 .. 5 { for j in -4 .. 5 {
@ -379,7 +381,8 @@ impl QrCode {
} }
// Draws a 5*5 alignment pattern, with the center module at (x, y). // 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) { fn draw_alignment_pattern(&mut self, x: i32, y: i32) {
for i in -2 .. 3 { for i in -2 .. 3 {
for j in -2 .. 3 { for j in -2 .. 3 {
@ -390,7 +393,7 @@ impl QrCode {
// Sets the color of a module and marks it as a function module. // Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in range. // Only used by the constructor. Coordinates must be in bounds.
fn set_function_module(&mut self, x: i32, y: i32, isblack: bool) { fn set_function_module(&mut self, x: i32, y: i32, isblack: bool) {
*self.module_mut(x, y) = isblack; *self.module_mut(x, y) = isblack;
self.isfunction[(y * self.size + x) as usize] = true; self.isfunction[(y * self.size + x) as usize] = true;

@ -251,6 +251,7 @@ namespace qrcodegen {
/*-- Private helper methods for constructor: Drawing function modules --*/ /*-- Private helper methods for constructor: Drawing function modules --*/
// Reads this object's version field, and draws and marks all function modules.
private drawFunctionPatterns(): void { private drawFunctionPatterns(): void {
// Draw horizontal and vertical timing patterns // Draw horizontal and vertical timing patterns
for (let i = 0; i < this.size; i++) { for (let i = 0; i < this.size; i++) {
@ -313,7 +314,7 @@ namespace qrcodegen {
// Draws two copies of the version bits (with its own error correction code), // Draws two copies of the version bits (with its own error correction code),
// based on this object's version field (which only has an effect for 7 <= version <= 40). // based on this object's version field, iff 7 <= version <= 40.
private drawVersion(): void { private drawVersion(): void {
if (this.version < 7) if (this.version < 7)
return; return;
@ -337,7 +338,8 @@ namespace qrcodegen {
} }
// Draws a 9*9 finder pattern including the border separator, with the center module at (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.
private drawFinderPattern(x: int, y: int): void { private drawFinderPattern(x: int, y: int): void {
for (let i = -4; i <= 4; i++) { for (let i = -4; i <= 4; i++) {
for (let j = -4; j <= 4; j++) { for (let j = -4; j <= 4; j++) {
@ -351,7 +353,8 @@ namespace qrcodegen {
} }
// Draws a 5*5 alignment pattern, with the center module at (x, y). // 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 { private drawAlignmentPattern(x: int, y: int): void {
for (let i = -2; i <= 2; i++) { for (let i = -2; i <= 2; i++) {
for (let j = -2; j <= 2; j++) for (let j = -2; j <= 2; j++)
@ -361,7 +364,7 @@ namespace qrcodegen {
// Sets the color of a module and marks it as a function module. // Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in range. // Only used by the constructor. Coordinates must be in bounds.
private setFunctionModule(x: int, y: int, isBlack: boolean): void { private setFunctionModule(x: int, y: int, isBlack: boolean): void {
this.modules[y][x] = isBlack; this.modules[y][x] = isBlack;
this.isFunction[y][x] = true; this.isFunction[y][x] = true;

Loading…
Cancel
Save