Skip to content

Commit 85341ee

Browse files
authored
Merge pull request #21 from JuliaLabs/sds/runic
format using Runic
2 parents ad52319 + c1524a8 commit 85341ee

File tree

15 files changed

+141
-118
lines changed

15 files changed

+141
-118
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# formatting using Runic
2+
b590cd059b303487b2d97b2f702dd5e349fdec91

.github/workflows/CI.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,18 @@ jobs:
5959
using AztecDiamonds
6060
DocMeta.setdocmeta!(AztecDiamonds, :DocTestSetup, :(using AztecDiamonds); recursive=true)
6161
doctest(AztecDiamonds)'
62+
runic:
63+
name: Runic
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: julia-actions/setup-julia@v2
68+
with:
69+
version: "nightly" # Only nightly have the -m flag currently
70+
- uses: julia-actions/cache@v2
71+
- name: Install Runic
72+
run: |
73+
julia --color=yes --project=@runic -e 'using Pkg; Pkg.add(url = "https://github.com/fredrikekre/Runic.jl")'
74+
- name: Run Runic
75+
run: |
76+
git ls-files -z -- '*.jl' | xargs -0 julia --project=@runic -m Runic --check --diff

docs/make.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
using AztecDiamonds
22
using Documenter
33

4-
DocMeta.setdocmeta!(AztecDiamonds, :DocTestSetup, :(using AztecDiamonds); recursive=true)
4+
DocMeta.setdocmeta!(AztecDiamonds, :DocTestSetup, :(using AztecDiamonds); recursive = true)
55

66
makedocs(;
7-
modules=[AztecDiamonds],
8-
authors="Simeon David Schaub <[email protected]> and contributors",
9-
repo="https://github.com/JuliaLabs/AztecDiamonds.jl/blob/{commit}{path}#{line}",
10-
sitename="AztecDiamonds.jl",
11-
format=Documenter.HTML(;
12-
prettyurls=get(ENV, "CI", "false") == "true",
13-
canonical="https://julia.mit.edu/AztecDiamonds.jl",
14-
edit_link="main",
15-
assets=String[],
7+
modules = [AztecDiamonds],
8+
authors = "Simeon David Schaub <[email protected]> and contributors",
9+
repo = "https://github.com/JuliaLabs/AztecDiamonds.jl/blob/{commit}{path}#{line}",
10+
sitename = "AztecDiamonds.jl",
11+
format = Documenter.HTML(;
12+
prettyurls = get(ENV, "CI", "false") == "true",
13+
canonical = "https://julia.mit.edu/AztecDiamonds.jl",
14+
edit_link = "main",
15+
assets = String[],
1616
),
17-
pages=[
17+
pages = [
1818
"Home" => "index.md",
1919
#"Examples" => [
2020
# "Basics" => "https://julia.mit.edu/AztecDiamonds.jl/examples/dev/notebook.html",
@@ -23,6 +23,6 @@ makedocs(;
2323
)
2424

2525
deploydocs(;
26-
repo="github.com/JuliaLabs/AztecDiamonds.jl",
27-
devbranch="main",
26+
repo = "github.com/JuliaLabs/AztecDiamonds.jl",
27+
devbranch = "main",
2828
)

examples/notebook.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ using InteractiveUtils
66

77
# ╔═╡ a609b8a8-04ac-4533-9a33-61ea33805846
88
begin
9-
using AztecDiamonds, CairoMakie
10-
CairoMakie.activate!(type = "svg")
9+
using AztecDiamonds, CairoMakie
10+
CairoMakie.activate!(type = "svg")
1111
end
1212

1313
# ╔═╡ 84f88e89-c55e-41ba-97ad-fd561458c7e9
@@ -18,12 +18,12 @@ D = diamond(N)
1818

1919
# ╔═╡ 1cf94d6d-a0bc-474b-b479-5b4f4c916ea5
2020
let
21-
f = Figure()
22-
ax = Axis(f[1, 1]; aspect=1)
23-
plot!(ax, D; domino_padding=0)
24-
lines!(ax, -N:N, parent(dr_path(D)); linewidth=3, label="DR-path", color=:orange)
25-
axislegend(ax)
26-
f
21+
f = Figure()
22+
ax = Axis(f[1, 1]; aspect = 1)
23+
plot!(ax, D; domino_padding = 0)
24+
lines!(ax, -N:N, parent(dr_path(D)); linewidth = 3, label = "DR-path", color = :orange)
25+
axislegend(ax)
26+
f
2727
end
2828

2929
# ╔═╡ ab0968e2-43c7-4610-87ba-47433c003081

src/AztecDiamonds.jl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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}
1515
end
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(2i-1) + abs(2j-1) 2N
18+
in_diamond(N, i, j) = abs(2i - 1) + abs(2j - 1) 2N
1919
Base.checkbounds(::Type{Bool}, (; N)::Tiling, i, j) = in_diamond(N, i, j)
2020
function 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
4747
end
4848
faces((; N)::Tiling) = DiamondFaces(N)
4949
Base.eltype(::DiamondFaces) = Tuple{Int, Int, Bool}
50-
Base.length((; N)::DiamondFaces) = N * (N+1) * 2
50+
Base.length((; N)::DiamondFaces) = N * (N + 1) * 2
5151
function 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)
6060
end
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)
6666
end
6767
Base.@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
@@ -86,9 +86,9 @@ end
8686
function 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′
110110
end
111111

112112
Base.@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
114114
end
115115

116116
# filling
117117
function 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
138138
function 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
146146
end
147147

148148
function 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)
151151
end
152152

