Skip to content
Snippets Groups Projects
Verified Commit ef69993b authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Fix Direction constructor and improve Position

parent 5b6ea2a8
Branches
Tags
No related merge requests found
...@@ -23,7 +23,8 @@ const version = let ...@@ -23,7 +23,8 @@ const version = let
end end
using DocStringExtensions using DocStringExtensions
using StaticArrays: FieldVector, @SArray, SVector using StaticArrays: FieldVector, @SArray, SVector, Size
import StaticArrays: similar_type
import UnROOT import UnROOT
using HDF5 using HDF5
......
...@@ -12,6 +12,7 @@ struct Position{T} <: FieldVector{3, T} ...@@ -12,6 +12,7 @@ struct Position{T} <: FieldVector{3, T}
y::T y::T
z::T z::T
end end
similar_type(::Type{<:Position}, ::Type{T}, s::Size{(3,)}) where {T} = Position{T}
""" """
A vector to represent a direction in 3D. A vector to represent a direction in 3D.
...@@ -20,14 +21,16 @@ struct Direction{T<:AbstractFloat} <: FieldVector{3, T} ...@@ -20,14 +21,16 @@ struct Direction{T<:AbstractFloat} <: FieldVector{3, T}
x::T x::T
y::T y::T
z::T z::T
function Direction(x, y, z) function Direction{U}(x, y, z) where U
T = promote_type(typeof(x), typeof(y), typeof(z)) T = promote_type(typeof(x), typeof(y), typeof(z), U)
if !(T <: AbstractFloat) if !(T <: AbstractFloat)
throw(ArgumentError("All elements must be convertible to an AbstractFloat")) throw(ArgumentError("All elements must be convertible to an AbstractFloat"))
end end
new{T}(x, y, z) new{T}(x, y, z)
end end
end end
similar_type(::Type{<:Direction}, ::Type{T}, s::Size{(3,)}) where {T} = Direction{T}
""" """
Fallback constructor to show a proper error message. Fallback constructor to show a proper error message.
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment