Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d237ca6

Browse files
authoredMay 6, 2024
Merge pull request #517 from Shane32/comments
Add code comments to QR code generation
2 parents e7a7eb2 + 66a4e27 commit d237ca6

15 files changed

+771
-89
lines changed
 

‎QRCoder/QRCodeGenerator.AlignmentPattern.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,21 @@ namespace QRCoder
44
{
55
public partial class QRCodeGenerator
66
{
7+
/// <summary>
8+
/// Represents the alignment pattern used in QR codes, which helps ensure the code remains readable even if it is somewhat distorted.
9+
/// Each QR code version has its own specific alignment pattern locations which this struct encapsulates.
10+
/// </summary>
711
private struct AlignmentPattern
812
{
13+
/// <summary>
14+
/// The version of the QR code. Higher versions have more complex and numerous alignment patterns.
15+
/// </summary>
916
public int Version;
17+
18+
/// <summary>
19+
/// A list of points where alignment patterns are located within the QR code matrix.
20+
/// Each point represents the center of an alignment pattern.
21+
/// </summary>
1022
public List<Point> PatternPositions;
1123
}
1224
}

‎QRCoder/QRCodeGenerator.CodewordBlock.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents a block of codewords in a QR code. QR codes are divided into several blocks for error correction purposes.
7+
/// Each block contains a series of data codewords followed by error correction codewords.
8+
/// </summary>
59
private struct CodewordBlock
610
{
11+
/// <summary>
12+
/// Initializes a new instance of the CodewordBlock struct with specified arrays of code words and error correction (ECC) words.
13+
/// </summary>
14+
/// <param name="codeWords">The array of data codewords for this block. Data codewords carry the actual information.</param>
15+
/// <param name="eccWords">The array of error correction codewords for this block. These codewords help recover the data if the QR code is damaged.</param>
716
public CodewordBlock(byte[] codeWords, byte[] eccWords)
817
{
918
this.CodeWords = codeWords;
1019
this.ECCWords = eccWords;
1120
}
1221

22+
/// <summary>
23+
/// Gets the data codewords associated with this block.
24+
/// </summary>
1325
public byte[] CodeWords { get; }
26+
27+
/// <summary>
28+
/// Gets the error correction codewords associated with this block.
29+
/// </summary>
1430
public byte[] ECCWords { get; }
1531
}
1632
}

‎QRCoder/QRCodeGenerator.ECCInfo.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents the error correction coding (ECC) information for a specific version and error correction level of a QR code.
7+
/// </summary>
58
private struct ECCInfo
69
{
10+
/// <summary>
11+
/// Initializes a new instance of the ECCInfo struct with specified properties.
12+
/// </summary>
13+
/// <param name="version">The version number of the QR code.</param>
14+
/// <param name="errorCorrectionLevel">The error correction level used in the QR code.</param>
15+
/// <param name="totalDataCodewords">The total number of data codewords for this version and error correction level.</param>
16+
/// <param name="eccPerBlock">The number of error correction codewords per block.</param>
17+
/// <param name="blocksInGroup1">The number of blocks in group 1.</param>
18+
/// <param name="codewordsInGroup1">The number of codewords in each block of group 1.</param>
19+
/// <param name="blocksInGroup2">The number of blocks in group 2, if any.</param>
20+
/// <param name="codewordsInGroup2">The number of codewords in each block of group 2, if any.</param>
721
public ECCInfo(int version, ECCLevel errorCorrectionLevel, int totalDataCodewords, int eccPerBlock, int blocksInGroup1,
822
int codewordsInGroup1, int blocksInGroup2, int codewordsInGroup2)
923
{
@@ -16,13 +30,45 @@ public ECCInfo(int version, ECCLevel errorCorrectionLevel, int totalDataCodeword
1630
this.BlocksInGroup2 = blocksInGroup2;
1731
this.CodewordsInGroup2 = codewordsInGroup2;
1832
}
33+
34+
/// <summary>
35+
/// Gets the version number of the QR code.
36+
/// </summary>
1937
public int Version { get; }
38+
39+
/// <summary>
40+
/// Gets the error correction level of the QR code.
41+
/// </summary>
2042
public ECCLevel ErrorCorrectionLevel { get; }
43+
44+
/// <summary>
45+
/// Gets the total number of data codewords for this version and error correction level.
46+
/// </summary>
2147
public int TotalDataCodewords { get; }
48+
49+
/// <summary>
50+
/// Gets the number of error correction codewords per block.
51+
/// </summary>
2252
public int ECCPerBlock { get; }
53+
54+
/// <summary>
55+
/// Gets the number of blocks in group 1.
56+
/// </summary>
2357
public int BlocksInGroup1 { get; }
58+
59+
/// <summary>
60+
/// Gets the number of codewords in each block of group 1.
61+
/// </summary>
2462
public int CodewordsInGroup1 { get; }
63+
64+
/// <summary>
65+
/// Gets the number of blocks in group 2, if any.
66+
/// </summary>
2567
public int BlocksInGroup2 { get; }
68+
69+
/// <summary>
70+
/// Gets the number of codewords in each block of group 2, if any.
71+
/// </summary>
2672
public int CodewordsInGroup2 { get; }
2773
}
2874
}

