Skip to content

Commit

Permalink
Remove need to cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
whomwah committed Mar 26, 2021
1 parent 04f8006 commit ec65d51
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/rqrcode/export/svg.rb
Expand Up @@ -106,12 +106,11 @@ def use_rect(str, module_size, offset, color)

def use_path(str, module_size, offset, color)
modules_array = @qrcode.modules
matrix_height = modules_array.length + 1
matrix_width = modules_array.first.length + 1
edge_matrix = Array.new(matrix_height) { Array.new(matrix_width) { [] } }
false_row = [[false] * modules_array.first.length]
matrix_width = matrix_height = modules_array.length + 1
empty_row = [Array.new(matrix_width - 1, false)]
edge_matrix = Array.new(matrix_height) { Array.new(matrix_width) }

(false_row + modules_array + false_row).each_cons(2).with_index do |row_pair, row_index|
(empty_row + modules_array + empty_row).each_cons(2).with_index do |row_pair, row_index|
first_row, second_row = row_pair

# horizontal edges
Expand All @@ -120,7 +119,8 @@ def use_path(str, module_size, offset, color)
when [true, false] then Edge.new column_index + 1, row_index, :left
when [false, true] then Edge.new column_index, row_index, :right
end
edge_matrix[edge.start_y][edge.start_x] << edge if edge

(edge_matrix[edge.start_y][edge.start_x] ||= []) << edge if edge
end

# vertical edges
Expand All @@ -129,14 +129,8 @@ def use_path(str, module_size, offset, color)
when [true, false] then Edge.new column_index, row_index, :down
when [false, true] then Edge.new column_index, row_index + 1, :up
end
edge_matrix[edge.start_y][edge.start_x] << edge if edge
end
end

# clean up empty cells
edge_matrix.each_with_index do |matrix_row, row_index|
matrix_row.each_with_index do |cell, column_index|
matrix_row[column_index] = nil if cell.empty?
(edge_matrix[edge.start_y][edge.start_x] ||= []) << edge if edge
end
end

Expand Down

0 comments on commit ec65d51

Please sign in to comment.