Skip to content

Commit 4649cc5

Browse files
authored
Account for edge case where you only have single x value in coordinate (#656)
* Account for edge case where you only have single x value in coordinate) * Added unit tests for text-based pretty printing
1 parent 69e4eb4 commit 4649cc5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

lib/BloqadeLattices/src/visualize.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,15 @@ function Base.show(io::IO, mime::MIME"text/plain", atoms::AtomList)
392392
y = Float64[]
393393
for coord in atoms
394394
push!(x, coord[1])
395-
push!(y, coord[2])
395+
396+
# Could be the case that coordinate only has single x value
397+
# in which case we set the y value to 0
398+
if length(coord) == 1
399+
push!(y, 0)
400+
else
401+
push!(y, coord[2])
402+
end
403+
396404
end
397405

398406
plt = scatterplot(

lib/BloqadeLattices/test/visualize.jl

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ using BloqadeLattices
33
using LuxorGraphPlot
44
using Documenter
55

6-
@testset "visualize" begin
6+
@testset "visualize (image)" begin
77
BloqadeLattices.darktheme!()
88
lt = generate_sites(KagomeLattice(), 5, 5, scale = 1.5)
99
blt = parallelepiped_region(KagomeLattice(), (5,0),(0,5);scale=1.5)
@@ -29,3 +29,18 @@ using Documenter
2929
@test img_atoms(lt; colors = nothing) isa LuxorGraphPlot.Drawing
3030
@test show(IOBuffer(), MIME"image/svg+xml"(), lt) === nothing
3131
end
32+
33+
34+
@testset "visualize (text)" begin
35+
36+
@testset "single x value" begin
37+
lt = generate_sites(ChainLattice(), 10, scale=5.74)
38+
show(stdout, MIME"text/plain"(), lt)
39+
end
40+
41+
@testset "x and y values" begin
42+
lt = generate_sites(SquareLattice(), 5, 5, scale=5.74)
43+
show(stdout, MIME"text/plain"(), lt)
44+
end
45+
46+
end

0 commit comments

Comments
 (0)