Skip to content

Commit

Permalink
Merge pull request #10 from MineralsCloud:conversion
Browse files Browse the repository at this point in the history
Add constructors of `Indices`, use constructors to implement `convert`
  • Loading branch information
singularitti authored Oct 8, 2023
2 parents 37aed5f + a13b103 commit b285d68
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/miller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,23 @@ Base.IndexStyle(::Type{<:Indices}) = IndexLinear()

Base.getindex(x::Indices, i::Int) = getindex(x.data, i)

Base.convert(::Type{T}, x::T) where {T<:Indices} = x
Base.convert(::Type{Miller}, mb::MillerBravais) =
Miller(2 * mb[1] + mb[2], 2 * mb[2] + mb[1], mb[4])
Base.convert(::Type{ReciprocalMiller}, mb::ReciprocalMillerBravais) =
ReciprocalMiller(mb[1], mb[2], mb[4])
Base.convert(::Type{MillerBravais}, m::Miller) =
Miller(mb::MillerBravais) = Miller(2 * mb[1] + mb[2], 2 * mb[2] + mb[1], mb[4])

ReciprocalMiller(mb::ReciprocalMillerBravais) = ReciprocalMiller(mb[1], mb[2], mb[4])

MillerBravais(m::Miller) =
MillerBravais(2 * m[1] - m[2], 2 * m[2] - m[1], -(m[1] + m[2]), 3 * m[3])
Base.convert(::Type{ReciprocalMillerBravais}, m::ReciprocalMiller) =

ReciprocalMillerBravais(m::ReciprocalMiller) =
ReciprocalMillerBravais(m[1], m[2], -(m[1] + m[2]), m[3])

Base.convert(::Type{T}, x::T) where {T<:Indices} = x
Base.convert(::Type{Miller}, mb::MillerBravais) = Miller(mb)
Base.convert(::Type{ReciprocalMiller}, mb::ReciprocalMillerBravais) = ReciprocalMiller(mb)
Base.convert(::Type{MillerBravais}, m::Miller) = MillerBravais(m)
Base.convert(::Type{ReciprocalMillerBravais}, m::ReciprocalMiller) =
ReciprocalMillerBravais(m)

Base.show(io::IO, x::Union{Miller,MillerBravais}) = print(io, '<', join(x.data, " "), '>')
Base.show(io::IO, x::Union{ReciprocalMiller,ReciprocalMillerBravais}) =
print(io, '{', join(x.data, " "), '}')

0 comments on commit b285d68

Please sign in to comment.