From 2e4c19150903c51826bb2f461b7581b438c65bce Mon Sep 17 00:00:00 2001 From: Brian van den Broek Date: Wed, 3 Sep 2025 13:52:59 +0200 Subject: [PATCH] Unforced quiet zone --- lib/qr_code/matrix_helper.ex | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/qr_code/matrix_helper.ex b/lib/qr_code/matrix_helper.ex index fea668e..bfe8d71 100644 --- a/lib/qr_code/matrix_helper.ex +++ b/lib/qr_code/matrix_helper.ex @@ -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