Skip to content

Commit 068c97c

Browse files
committed
Only rectangles outside finder
1 parent 1a253ef commit 068c97c

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

QrCodeAnalyzer/Penalty.cs

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

34
namespace Net.Codecrete.QrCodeGenerator.Analyzer
45
{
@@ -22,7 +23,7 @@ internal static List<Rectangle> GetBlocks(QrCode qr)
2223
}
2324
}
2425

25-
return rectangles;
26+
return FilterOutsideFinderArea(rectangles, qr.Size);
2627
}
2728

2829
internal static List<Rectangle> GetHorizontalStreaks(QrCode qr)
@@ -54,7 +55,8 @@ internal static List<Rectangle> GetHorizontalStreaks(QrCode qr)
5455
rectangles.Add(new Rectangle(size - count, y, count, 1));
5556
}
5657
}
57-
return rectangles;
58+
59+
return FilterOutsideFinderArea(rectangles, qr.Size);
5860
}
5961

6062

@@ -87,7 +89,19 @@ internal static List<Rectangle> GetVerticalStreaks(QrCode qr)
8789
rectangles.Add(new Rectangle(x, size - count, 1, count));
8890
}
8991
}
90-
return rectangles;
92+
return FilterOutsideFinderArea(rectangles, qr.Size);
93+
}
94+
95+
private static List<Rectangle> FilterOutsideFinderArea(List<Rectangle> rectangles, int size)
96+
{
97+
return [.. rectangles.Where(r => !IsInFinderArea(r.X, r.Y, r.Width, r.Height, size))];
98+
}
99+
100+
private static bool IsInFinderArea(int x, int y, int w, int h, int size)
101+
{
102+
return (x >= 0 && y >= 0 && x + w <= 8 && y + h <= 8)
103+
|| (x >= size - 8 && y >= 0 && x + w <= size && y + h <= 8)
104+
|| (x >= 0 && y >= size - 8 && x + w <= 8 && y + h <= size);
91105
}
92106
}
93107
}

0 commit comments

Comments
 (0)