private static void maybeEmbedPositionAdjustmentPatterns(Version version, ByteMatrix matrix)
{
if (version.VersionNumber < 2)
{
// The patterns appear if version >= 2
return;
}
int index = version.VersionNumber - 1;
int[] coordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index];
int numCoordinates = POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index].Length;
for (int i = 0; i < numCoordinates; ++i)
{
for (int j = 0; j < numCoordinates; ++j)
{
int y = coordinates[i];
int x = coordinates[j];
if (x == -1 || y == -1)
{
continue;
}
// If the cell is unset, we embed the position adjustment pattern here.
if (isEmpty(matrix[x, y]))
{
// -2 is necessary since the x/y coordinates point to the center of the pattern, not the
// left top corner.
embedPositionAdjustmentPattern(x - 2, y - 2, matrix);
}
}
}
}