diff --git a/Project.toml b/Project.toml index 94b9e831..2a978e2f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Crystalline" uuid = "ae5e2be0-a263-11e9-351e-f94dad1eb351" authors = ["Thomas Christensen "] -version = "0.3.8" +version = "0.3.9" [deps] Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa" diff --git a/src/Crystalline.jl b/src/Crystalline.jl index 3952cbcc..cefde1a6 100644 --- a/src/Crystalline.jl +++ b/src/Crystalline.jl @@ -18,7 +18,8 @@ import Base: getindex, setindex!, # → iteration/AbstractArray interface string, isapprox, zero, readuntil, vec, show, summary, +, -, ∘, ==, ImmutableDict, - isone, one + isone, one, + convert import LinearAlgebra: inv import Random # → `_Uniform` in src/utils.jl import Random: rand # ⤶ diff --git a/src/types.jl b/src/types.jl index 4a575300..2427c576 100644 --- a/src/types.jl +++ b/src/types.jl @@ -8,18 +8,30 @@ for T in (:DirectBasis, :ReciprocalBasis) @doc """ $($T){D} <: Basis{D} - - `vecs::NTuple{D, SVector{D, Float64}}` + - `vecs::SVector{D, SVector{D,Float64}}` """ struct $T{D} <: Basis{D} - vecs::SVector{D,SVector{D,Float64}} + vecs::SVector{D, SVector{D,Float64}} + $T{D}(vecs::SVector{D, SVector{D,Float64}}) where D = new{D}(vecs) + $T(vecs::SVector{D, SVector{D,Float64}}) where D = new{D}(vecs) end end - @eval $T(Rs::NTuple{D,AbstractVector{<:Real}}) where D = $T{D}(SVector{D,Float64}.(Rs)) - @eval $T(Rs::NTuple{D,NTuple{D,<:Real}}) where D = $T{D}(SVector{D,Float64}.(Rs)) - @eval $T(Rs::AbstractVector{<:Real}...) = $T(Rs) - @eval $T(Rs::NTuple{D,<:Real}...) where D = $T{D}(SVector{D,Float64}.(Rs)) - @eval $T(Rs::AbstractVector{<:Real}) = (D=length(Rs); $T{D}(SVector{D,Float64}.(Rs))) -end + @eval function convert(::Type{$T{D}}, Vs::StaticVector{D, <:StaticVector{D, <:Real}}) where D + $T{D}(convert(SVector{D, SVector{D, Float64}}, Vs)) + end + @eval $T{D}(Vs::NTuple{D, SVector{D, Float64}}) where D = $T{D}(SVector{D}(Vs)) + @eval $T(Vs::NTuple{D, SVector{D, Float64}}) where D = $T{D}(Vs) + @eval $T{D}(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(SVector{D,Float64}.(Vs)) + @eval $T(Vs::NTuple{D, NTuple{D,<:Real}}) where D = $T{D}(Vs) + @eval $T{D}(Vs::AbstractVector{<:Real}...) where D = $T{D}(convert(SVector{D, SVector{D, Float64}}, Vs)) + @eval $T(Vs::AbstractVector{<:Real}...) = $T{length(Vs)}(Vs...) + @eval $T{D}(Vs::StaticVector{D,<:Real}...) where D = $T{D}(Vs) # resolve ambiguities w/ + @eval $T(Vs::StaticVector{D,<:Real}...) where D = $T{D}(Vs) # `::StaticArray` methods +end + +# Fix a bug in StaticArrays: https://github.com/JuliaArrays/StaticArrays.jl/issues/915 +# TODO: Remove when fixed upstream +Base.abs2(a::StaticArray) = LinearAlgebra.norm_sqr(a) vecs(Vs::Basis) = Vs.vecs # define the AbstractArray interface for DirectBasis{D}