src/dr_path.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ function dr_path(t::Tiling)
44
y[-N] = -0.5
55
prev = UP
66
i = -1
7-
for j in 1-N:N
8-
@assert checkbounds(Bool, t, i+1, j)
9-
tile = x[i+1, j]
7+
for j in (1 - N):N
8+
@assert checkbounds(Bool, t, i + 1, j)
9+
tile = x[i + 1, j]
1010
if prev == RIGHT
1111
y[j] = i + 0.5
1212
elseif tile == UP

src/ka.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ KernelAbstractions.get_backend((; x)::Tiling) = KernelAbstractions.get_backend(x
1111

1212
@inbounds if in_diamond(N, i, j) && isblock(t, i, j, Val(false))
1313
if t[i, j] == UP
14-
t[i, j+1] = NONE
14+
t[i, j + 1] = NONE
1515
else
16-
t[i+1, j] = NONE
16+
t[i + 1, j] = NONE
1717
end
1818
t[i, j] = NONE
1919
end
@@ -27,12 +27,12 @@ end
2727

2828
@inbounds if in_diamond(N, i, j)
2929
tile = @inbounds t[i, j]
30-
isdotted = isodd(i+j-N)
30+
isdotted = isodd(i + j - N)
3131
inc = ifelse(isdotted, -1, 1)
3232
@inbounds if tile == UP
33-
t′[i, j+inc] = UP
33+
t′[i, j + inc] = UP
3434
elseif tile == RIGHT
35-
t′[i+inc, j] = RIGHT
35+
t′[i + inc, j] = RIGHT
3636
end
3737
end
3838
end
@@ -71,9 +71,9 @@ end
7171
@inbounds if in_diamond(N, i, j)
7272
if scratch[i, j] == SHOULD_FILL
7373
if rand(Bool)
74-
t′[i, j] = t′[i, j+1] = UP
74+
t′[i, j] = t′[i, j + 1] = UP
7575
else
76-
t′[i, j] = t′[i+1, j] = RIGHT
76+
t′[i, j] = t′[i + 1, j] = RIGHT
7777
end
7878
end
7979
end
@@ -99,7 +99,7 @@ function ka_diamond!(t, t′, N; backend)
9999
t, t′ = t′, t
100100

101101
for N in 2:N
102-
zero!(t′, N-1; ndrange)
102+
zero!(t′, N - 1; ndrange)
103103
t′ = Tiling(N, t′.x)
104104

105105
remove_bad_blocks!(t; ndrange)
@@ -116,7 +116,7 @@ end
116116
function ka_diamond(N, ArrayT)
117117
mem = ntuple(_ -> fill!(ArrayT{Edge}(undef, 2N, 2N), NONE), 2)
118118
t, t′ = map(x -> Tiling(0, OffsetMatrix(x, inds(N))), mem)
119-
return ka_diamond!(t, t′, N; backend=KernelAbstractions.get_backend(mem[1]))
119+
return ka_diamond!(t, t′, N; backend = KernelAbstractions.get_backend(mem[1]))
120120
end
121121

122122
# rotation of tilings
@@ -129,10 +129,10 @@ end
129129
edge = NONE
130130
if @inbounds t.x[i, j] == RIGHT
131131
edge = UP
132-
elseif get(t, (i-1, j), NONE) == UP
132+
elseif get(t, (i - 1, j), NONE) == UP
133133
edge = RIGHT
134134
end
135-
@inbounds t′.x[j, 1-i] = edge
135+
@inbounds t′.x[j, 1 - i] = edge
136136
end
137137

138138
@kernel function rotl90_kernel!(t′::Tiling, @Const(t::Tiling))
@@ -143,10 +143,10 @@ end
143143
edge = NONE
144144
if @inbounds t.x[i, j] == UP
145145
edge = RIGHT
146-
elseif get(t, (i, j-1), NONE) == RIGHT
146+
elseif get(t, (i, j - 1), NONE) == RIGHT
147147
edge = UP
148148
end
149-
@inbounds t′.x[1-j, i] = edge
149+
@inbounds t′.x[1 - j, i] = edge
150150
end
151151

152152
@kernel function rot180_kernel!(t′::Tiling, @Const(t::Tiling))
@@ -155,20 +155,20 @@ end
155155
i, j = I .- N
156156

157157
edge = NONE
158-
if get(t, (i-1, j), NONE) == UP
158+
if get(t, (i - 1, j), NONE) == UP
159159
edge = UP
160-
elseif get(t, (i, j-1), NONE) == RIGHT
160+
elseif get(t, (i, j - 1), NONE) == RIGHT
161161
edge = RIGHT
162162
end
163-
@inbounds t′.x[1-i, 1-j] = edge
163+
@inbounds t′.x[1 - i, 1 - j] = edge
164164
end
165165

166166
for rot in Symbol.(:rot, ["r90", "l90", "180"])
167167
@eval function Base.$rot(t::Tiling)
168168
(; N, x) = t
169169
t′ = Tiling(N, similar(x))
170170
backend = KernelAbstractions.get_backend(t)
171-
$(Symbol(rot, :_kernel!))(backend)(t′, t; ndrange=(2N, 2N))
171+
$(Symbol(rot, :_kernel!))(backend)(t′, t; ndrange = (2N, 2N))
172172
return t′
173173
end
174174
end

src/makie.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
using MakieCore
22
using GeometryBasics: Vec2f, Point2f, Rect2f
33

4-
function prepare_plot(t::Tiling; pad=.1f0)
4+
function prepare_plot(t::Tiling; pad = 0.1f0)
55
tiles = Rect2f[]
66
colors = RGB{Colors.N0f8}[]
77
arrow_pts, arrows = Point2f[], Vec2f[]
88
foreach(faces(t)) do (i, j, isdotted)
99
if t[i, j] == UP
10-
r = Rect2f(j-1+pad, i-1+pad, 1-2pad, 2-2pad)
10+
r = Rect2f(j - 1 + pad, i - 1 + pad, 1 - 2pad, 2 - 2pad)
1111
col = isdotted ? colorant"red" : colorant"green"
1212
push!(tiles, r)
1313
push!(colors, col)
14-
off = isdotted ? -.3f0 : .3f0
15-
push!(arrow_pts, Point2f(j-.5f0-off, i))
16-
push!(arrows, Point2f(isdotted ? -.5f0 : .5f0, 0))
14+
off = isdotted ? -0.3f0 : 0.3f0
15+
push!(arrow_pts, Point2f(j - 0.5f0 - off, i))
16+
push!(arrows, Point2f(isdotted ? -0.5f0 : 0.5f0, 0))
1717
elseif t[i, j] == RIGHT
18-
r = Rect2f(j-1+pad, i-1+pad, 2-2pad, 1-2pad)
18+
r = Rect2f(j - 1 + pad, i - 1 + pad, 2 - 2pad, 1 - 2pad)
1919
col = isdotted ? colorant"yellow" : colorant"blue"
2020
push!(tiles, r)
2121
push!(colors, col)
22-
off = isdotted ? -.3f0 : .3f0
23-
push!(arrow_pts, Point2f(j, i-.5f0-off))
24-
push!(arrows, Point2f(0, isdotted ? -.5f0 : .5f0))
22+
off = isdotted ? -0.3f0 : 0.3f0
23+
push!(arrow_pts, Point2f(j, i - 0.5f0 - off))
24+
push!(arrows, Point2f(0, isdotted ? -0.5f0 : 0.5f0))
2525
end
2626
end
27-
tiles, colors, arrow_pts, arrows
27+
return tiles, colors, arrow_pts, arrows
2828
end
2929

3030
MakieCore.@recipe(TilingPlot, t) do scene
@@ -39,8 +39,8 @@ MakieCore.plottype(::Tiling) = TilingPlot
3939

4040
function MakieCore.plot!(x::TilingPlot{<:Tuple{Tiling}})
4141
t = adapt(Array, x[:t][])
42-
tiles, colors, arrow_pts, arrows = prepare_plot(t; pad=x.domino_padding[])
43-
poly!(x, tiles; color=colors, strokewidth=x.domino_stroke)
42+
tiles, colors, arrow_pts, arrows = prepare_plot(t; pad = x.domino_padding[])
43+
poly!(x, tiles; color = colors, strokewidth = x.domino_stroke)
4444
x.show_arrows[] && arrows!(x, arrow_pts, arrows)
45-
x
45+
return x
4646
end

0 commit comments

Comments
 (0)