Skip to content

Commit 462989f

Browse files
committed
Cicular: new interface
1 parent ba7895a commit 462989f

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/NetworkLayout.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ include("buchheim.jl")
3636
include("spring.jl")
3737
include("stress.jl")
3838
include("spectral.jl")
39-
# include("circular.jl")
39+
include("circular.jl")
4040
# include("shell.jl")
4141

4242
end

src/circular.jl

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,16 @@ julia> g = simple_house_graph()
1414
julia> locs_x, locs_y = circular_layout(g)
1515
```
1616
"""
17-
module Circular
17+
struct Circular{Ptype} <: AbstractLayout{2,Ptype} end
1818

19-
using GeometryBasics
19+
Circular(; Ptype=Float64) = Circular{Ptype}()
2020

21-
function layout(adj_matrix::AbstractMatrix)
22-
return layout!(adj_matrix)
23-
end
24-
25-
function layout!(adj_matrix::AbstractMatrix)
21+
function layout(::Circular{Ptype}, adj_matrix) where {Ptype}
2622
if size(adj_matrix, 1) == 1
27-
return Point{2,Float64}[Point(0.0, 0.0)]
23+
return Point{2,Ptype}[Point(0.0, 0.0)]
2824
else
2925
# Discard the extra angle since it matches 0 radians.
30-
θ = range(0, stop=2pi, length=size(adj_matrix, 1) + 1)[1:(end - 1)]
31-
return Point{2,Float64}[(cos(o), sin(o)) for o in θ]
26+
θ = range(0; stop=2pi, length=size(adj_matrix, 1) + 1)[1:(end - 1)]
27+
return Point{2,Ptype}[(cos(o), sin(o)) for o in θ]
3228
end
3329
end
34-
35-
end # end of module

test/runtests.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,20 @@ jagmesh_adj = jagmesh()
169169
end
170170

171171
@testset "Testing Circular Layout Algorithm" begin
172+
using NetworkLayout: Circular
172173
println("Circular wheel_graph")
173174
@testset "Testing wheel_graph" begin
174175
g = wheel_graph(10)
175176
adj_matrix = adjacency_matrix(g)
176-
positions = @time Circular.layout(adj_matrix)
177+
positions = @time Circular()(adj_matrix)
177178
@test typeof(positions) == Vector{Point{2,Float64}}
179+
positions = @time Circular(Ptype=Float32)(adj_matrix)
180+
@test typeof(positions) == Vector{Point{2,Float32}}
178181
end
179182
@testset "Testing Base Case" begin
180183
g = Graph(1)
181184
adj_matrix = adjacency_matrix(g)
182-
positions = @time Circular.layout(adj_matrix)
185+
positions = @time Circular()(adj_matrix)
183186
@test typeof(positions) == Vector{Point{2,Float64}}
184187
end
185188
end

0 commit comments

Comments
 (0)