Skip to content

Commit 8039d93

Browse files
committed
add init functions for generating char arrays externally
1 parent 585abdf commit 8039d93

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "UnicodeGraphics"
22
uuid = "ebadf6b4-db70-5817-83da-4a19ad584e34"
33
authors = ["Rafael Schouten <[email protected]>"]
4-
version = "0.1.0"
4+
version = "0.1.2"
55

66
[compat]
77
julia = "1"

src/UnicodeGraphics.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export blockize, brailize, blockize!, brailize!
99
brailize(a, cutoff=0)
1010
Convert an array to a block unicode string, filling values above the cutoff point.
1111
"""
12-
blockize(a, cutoff=0) = begin
13-
yrange, xrange = axes(a)
14-
out = Array{Char,2}(undef, length(xrange) + 1, (length(yrange) - 1) ÷ 2 + 1)
15-
blockize!(out, a, cutoff)
16-
end
12+
blockize(a, cutoff=0) = blockize!(initblock(size(a)), a, cutoff)
13+
14+
# x and y are inverted: repl rows are columns.
15+
initblock((y, x)) = initblock(y, x)
16+
initblock(y, x) = Array{Char,2}(undef, x + 1, (y - 1) ÷ 2 + 1)
1717

1818
"""
1919
blockize!(out, a, cutoff=0)
@@ -54,11 +54,11 @@ const braile_hex = ((0x01, 0x08), (0x02, 0x10), (0x04, 0x20), (0x40, 0x80))
5454
brailize(a, cutoff=0)
5555
Convert an array to a braile unicode string, filling values above the cutoff point.
5656
"""
57-
brailize(a, cutoff=0) = begin
58-
yrange, xrange = axes(a)
59-
out = Array{Char,2}(undef, (length(xrange) - 1) ÷ 2 + 2, (length(yrange) - 1) ÷ 4 + 1)
60-
brailize!(out, a, cutoff)
61-
end
57+
brailize(a, cutoff=0) = brailize!(initbraile(size(a)), a, cutoff)
58+
59+
# x and y are inverted: repl rows are columns.
60+
initbraile((y, x)) = initbraile(y, x)
61+
initbraile(y, x) = Array{Char,2}(undef, (x - 1) ÷ 2 + 2, (y - 1) ÷ 4 + 1)
6262

6363
"""
6464
brailize!(out, a, cutoff=0)

test/runtests.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using UnicodeGraphics,
2-
OffsetArrays,
3-
Test
1+
using UnicodeGraphics, OffsetArrays, Test
42

53
pac = [0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0;
64
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0;
@@ -83,7 +81,7 @@ block_ghost =
8381
██▀███▀▀███▀██
8482
▀ ▀▀ ▀▀ ▀\0"""
8583

86-
test_ghost = blockize(OffsetArray(ghost[3:15, 4:17], 3:15, 4:17), 0.5, )
84+
test_ghost = blockize(OffsetArray(ghost[3:15, 4:17], 3:15, 4:17), 0.5)
8785
@test test_ghost == block_ghost
8886
println(test_ghost, "\n\n", block_ghost, "\n\n")
8987

0 commit comments

Comments
 (0)