Skip to content

Commit

Permalink
Change from int? to int
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed May 22, 2024
1 parent 2e9d24a commit 5c652f3
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions QRCoder/QRCodeGenerator.ModulePlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public static void PlaceFormat(QRCodeData qrCode, BitArray formatStr, bool offse
/// <returns>The index of the selected mask pattern.</returns>
public static int MaskCode(QRCodeData qrCode, int version, BlockedModules blockedModules, ECCLevel eccLevel)
{
int? selectedPattern = null;
var patternScore = 0;
int selectedPattern = -1; // no pattern selected yet
var patternScore = int.MaxValue; // lower score is better

var size = qrCode.ModuleMatrix.Count - 8;

Expand Down Expand Up @@ -165,15 +165,15 @@ public static int MaskCode(QRCodeData qrCode, int version, BlockedModules blocke
var score = MaskPattern.Score(qrTemp);

// Select the pattern with the lowest score, indicating better QR code readability.
if (!selectedPattern.HasValue || patternScore > score)
if (patternScore > score)
{
selectedPattern = maskPattern;
patternScore = score;
}
}

// Apply the best mask pattern to the actual QR code.
var selectedPatternFunc = MaskPattern.Patterns[selectedPattern.Value];
var selectedPatternFunc = MaskPattern.Patterns[selectedPattern];
for (var x = 0; x < size; x++)
{
for (var y = 0; y < x; y++)
Expand All @@ -191,7 +191,7 @@ public static int MaskCode(QRCodeData qrCode, int version, BlockedModules blocke
}
}

return selectedPattern.Value;
return selectedPattern;
}

/// <summary>
Expand Down

0 comments on commit 5c652f3

Please sign in to comment.