Skip to content

Commit 779a0fb

Browse files
committed
Resolve name ambiguity
1 parent 9a9d013 commit 779a0fb

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

CONTEXT.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The union of all fixed-pattern footprints — every module the payload must not
2626

2727
**Payload-area map**:
2828
The complement of the reserved modules: the modules the payload zig-zag is allowed
29-
to fill. This is what `GetDataMask` returns.
29+
to fill. This is what `GetPayloadAreaMap` returns.
3030
_Avoid_: "data mask" — see Flagged ambiguities.
3131

3232
**Mask pattern**:
@@ -52,11 +52,3 @@ lowest penalty score. Exposed as `QrCode.Mask`.
5252
> emits both: it stamps the dark **modules** and reserves the **footprint** in the same
5353
> place. You can't infer reserved from drawn, because a footprint reserves light modules
5454
> too."
55-
56-
## Flagged ambiguities
57-
58-
- **"data mask"** was used for two distinct things: (1) the **payload-area map**
59-
returned by `GetDataMask` / `DataMaskCache`, and (2) a **mask pattern** (the 8 XOR
60-
patterns), as in `GetDataMaskPattern`. Resolved: prefer **payload-area map** for (1)
61-
and **mask pattern** for (2). The existing `GetDataMask` method name is retained for
62-
compatibility but denotes the payload-area map.

QrCodeGenerator/FixedPatterns.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ internal static class FixedPatterns
4242
// inverted reserved mask (the modules the payload zig-zag may fill). Both are
4343
// computed by a single BuildFixedPatterns walk and cached together.
4444
// The cached instances are shared and must not be mutated (CreateWithFixedPatterns
45-
// hands out a Copy; GetDataMask's result is treated as read-only by callers).
46-
private static readonly ConcurrentDictionary<int, (BitMatrix Drawn, BitMatrix DataMask)> Cache
45+
// hands out a Copy; GetPayloadAreaMap's result is treated as read-only by callers).
46+
private static readonly ConcurrentDictionary<int, (BitMatrix Drawn, BitMatrix PayloadAreaMap)> Cache
4747
= new ConcurrentDictionary<int, (BitMatrix, BitMatrix)>();
4848

49-
private static (BitMatrix Drawn, BitMatrix DataMask) GetCached(int version)
49+
private static (BitMatrix Drawn, BitMatrix PayloadAreaMap) GetCached(int version)
5050
{
5151
return Cache.GetOrAdd(version, ComputeCached);
5252
}
5353

