diff --git a/src/lattices/latticepoints.jl b/src/lattices/latticepoints.jl index 9b6d767..14a233e 100644 --- a/src/lattices/latticepoints.jl +++ b/src/lattices/latticepoints.jl @@ -44,15 +44,21 @@ function Base.:-(i::LatticePoint{N,G}, j::LatticePoint{N,G}) where {N,G} return LatticePoint(i.coordinates .- j.coordinates, i.lattice) end -Base.:+(i::LatticePoint{N}, j::NTuple{N,Int}) where {N} = i + LatticePoint(j, i.lattice) -Base.:+(i::LatticePoint{1}, j::Int) = i + LatticePoint(j, i.lattice) -Base.:+(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} = LatticePoint(i, j.lattice) + j -Base.:+(i::Int, j::LatticePoint{1}) = LatticePoint(i, j.lattice) + j - -Base.:-(i::LatticePoint{N}, j::NTuple{N,Int}) where {N} = i - LatticePoint(j, i.lattice) -Base.:-(i::LatticePoint{1}, j::Int) = i - LatticePoint(j, i.lattice) -Base.:-(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} = LatticePoint(i, j.lattice) - j -Base.:-(i::Int, j::LatticePoint{1}) = LatticePoint(i, j.lattice) - j +function Base.:+(i::LatticePoint{N}, j::NTuple{N,Int}) where {N} + return LatticePoint(i.coordinates .+ j, i.lattice) +end +Base.:+(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .+ j, i.lattice) +Base.:+(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} = j + i +Base.:+(i::Int, j::LatticePoint{1}) = j + i + +function Base.:-(i::LatticePoint{N}, j::NTuple{N,Int}) where {N} + return LatticePoint(i.coordinates .+ j, i.lattice) +end +Base.:-(i::LatticePoint{1}, j::Int) = LatticePoint(i.coordinates .+ j, i.lattice) +function Base.:-(i::NTuple{N,Int}, j::LatticePoint{N}) where {N} + return LatticePoint(i .- j.coordinates, j.lattice) +end +Base.:-(i::Int, j::LatticePoint{1}) = LatticePoint(i .- j, j.lattice) Base.isless(i::L, j::L) where {L<:LatticePoint} = linearize_index(i) < linearize_index(j) diff --git a/test/lattices.jl b/test/lattices.jl index d2507f9..a28c849 100644 --- a/test/lattices.jl +++ b/test/lattices.jl @@ -100,6 +100,39 @@ end end end +@testset "InfiniteStrip" begin + for L in 2:4 + lattice = InfiniteStrip(L) + V = vertices(lattice) + @test length(lattice) == length(V) == L + @test lattice[1, 1] == first(V) + + NN = nearest_neighbours(lattice) + @test length(NN) == 2L - 1 # coordination number 4 - 1 boundary + @test allunique(NN) + + NNN = next_nearest_neighbours(lattice) + @test length(NNN) == 2L - 2 # coordination number 4 - 2 boundary + @test allunique(NNN) + + for N in (2L, 3L) + lattice = InfiniteStrip(L, N) + V = vertices(lattice) + @test length(lattice) == length(V) == N + + NN = nearest_neighbours(lattice) + @test length(NN) == 2N - (N ÷ L) # coordination number 4 + @test allunique(NN) + + NNN = next_nearest_neighbours(lattice) + @test length(NNN) == 2N - 2(N ÷ L) # coordination number 4 + @test allunique(NNN) + end + + @test_throws ArgumentError InfiniteStrip(L, 5) + end +end + @testset "InfiniteHoneycombYC" begin for L in 4:4:12, N in 1:3 lattice = HoneycombYC(L, N * L)