@@ -7,15 +7,15 @@ export Tiling, diamond, ka_diamond, dr_path
77
88@enum Edge:: UInt8 NONE UP RIGHT SHOULD_FILL
99
10- inds (N) = (1 - N : N, 1 - N : N)
10+ inds (N) = (( 1 - N) : N, ( 1 - N) : N)
1111
12- struct Tiling{M<: AbstractMatrix{Edge} }
12+ struct Tiling{M <: AbstractMatrix{Edge} }
1313 N:: Int
1414 x:: OffsetMatrix{Edge, M}
1515end
16- Tiling (N:: Int ; sizehint= N) = Tiling (N, fill (NONE, inds (sizehint)))
16+ Tiling (N:: Int ; sizehint = N) = Tiling (N, fill (NONE, inds (sizehint)))
1717
18- in_diamond (N, i, j) = abs (2 i- 1 ) + abs (2 j- 1 ) ≤ 2 N
18+ in_diamond (N, i, j) = abs (2 i - 1 ) + abs (2 j - 1 ) ≤ 2 N
1919Base. checkbounds (:: Type{Bool} , (; N):: Tiling , i, j) = in_diamond (N, i, j)
2020function Base. checkbounds (t:: Tiling , i, j)
2121 checkbounds (Bool, t, i, j) || throw (BoundsError (t, (i, j)))
@@ -47,30 +47,30 @@ struct DiamondFaces <: Transducers.Foldable
4747end
4848faces ((; N):: Tiling ) = DiamondFaces (N)
4949Base. eltype (:: DiamondFaces ) = Tuple{Int, Int, Bool}
50- Base. length ((; N):: DiamondFaces ) = N * (N+ 1 ) * 2
50+ Base. length ((; N):: DiamondFaces ) = N * (N + 1 ) * 2
5151function Transducers. __foldl__ (rf:: R , val:: V , (; N):: DiamondFaces ) where {R, V}
52- for j in 1 - N : N
53- j′ = max (j, 1 - j)
54- for i in j′ - N : N - j′ + 1
55- isdotted = isodd (i+ j - N)
52+ for j in ( 1 - N) : N
53+ j′ = max (j, 1 - j)
54+ for i in (j′ - N) : (N - j′ + 1 )
55+ isdotted = isodd (i + j - N)
5656 val = @next (rf, val, (i, j, isdotted))
5757 end
5858 end
5959 return complete (rf, val)
6060end
6161
6262
63- struct BlockIterator{good, T<: Tiling } <: Transducers.Foldable
63+ struct BlockIterator{good, T <: Tiling } <: Transducers.Foldable
6464 t:: T
65- BlockIterator {good} (t:: T ) where {good, T<: Tiling } = new {good, T} (t)
65+ BlockIterator {good} (t:: T ) where {good, T <: Tiling } = new {good, T} (t)
6666end
6767Base. @propagate_inbounds function isblock (t:: Tiling , i, j, :: Val{good} ) where {good}
6868 (; N) = t
69- isdotted = isodd (i+ j - N)
69+ isdotted = isodd (i + j - N)
7070 tile = t[i, j]
71- if tile == UP && j < N && get (t, (i, j+ 1 ), NONE) == UP
71+ if tile == UP && j < N && get (t, (i, j + 1 ), NONE) == UP
7272 return good == isdotted
73- elseif tile == RIGHT && i < N && get (t, (i+ 1 , j), NONE) == RIGHT
73+ elseif tile == RIGHT && i < N && get (t, (i + 1 , j), NONE) == RIGHT
7474 return good == isdotted
7575 end
7676 return false
8686function remove_bad_blocks! (t:: Tiling )
8787 foreach (BlockIterator {false} (t)) do (i, j)
8888 @inbounds if t[i, j] == UP
89- t[i, j+ 1 ] = NONE
89+ t[i, j + 1 ] = NONE
9090 else
91- t[i+ 1 , j] = NONE
91+ t[i + 1 , j] = NONE
9292 end
9393 @inbounds t[i, j] = NONE
9494 end
@@ -101,26 +101,26 @@ function slide_tiles!(t′::Tiling, t::Tiling)
101101 tile = @inbounds t[i, j]
102102 inc = isdotted ? - 1 : 1
103103 @inbounds if tile == UP
104- t′[i, j+ inc] = UP
104+ t′[i, j + inc] = UP
105105 elseif tile == RIGHT
106- t′[i+ inc, j] = RIGHT
106+ t′[i + inc, j] = RIGHT
107107 end
108108 end
109109 return t′
110110end
111111
112112Base. @propagate_inbounds function is_empty_tile (t′:: Tiling , i, j)
113- return t′[i, j] == NONE && get (t′, (i- 1 , j), NONE) != UP && get (t′, (i, j- 1 ), NONE) != RIGHT
113+ return t′[i, j] == NONE && get (t′, (i - 1 , j), NONE) != UP && get (t′, (i, j - 1 ), NONE) != RIGHT
114114end
115115
116116# filling
117117function fill_empty_blocks! (t′:: Tiling )
118118 foreach (faces (t′)) do (i, j)
119119 @inbounds if is_empty_tile (t′, i, j)
120120 if rand (Bool)
121- t′[i, j] = t′[i, j+ 1 ] = UP
121+ t′[i, j] = t′[i, j + 1 ] = UP
122122 else
123- t′[i, j] = t′[i+ 1 , j] = RIGHT
123+ t′[i, j] = t′[i + 1 , j] = RIGHT
124124 end
125125 end
126126 end
@@ -138,15 +138,15 @@ end
138138function diamond! (t, t′, N)
139139 for N in 1 : N
140140 (; x) = t′
141- view (x, inds (N- 1 )... ) .= NONE
141+ view (x, inds (N - 1 )... ) .= NONE
142142 t′ = Tiling (N, x)
143143 t, t′ = step! (t′, t), t
144144 end
145145 return t
146146end
147147
148148function diamond (N)
149- t, t′ = Tiling (0 ; sizehint= N), Tiling (0 ; sizehint= N)
149+ t, t′ = Tiling (0 ; sizehint = N), Tiling (0 ; sizehint = N)
150150 return diamond! (t, t′, N)
151151end
152152
0 commit comments