From ef69993b72df3678f301ff4542c9b34e79e39584 Mon Sep 17 00:00:00 2001
From: Tamas Gal <himself@tamasgal.com>
Date: Tue, 25 Mar 2025 16:03:36 +0100
Subject: [PATCH] Fix Direction constructor and improve Position

---
 src/KM3io.jl | 3 ++-
 src/types.jl | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/KM3io.jl b/src/KM3io.jl
index fd1c11e7..9574f437 100644
--- a/src/KM3io.jl
+++ b/src/KM3io.jl
@@ -23,7 +23,8 @@ const version = let
 end
 
 using DocStringExtensions
-using StaticArrays: FieldVector, @SArray, SVector
+using StaticArrays: FieldVector, @SArray, SVector, Size
+import StaticArrays: similar_type
 import UnROOT
 
 using HDF5
diff --git a/src/types.jl b/src/types.jl
index 1da7b7cc..f25db0e9 100644
--- a/src/types.jl
+++ b/src/types.jl
@@ -12,6 +12,7 @@ struct Position{T} <: FieldVector{3, T}
     y::T
     z::T
 end
+similar_type(::Type{<:Position}, ::Type{T}, s::Size{(3,)}) where {T} = Position{T}
 
 """
 A vector to represent a direction in 3D.
@@ -20,14 +21,16 @@ struct Direction{T<:AbstractFloat} <: FieldVector{3, T}
     x::T
     y::T
     z::T
-    function Direction(x, y, z)
-        T = promote_type(typeof(x), typeof(y), typeof(z))
+    function Direction{U}(x, y, z) where U
+        T = promote_type(typeof(x), typeof(y), typeof(z), U)
         if !(T <: AbstractFloat)
             throw(ArgumentError("All elements must be convertible to an AbstractFloat"))
         end
         new{T}(x, y, z)
     end
 end
+similar_type(::Type{<:Direction}, ::Type{T}, s::Size{(3,)}) where {T} = Direction{T}
+
 """
 Fallback constructor to show a proper error message.
 """
-- 
GitLab