Simplified QrCode.toSvgString() loop ranges in all language versions except C.

pull/39/merge
Project Nayuki 6 years ago
parent 62930ef455
commit f3ba9c0837

@ -169,8 +169,8 @@ std::string QrCode::toSvgString(int border) const {
sb << "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
sb << "\t<path d=\"";
bool head = true;
for (int y = -border; y < size + border; y++) {
for (int x = -border; x < size + border; x++) {
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (getModule(x, y)) {
if (head)
head = false;

@ -292,8 +292,8 @@ public final class QrCode {
sb.append("\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n");
sb.append("\t<path d=\"");
boolean head = true;
for (int y = -border; y < size + border; y++) {
for (int x = -border; x < size + border; x++) {
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (getModule(x, y)) {
if (head)
head = false;

@ -170,8 +170,8 @@ var qrcodegen = new function() {
if (border < 0)
throw "Border must be non-negative";
var parts = [];
for (var y = -border; y < size + border; y++) {
for (var x = -border; x < size + border; x++) {
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if (this.getModule(x, y))
parts.push("M" + (x + border) + "," + (y + border) + "h1v1h-1z");
}

@ -225,8 +225,8 @@ class QrCode(object):
if border < 0:
raise ValueError("Border must be non-negative")
parts = []
for y in range(-border, self._size + border):
for x in range(-border, self._size + border):
for y in range(self._size):
for x in range(self._size):
if self.get_module(x, y):
parts.append("M{},{}h1v1h-1z".format(x + border, y + border))
return """<?xml version="1.0" encoding="UTF-8"?>

@ -249,8 +249,8 @@ impl QrCode {
result += "\t<rect width=\"100%\" height=\"100%\" fill=\"#FFFFFF\"/>\n";
result += "\t<path d=\"";
let mut head = true;
for y in -border .. self.size + border {
for x in -border .. self.size + border {
for y in 0 .. self.size {
for x in 0 .. self.size {
if self.get_module(x, y) {
if head {
head = false;

@ -233,8 +233,8 @@ namespace qrcodegen {
if (border < 0)
throw "Border must be non-negative";
let parts: Array<string> = [];
for (let y = -border; y < this.size + border; y++) {
for (let x = -border; x < this.size + border; x++) {
for (let y = 0; y < this.size; y++) {
for (let x = 0; x < this.size; x++) {
if (this.getModule(x, y))
parts.push(`M${x + border},${y + border}h1v1h-1z`);
}

Loading…
Cancel
Save