54-
private static (BitMatrix Drawn, BitMatrix DataMask) ComputeCached(int version)
54+
private static (BitMatrix Drawn, BitMatrix PayloadAreaMap) ComputeCached(int version)
5555
{
5656
var (drawn, reserved) = BuildFixedPatterns(version);
5757
// Turn the reserved mask into the payload-area map (where data goes).
@@ -84,9 +84,9 @@ internal static BitMatrix CreateWithFixedPatterns(int version)
8484
/// </summary>
8585
/// <param name="version">The QR code version.</param>
8686
/// <returns>A shared <see cref="BitMatrix"/> instance.</returns>
87-
internal static BitMatrix GetDataMask(int version)
87+
internal static BitMatrix GetPayloadAreaMap(int version)
8888
{
89-
return GetCached(version).DataMask;
89+
return GetCached(version).PayloadAreaMap;
9090
}
9191

9292
#endregion

QrCodeGenerator/QrCodeBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private static void SetFormatBit(BitMatrix modules, BitMatrix transposed, int x,
296296
[SuppressMessage("csharpsquid", "S127")]
297297
internal static void FillPayload(BitMatrix modules, byte[] codewords, int version)
298298
{
299-
var dataMask = FixedPatterns.GetDataMask(version);
299+
var payloadArea = FixedPatterns.GetPayloadAreaMap(version);
300300

301301
// zigzag up and down with a 2-wide stride, starting in the right bottom corner
302302
var size = modules.Size;
@@ -322,7 +322,7 @@ internal static void FillPayload(BitMatrix modules, byte[] codewords, int versio
322322
// alternate between the 2 columns
323323
for (var x = h; x > h - 2; x -= 1)
324324
{
325-
if (!dataMask.Get(x, y))
325+
if (!payloadArea.Get(x, y))
326326
{
327327
// skip modules not intended for payload
328328
continue;
@@ -358,7 +358,7 @@ private static BitMatrix GetDataMaskPattern(int patternIndex, int version)
358358
private static BitMatrix CreateDataMaskPattern((int patternIndex, int version) key)
359359
{
360360
var pattern = CreatePattern(key.patternIndex, key.version);
361-
pattern.And(FixedPatterns.GetDataMask(key.version));
361+
pattern.And(FixedPatterns.GetPayloadAreaMap(key.version));
362362
return pattern;
363363
}
364364

QrCodeGeneratorTest/QrCodeBuilderTest.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,15 @@ public void FillPayload([CombinatorialRange(1, 40)] int version)
176176
}
177177

178178
var modules = FixedPatterns.CreateWithFixedPatterns(version);
179-
var dataMask = FixedPatterns.GetDataMask(version);
179+
var payloadArea = FixedPatterns.GetPayloadAreaMap(version);
180180
var size = modules.Size;
181-
Assert.Equal(0, CountDarkDataModules(modules, dataMask));
181+
Assert.Equal(0, CountDarkDataModules(modules, payloadArea));
182182

183183
QrCodeBuilder.FillPayload(modules, codewords, version);
184184

185-
var darkModules = CountDarkDataModules(modules, dataMask);
185+
var darkModules = CountDarkDataModules(modules, payloadArea);
186186
Assert.Equal(codewords.Length * 8, darkModules);
187-
var lightModules = CountLightDataModules(modules, dataMask);
187+
var lightModules = CountLightDataModules(modules, payloadArea);
188188
Assert.InRange(lightModules, 0, 7);
189189

190190
// assert that all light modules are near the bottom left corner
@@ -196,7 +196,7 @@ public void FillPayload([CombinatorialRange(1, 40)] int version)
196196
{
197197
for (var y = size - 12 - versionInfoOffset; y < size - 8 - versionInfoOffset; y += 1)
198198
{
199-
if (!modules.Get(x, y) && dataMask.Get(x, y))
199+
if (!modules.Get(x, y) && payloadArea.Get(x, y))
200200
{
201201
count += 1;
202202
}
@@ -321,15 +321,15 @@ private static void AssertMirrored(BitMatrix matrix)
321321
}
322322
}
323323

324-
private static int CountDarkDataModules(BitMatrix modules, BitMatrix dataMask)
324+
private static int CountDarkDataModules(BitMatrix modules, BitMatrix payloadArea)
325325
{
326326
var sum = 0;
327327
var size = modules.Size;
328328
for (var x = 0; x < size; x += 1)
329329
{
330330
for (var y = 0; y < size; y += 1)
331331
{
332-
if (modules.Get(x, y) && dataMask.Get(x, y))
332+
if (modules.Get(x, y) && payloadArea.Get(x, y))
333333
{
334334
sum += 1;
335335
}
@@ -338,15 +338,15 @@ private static int CountDarkDataModules(BitMatrix modules, BitMatrix dataMask)
338338
return sum;
339339
}
340340

341-
private static int CountLightDataModules(BitMatrix modules, BitMatrix dataMask)
341+
private static int CountLightDataModules(BitMatrix modules, BitMatrix payloadArea)
342342
{
343343
var sum = 0;
344344
var size = modules.Size;
345345
for (var x = 0; x < size; x += 1)
346346
{
347347
for (var y = 0; y < size; y += 1)
348348
{
349-
if (!modules.Get(x, y) && dataMask.Get(x, y))
349+
if (!modules.Get(x, y) && payloadArea.Get(x, y))
350350
{
351351
sum += 1;
352352
}

0 commit comments

Comments
 (0)