‎QRCoder/QRCodeGenerator.ECCLevel.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@
33
public partial class QRCodeGenerator
44
{
55
/// <summary>
6-
/// Error correction level. These define the tolerance levels for how much of the code can be lost before the code cannot be recovered.
6+
/// Defines the levels of error correction available in QR codes.
7+
/// Each level specifies the proportion of data that can be recovered if the QR code is partially obscured or damaged.
78
/// </summary>
89
public enum ECCLevel
910
{
1011
/// <summary>
11-
/// 7% may be lost before recovery is not possible
12+
/// Level L: Low error correction (approximately 7% of data can be recovered).
13+
/// This level allows the highest data density.
1214
/// </summary>
1315
L,
16+
1417
/// <summary>
15-
/// 15% may be lost before recovery is not possible
18+
/// Level M: Medium error correction (approximately 15% of data can be recovered).
19+
/// Offers a balance between data capacity and error recovery.
1620
/// </summary>
1721
M,
22+
1823
/// <summary>
19-
/// 25% may be lost before recovery is not possible
24+
/// Level Q: Quartile error correction (approximately 25% of data can be recovered).
25+
/// More robust error correction at the cost of reduced data capacity.
2026
/// </summary>
2127
Q,
28+
2229
/// <summary>
23-
/// 30% may be lost before recovery is not possible
30+
/// Level H: High error correction (approximately 30% of data can be recovered).
31+
/// Provides the highest level of error recovery, ideal for environments with high risk of data loss.
2432
/// </summary>
2533
H
2634
}

‎QRCoder/QRCodeGenerator.EciMode.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,34 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Enumerates the Extended Channel Interpretation (ECI) modes used in QR codes to handle different character encoding standards.
7+
/// ECI mode allows QR codes to efficiently encode data using character sets other than the default ISO-8859-1.
8+
/// </summary>
59
public enum EciMode
610
{
11+
/// <summary>
12+
/// Default encoding mode (typically ISO-8859-1). Used when no ECI mode is explicitly specified.
13+
/// This mode is assumed in basic QR codes where no extended character sets are needed.
14+
/// </summary>
715
Default = 0,
16+
17+
/// <summary>
18+
/// Specifies the use of the ISO-8859-1 character set, covering most Western European languages.
19+
/// This mode explicitly sets the encoding to ISO-8859-1, which includes characters used in languages such as English, French, German, and Spanish.
20+
/// </summary>
821
Iso8859_1 = 3,
22+
23+
/// <summary>
24+
/// Specifies the use of the ISO-8859-2 character set, which is primarily used for Central and Eastern European languages.
25+
/// This includes characters used in languages such as Polish, Czech, Slovak, Hungarian, and Romanian.
26+
/// </summary>
927
Iso8859_2 = 4,
28+
29+
/// <summary>
30+
/// Specifies the use of UTF-8 encoding.
31+
/// UTF-8 can encode any Unicode character and is useful for QR codes that need to support multi-language content.
32+
/// </summary>
1033
Utf8 = 26
1134
}
1235
}

