Incorporate units into custom types

You’d want to make the change to replace one(T)*unit(T) with oneunit(t) which is in Base.

using LinearAlgebra, StaticArrays
using Unitful
using Unitful: μm

mutable struct Ray{T, S}
    origin::SVector{3, T}
    direction::SVector{3, S}
    intensity::T
end
Ray(o::SVector{3, T}, d::SVector{3, T}) where {T} = Ray(o, normalize(d), oneunit(T))

I’d also point out there is a potential pitfall to assigning Unitful units. For instance, the rays a and b are equivalent, but the promotion will cause issues.

Ray(o::SVector{3},d::SVector{3}) = Ray(promote(o,d)...)

a=SVector(1.0μm, 2.0μm, 3.0μm)
b=SVector(1e-6u"m", 2e-6u"m", 3e-6u"m")

a==b #true
A=Ray(a,a)
B=Ray(a,b)

A==B #false
A.origin==B.origin #true
A.direction==B.direction #true
A.intensity==B.intensity #false intensity of 1μm ≠ 1m