Skip to content

Commit

Permalink
Account for edge case where you only have single x value in coordinate (
Browse files Browse the repository at this point in the history
#656)

* Account for edge case where you only have single x value in coordinate)

* Added unit tests for text-based pretty printing
  • Loading branch information
johnzl-777 authored Jan 22, 2024
1 parent 69e4eb4 commit 4649cc5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/BloqadeLattices/src/visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,15 @@ function Base.show(io::IO, mime::MIME"text/plain", atoms::AtomList)
y = Float64[]
for coord in atoms
push!(x, coord[1])
push!(y, coord[2])

# Could be the case that coordinate only has single x value
# in which case we set the y value to 0
if length(coord) == 1
push!(y, 0)
else
push!(y, coord[2])
end

end

plt = scatterplot(
Expand Down
17 changes: 16 additions & 1 deletion lib/BloqadeLattices/test/visualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using BloqadeLattices
using LuxorGraphPlot
using Documenter

@testset "visualize" begin
@testset "visualize (image)" begin
BloqadeLattices.darktheme!()
lt = generate_sites(KagomeLattice(), 5, 5, scale = 1.5)
blt = parallelepiped_region(KagomeLattice(), (5,0),(0,5);scale=1.5)
Expand All @@ -29,3 +29,18 @@ using Documenter
@test img_atoms(lt; colors = nothing) isa LuxorGraphPlot.Drawing
@test show(IOBuffer(), MIME"image/svg+xml"(), lt) === nothing
end


@testset "visualize (text)" begin

@testset "single x value" begin
lt = generate_sites(ChainLattice(), 10, scale=5.74)
show(stdout, MIME"text/plain"(), lt)
end

@testset "x and y values" begin
lt = generate_sites(SquareLattice(), 5, 5, scale=5.74)
show(stdout, MIME"text/plain"(), lt)
end

end

0 comments on commit 4649cc5

Please sign in to comment.