‎QRCoder/QRCodeGenerator.EncodingMode.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
1-
namespace QRCoder
1+
using System;
2+
3+
namespace QRCoder
24
{
35
public partial class QRCodeGenerator
46
{
7+
/// <summary>
8+
/// Specifies the encoding modes for the characters in a QR code.
9+
/// </summary>
510
private enum EncodingMode
611
{
12+
/// <summary>
13+
/// Numeric encoding mode, which is used to encode numeric data (digits 0-9).
14+
/// Three characters are encoded into 10 bits.
15+
/// </summary>
716
Numeric = 1,
17+
18+
/// <summary>
19+
/// Alphanumeric encoding mode, which is used to encode alphanumeric characters (0-9, A-Z, space, and some punctuation).
20+
/// Two characters are encoded into 11 bits.
21+
/// </summary>
822
Alphanumeric = 2,
23+
24+
/// <summary>
25+
/// Byte encoding mode, primarily using the ISO-8859-1 character set. Each character is encoded into 8 bits.
26+
/// When combined with ECI, it can be adapted to use other character sets.
27+
/// </summary>
928
Byte = 4,
29+
30+
/// <summary>
31+
/// Kanji encoding mode, which is used to encode characters from the Shift JIS character set, primarily for Japanese Kanji and Kana characters.
32+
/// One character is encoded into 13 bits. This mode is not currently supported by QRCoder.
33+
/// </summary>
1034
Kanji = 8,
35+
36+
/// <summary>
37+
/// Extended Channel Interpretation (ECI) mode, which specifies a character set via an 8-bit number followed by one of the other encoding modes.
38+
/// This allows adapting the byte encoding to accommodate various global text encodings.
39+
/// </summary>
1140
ECI = 7
1241
}
1342
}

‎QRCoder/QRCodeGenerator.ModulePlacer.MaskPattern.cs

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34

45
namespace QRCoder
@@ -7,63 +8,109 @@ public partial class QRCodeGenerator
78
{
89
private static partial class ModulePlacer
910
{
11+
/// <summary>
12+
/// Provides static methods and properties to handle mask patterns used in QR code generation.
13+
/// Mask patterns are applied to QR codes to break up patterns in the data matrix that might confuse scanners.
14+
/// </summary>
1015
private static class MaskPattern
1116
{
17+
/// <summary>
18+
/// A dictionary mapping each mask pattern index to its corresponding function that calculates whether a given pixel should be masked.
19+
/// </summary>
1220
public static readonly Dictionary<int, Func<int, int, bool>> Patterns =
1321
new Dictionary<int, Func<int, int, bool>>(8) {
1422
{ 1, MaskPattern.Pattern1 }, {2, MaskPattern.Pattern2 }, {3, MaskPattern.Pattern3 }, {4, MaskPattern.Pattern4 },
1523
{ 5, MaskPattern.Pattern5 }, {6, MaskPattern.Pattern6 }, {7, MaskPattern.Pattern7 }, {8, MaskPattern.Pattern8 }
1624
};
1725

26+
/// <summary>
27+
/// Mask pattern 1: (x + y) % 2 == 0
28+
/// Applies a checkerboard mask on the QR code.
29+
/// </summary>
1830
public static bool Pattern1(int x, int y)
1931
{
2032
return (x + y) % 2 == 0;
2133
}
2234

35+
/// <summary>
36+
/// Mask pattern 2: y % 2 == 0
37+
/// Applies a horizontal striping mask on the QR code.
38+
/// </summary>
2339
public static bool Pattern2(int x, int y)
2440
{
2541
return y % 2 == 0;
2642
}
2743

44+
/// <summary>
45+
/// Mask pattern 3: x % 3 == 0
46+
/// Applies a vertical striping mask on the QR code.
47+
/// </summary>
2848
public static bool Pattern3(int x, int y)
2949
{
3050
return x % 3 == 0;
3151
}
3252

53+
/// <summary>
54+
/// Mask pattern 4: (x + y) % 3 == 0
55+
/// Applies a diagonal striping mask on the QR code.
56+
/// </summary>
3357
public static bool Pattern4(int x, int y)
3458
{
3559
return (x + y) % 3 == 0;
3660
}
3761

62+
/// <summary>
63+
/// Mask pattern 5: ((y / 2) + (x / 3)) % 2 == 0
64+
/// Applies a complex pattern mask on the QR code, mixing horizontal and vertical rules.
65+
/// </summary>
3866
public static bool Pattern5(int x, int y)
3967
{
4068
return ((int)(Math.Floor(y / 2d) + Math.Floor(x / 3d)) % 2) == 0;
4169
}
4270

71+
/// <summary>
72+
/// Mask pattern 6: ((x * y) % 2 + (x * y) % 3) == 0
73+
/// Applies a mask based on the product of x and y coordinates modulo 2 and 3.
74+
/// </summary>
4375
public static bool Pattern6(int x, int y)
4476
{
4577
return ((x * y) % 2) + ((x * y) % 3) == 0;
4678
}
4779

80+
/// <summary>
81+
/// Mask pattern 7: (((x * y) % 2 + (x * y) % 3) % 2) == 0
82+
/// Applies a mask based on a more complex function involving the product of x and y coordinates.
83+
/// </summary>
4884
public static bool Pattern7(int x, int y)
4985
{
5086
return (((x * y) % 2) + ((x * y) % 3)) % 2 == 0;
5187
}
5288

89+
/// <summary>
90+
/// Mask pattern 8: (((x + y) % 2) + ((x * y) % 3) % 2) == 0
91+
/// Combines rules of checkers and complex multiplicative masks.
92+
/// </summary>
5393
public static bool Pattern8(int x, int y)
5494
{
5595
return (((x + y) % 2) + ((x * y) % 3)) % 2 == 0;
5696
}
5797

98+
/// <summary>
99+
/// Calculates a penalty score for a QR code to evaluate the effectiveness of a mask pattern.
100+
/// A lower score indicates a QR code that is easier for decoders to read accurately.
101+
/// The score is the sum of four penalty rules applied to the QR code.
102+
/// </summary>
103+
/// <param name="qrCode">The QR code data structure to be evaluated.</param>
104+
/// <returns>The total penalty score of the QR code.</returns>
58105
public static int Score(QRCodeData qrCode)
59106
{
60-
int score1 = 0,
61-
score2 = 0,
62-
score3 = 0,
63-
score4 = 0;
107+
int score1 = 0, // Penalty for groups of five or more same-color modules in a row (or column)
108+
score2 = 0, // Penalty for blocks of modules in the same color
109+
score3 = 0, // Penalty for specific patterns found within the QR code
110+
score4 = 0; // Penalty for having more than 50% black modules or more than 50% white modules
64111
var size = qrCode.ModuleMatrix.Count;
65112

66-
//Penalty 1
113+
//Penalty 1: Checking for consecutive modules of the same color in rows and columns
67114
for (var y = 0; y < size; y++)
68115
{
69116
var modInRow = 0;
@@ -72,6 +119,7 @@ public static int Score(QRCodeData qrCode)
72119
var lastValColumn = qrCode.ModuleMatrix[0][y];
73120
for (var x = 0; x < size; x++)
74121
{
122+
// Check rows for consecutive modules
75123
if (qrCode.ModuleMatrix[y][x] == lastValRow)
76124
modInRow++;
77125
else
@@ -82,7 +130,7 @@ public static int Score(QRCodeData qrCode)
82130
score1++;
83131
lastValRow = qrCode.ModuleMatrix[y][x];
84132

85-
133+
// Check columns for consecutive modules
86134
if (qrCode.ModuleMatrix[x][y] == lastValColumn)
87135
modInColumn++;
88136
else
@@ -95,8 +143,7 @@ public static int Score(QRCodeData qrCode)
95143
}
96144
}
97145

98-
99-
//Penalty 2
146+
//Penalty 2: Checking for blocks of modules in the same color
100147
for (var y = 0; y < size - 1; y++)
101148
{
102149
for (var x = 0; x < size - 1; x++)
@@ -108,11 +155,12 @@ public static int Score(QRCodeData qrCode)
108155
}
109156
}
110157

111-
//Penalty 3
158+
//Penalty 3: Checking for specific patterns within the QR code (patterns that should be avoided)
112159
for (var y = 0; y < size; y++)
113160
{
114161
for (var x = 0; x < size - 10; x++)
115162
{
163+
// Horizontal pattern matching
116164
if ((qrCode.ModuleMatrix[y][x] &&
117165
!qrCode.ModuleMatrix[y][x + 1] &&
118166
qrCode.ModuleMatrix[y][x + 2] &&
@@ -139,6 +187,7 @@ public static int Score(QRCodeData qrCode)
139187
score3 += 40;
140188
}
141189

190+
// Vertical pattern matching
142191
if ((qrCode.ModuleMatrix[x][y] &&
143192
!qrCode.ModuleMatrix[x + 1][y] &&
144193
qrCode.ModuleMatrix[x + 2][y] &&
@@ -167,7 +216,7 @@ public static int Score(QRCodeData qrCode)
167216
}
168217
}
169218

170-
//Penalty 4
219+
//Penalty 4: Proportions of dark and light modules
171220
int blackModules = 0;
172221
foreach (var bitArray in qrCode.ModuleMatrix)
173222
for (var x = 0; x < size; x++)
@@ -179,6 +228,7 @@ public static int Score(QRCodeData qrCode)
179228
var nextMultipleOf5 = Math.Abs(percentDiv5 - 9);
180229
score4 = Math.Min(prevMultipleOf5, nextMultipleOf5) * 10;
181230

231+
// Return the sum of all four penalties
182232
return (score1 + score2) + (score3 + score4);
183233
}
184234
}

‎QRCoder/QRCodeGenerator.ModulePlacer.cs

Lines changed: 162 additions & 35 deletions
Large diffs are not rendered by default.

‎QRCoder/QRCodeGenerator.Point.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,50 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
24

35
namespace QRCoder
46
{
57
public partial class QRCodeGenerator
68
{
9+
/// <summary>
10+
/// Represents a 2D point with integer coordinates.
11+
/// </summary>
712
private readonly struct Point : IEquatable<Point>
813
{
14+
/// <summary>
15+
/// Gets the X-coordinate of the point.
16+
/// </summary>
917
public int X { get; }
18+
19+
/// <summary>
20+
/// Gets the Y-coordinate of the point.
21+
/// </summary>
1022
public int Y { get; }
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="Point"/> struct with specified X and Y coordinates.
26+
/// </summary>
27+
/// <param name="x">The X-coordinate of the point.</param>
28+
/// <param name="y">The Y-coordinate of the point.</param>
1129
public Point(int x, int y)
1230
{
1331
this.X = x;
1432
this.Y = y;
1533
}
1634

35+
/// <summary>
36+
/// Determines whether the specified <see cref="Point"/> is equal to the current <see cref="Point"/>.
37+
/// </summary>
38+
/// <param name="other">The <see cref="Point"/> to compare with the current <see cref="Point"/>.</param>
39+
/// <returns>True if the specified <see cref="Point"/> has the same X and Y coordinates as the current <see cref="Point"/>; otherwise, false.</returns>
40+
/// <remarks>
41+
/// If this method which implements <see cref="IEquatable{T}.Equals(T)"/> is not implemented, comparisons used by methods such as <see cref="List{T}.Contains(T)"/>
42+
/// fall back to reflection, which causes heap allocations internally during the calls to <see cref="FieldInfo.GetValue(object)"/>.
43+
/// </remarks>
1744
public bool Equals(Point other)
1845
{
1946
return this.X == other.X && this.Y == other.Y;
2047
}
21-
2248
}
2349
}
2450
}

‎QRCoder/QRCodeGenerator.Polynom.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ namespace QRCoder
55
{
66
public partial class QRCodeGenerator
77
{
8+
/// <summary>
9+
/// Represents a polynomial, which is a sum of polynomial terms.
10+
/// </summary>
811
private struct Polynom
912
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="Polynom"/> struct with a specified number of initial capacity for polynomial terms.
15+
/// </summary>
16+
/// <param name="count">The initial capacity of the polynomial items list.</param>
1017
public Polynom(int count)
1118
{
1219
this.PolyItems = new List<PolynomItem>(count);
1320
}
1421

22+
/// <summary>
23+
/// Gets or sets the list of polynomial items, where each item represents a term in the polynomial.
24+
/// </summary>
1525
public List<PolynomItem> PolyItems { get; set; }
1626

27+
/// <summary>
28+
/// Returns a string that represents the polynomial in standard algebraic notation.
29+
/// Example output: "a^2*x^3 + a^5*x^1 + a^3*x^0", which represents the polynomial 2x³ + 5x + 3.
30+
/// </summary>
1731
public override string ToString()
1832
{
1933
var sb = new StringBuilder();
@@ -23,6 +37,7 @@ public override string ToString()
2337
sb.Append("a^" + polyItem.Coefficient + "*x^" + polyItem.Exponent + " + ");
2438
}
2539

40+
// Remove the trailing " + " if the string builder has added terms
2641
if (sb.Length > 0)
2742
sb.Length -= 3;
2843

‎QRCoder/QRCodeGenerator.PolynomItem.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,31 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents an individual term of a polynomial, consisting of a coefficient and an exponent.
7+
/// For example, the term 3x² would be represented as a <see cref="PolynomItem"/> with a coefficient of 3 and an exponent of 2.
8+
/// </summary>
59
private struct PolynomItem
610
{
11+
/// <summary>
12+
/// Initializes a new instance of the <see cref="PolynomItem"/> struct with the specified coefficient and exponent.
13+
/// </summary>
14+
/// <param name="coefficient">The coefficient of the polynomial term. For example, in the term 3x², the coefficient is 3.</param>
15+
/// <param name="exponent">The exponent of the polynomial term. For example, in the term 3x², the exponent is 2.</param>
716
public PolynomItem(int coefficient, int exponent)
817
{
918
this.Coefficient = coefficient;
1019
this.Exponent = exponent;
1120
}
1221

22+
/// <summary>
23+
/// Gets the coefficient of the polynomial term.
24+
/// </summary>
1325
public int Coefficient { get; }
26+
27+
/// <summary>
28+
/// Gets the exponent of the polynomial term.
29+
/// </summary>
1430
public int Exponent { get; }
1531
}
1632
}

‎QRCoder/QRCodeGenerator.Rectangle.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,38 @@
22
{
33
public partial class QRCodeGenerator
44
{
5+
/// <summary>
6+
/// Represents a rectangle defined by its top-left corner's coordinates, width, and height.
7+
/// </summary>
58
private readonly struct Rectangle
69
{
10+
/// <summary>
11+
/// Gets the X-coordinate of the top-left corner of the rectangle.
12+
/// </summary>
713
public int X { get; }
14+
15+
/// <summary>
16+
/// Gets the Y-coordinate of the top-left corner of the rectangle.
17+
/// </summary>
818
public int Y { get; }
19+
20+
/// <summary>
21+
/// Gets the width of the rectangle.
22+
/// </summary>
923
public int Width { get; }
24+
25+
/// <summary>
26+
/// Gets the height of the rectangle.
27+
/// </summary>
1028
public int Height { get; }
1129

30+
/// <summary>
31+
/// Initializes a new instance of the <see cref="Rectangle"/> struct with the specified top-left corner coordinates, width, and height.
32+
/// </summary>
33+
/// <param name="x">The X-coordinate of the top-left corner of the rectangle.</param>
34+
/// <param name="y">The Y-coordinate of the top-left corner of the rectangle.</param>
35+
/// <param name="w">The width of the rectangle.</param>
36+
/// <param name="h">The height of the rectangle.</param>
1237
public Rectangle(int x, int y, int w, int h)
1338
{
1439
this.X = x;

‎QRCoder/QRCodeGenerator.VersionInfo.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@ namespace QRCoder
44
{
55
public partial class QRCodeGenerator
66
{
7+
/// <summary>
8+
/// Represents version-specific information of a QR code.
9+
/// </summary>
710
private struct VersionInfo
811
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="VersionInfo"/> struct with a specific version number and its details.
14+
/// </summary>
15+
/// <param name="version">The version number of the QR code. Each version has a different module configuration.</param>
16+
/// <param name="versionInfoDetails">A list of detailed information related to error correction levels and capacity for each encoding mode.</param>
917
public VersionInfo(int version, List<VersionInfoDetails> versionInfoDetails)
1018
{
1119
this.Version = version;
1220
this.Details = versionInfoDetails;
1321
}
22+
23+
/// <summary>
24+
/// Gets the version number of the QR code. Each version number specifies a different size of the QR matrix.
25+
/// </summary>
1426
public int Version { get; }
27+
28+
/// <summary>
29+
/// Gets a list of details about the QR code version, including the error correction levels and encoding capacities.
30+
/// </summary>
1531
public List<VersionInfoDetails> Details { get; }
1632
}
1733
}

‎QRCoder/QRCodeGenerator.VersionInfoDetails.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@ namespace QRCoder
44
{
55
public partial class QRCodeGenerator
66
{
7+
/// <summary>
8+
/// Represents the detailed information about each error correction level and its corresponding capacities in different encoding modes for a specific version of a QR code.
9+
/// </summary>
710
private struct VersionInfoDetails
811
{
12+
/// <summary>
13+
/// Initializes a new instance of the <see cref="VersionInfoDetails"/> struct, detailing the error correction level and the capacity for each encoding mode.
14+
/// </summary>
15+
/// <param name="errorCorrectionLevel">The error correction level, which determines how much of the code can be restored if the QR code gets damaged.</param>
16+
/// <param name="capacityDict">A dictionary mapping each encoding mode to its capacity for the specific error correction level.</param>
917
public VersionInfoDetails(ECCLevel errorCorrectionLevel, Dictionary<EncodingMode, int> capacityDict)
1018
{
1119
this.ErrorCorrectionLevel = errorCorrectionLevel;
1220
this.CapacityDict = capacityDict;
1321
}
1422

23+
/// <summary>
24+
/// Gets the error correction level of the QR code, influencing how robust the QR code is against errors and damage.
25+
/// </summary>
1526
public ECCLevel ErrorCorrectionLevel { get; }
27+
28+
/// <summary>
29+
/// Gets a dictionary that contains the capacities of different encoding modes under the specified error correction level.
30+
/// These capacities dictate how many characters can be encoded under each mode.
31+
/// </summary>
1632
public Dictionary<EncodingMode, int> CapacityDict { get; }
1733
}
1834
}

‎QRCoder/QRCodeGenerator.cs

Lines changed: 294 additions & 37 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.