Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/qr_code/matrix_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ defmodule QRCode.MatrixHelper do
"""
alias MatrixReloaded.Matrix

@spec surround_matrix(Matrix.t(), integer(), integer()) :: Matrix.t()
@spec surround_matrix(Matrix.t(), integer() | nil, integer()) :: Matrix.t()
def surround_matrix(matrix, quiet_zone, _value) when quiet_zone in [0, nil] do
matrix
end

def surround_matrix(matrix, quiet_zone, value)
when is_integer(quiet_zone) and quiet_zone >= 0 do
when is_integer(quiet_zone) and quiet_zone > 0 do
{rows, cols} = Matrix.size(matrix)

# Create new matrix with quiet zone
{:ok, new_matrix} = Matrix.new({rows + 2 * quiet_zone, cols + 2 * quiet_zone}, value)
{:ok, new_matrix} =
Matrix.new({rows + 2 * quiet_zone, cols + 2 * quiet_zone}, value)

# Copy qr code matrix to new matrix
{:ok, new_matrix} = Matrix.update_map(new_matrix, matrix, [{quiet_zone, quiet_zone}])
{:ok, new_matrix} =
Matrix.update_map(new_matrix, matrix, [{quiet_zone, quiet_zone}])

new_matrix
end
Expand Down