From b379ebd0b3cf5f6cfcfd32fbed7de91c10a5e6c6 Mon Sep 17 00:00:00 2001 From: Keith_Reid_sfw Date: Fri, 19 Feb 2021 10:06:20 +0000 Subject: [PATCH 1/2] added small function for viewing a square matrix in rhomboid style; no test --- src/Hexagons.jl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Hexagons.jl b/src/Hexagons.jl index 2b42f8c..789059f 100644 --- a/src/Hexagons.jl +++ b/src/Hexagons.jl @@ -45,6 +45,29 @@ end hexagon(x::Int, y::Int, z::Int) = HexagonCubic(x, y, z) hexagon(q::Int, r::Int) = HexagonAxial(q, r) +# Print a square matrix in a rhomboid form for human inspection +# ------------------------------------------------------ + +function rhomboid_print(square_matrix::Array) + side_length = trunc(Int, length(square_matrix) ^ 0.5) + transposed_square = square_matrix' + spaces = string.(collect(" " ^ side_length)) + for i in 1:side_length + start = 1+(i-1)* side_length + stop = (i) * side_length + this_row = string.(Int.(transposed_square[start:stop])) + both = [collect(pair) for pair in zip(this_row, spaces)] + all_both = vcat(both...) + pretty_both = string(all_both...) + pad_left = " " ^ i + padded_pretty = hcat(pad_left, pretty_both) + joined_padded_pretty = string(padded_pretty...) + println(joined_padded_pretty) + end +end + +mock = [0 1 1 0; 1 0 0 1; 1 0 0 1; 0 1 1 0] +rhomboid_print(mock) # Convert between hexagon indexing # -------------------------------- From 2898cd104b603b0bbe1bd995a2e672d18d8b1614 Mon Sep 17 00:00:00 2001 From: keithreid-sfw <56557748+keithreid-sfw@users.noreply.github.com> Date: Fri, 19 Feb 2021 10:17:06 +0000 Subject: [PATCH 2/2] commented out my mock demonstration --- src/Hexagons.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Hexagons.jl b/src/Hexagons.jl index 789059f..f79ef8f 100644 --- a/src/Hexagons.jl +++ b/src/Hexagons.jl @@ -66,8 +66,8 @@ function rhomboid_print(square_matrix::Array) end end -mock = [0 1 1 0; 1 0 0 1; 1 0 0 1; 0 1 1 0] -rhomboid_print(mock) +#mock = [0 1 1 0; 1 0 0 1; 1 0 0 1; 0 1 1 0] +#rhomboid_print(mock) # Convert between hexagon indexing # --------------------------------