codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.43k stars 1.08k forks source link

Change MaskPattern.Patterns to a list #531

Closed Shane32 closed 1 month ago

Shane32 commented 1 month ago

This code changes MaskPattern.Patterns to a list instead of a dictionary to hopefully make some code easier to understand.

Existing code

The index is stored zero-based within the QR code, and I was confused by this code here:

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L130

followed by

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L163

and

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L175-L176

which is actually correct because of

https://github.com/codebude/QRCoder/blob/14a83f2e1c2d946e54db72cd91f3e420630e1f71/QRCoder/QRCodeGenerator.ModulePlacer.cs#L185

So since the dictionary is unnecessary, I converted it to a list. It should be faster too but I didn't check.

New code

Now we start with this:

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L118-L120

and uses are simple:

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L132

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L165

https://github.com/codebude/QRCoder/blob/d48a2fb2d2b95fce2cdd35dfacdff68544e60c61/QRCoder/QRCodeGenerator.ModulePlacer.cs#L187

Shane32 commented 1 month ago

I'll need to fix conflicts here

codebude commented 1 month ago

Can you also have a look on the merge conflicts? image