Skip to content

Commit

Permalink
Fixing some promotions in beam
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmaostc committed Sep 21, 2023
1 parent d6ee87a commit 814316e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/beam.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ GeometricBeam{Float64}(1.0, 0.0, 0.0)
zpos::T = zero(w) # position along beam axis
end

function GeometricBeam(; w=0.0, k=zero(w), zpos=zero(w))
w, k, zpos = promote(w, k, zpos)
return GeometricBeam{typeof(w)}(; w, k, zpos)
end

"""
struct GaussianBeam{T} <: AbstractBeam{T}
Expand Down Expand Up @@ -64,8 +68,10 @@ julia> GaussianBeam(w0=100e-6, z=12.0, n=1.0, λ=633e-9, zpos=0.0)
GaussianBeam{Float64}(12.0 + 0.049630215696521214im, 0.0, 1.0, 6.33e-7)
```
"""
GaussianBeam(; w0=100e-3, z=0.0, n=1.0, λ=633e-9, zpos=0.0) = GaussianBeam{typeof(w0)}(z + 1im ** n * w0^2) / (λ), zpos, n, λ)

function GaussianBeam(; w0=100e-3, z=0.0, n=1.0, λ=633e-9, zpos=0.0)
w0, z, n, λ, zpos = promote(w0, z, n, λ, zpos)
return GaussianBeam{typeof(w0)}(z + 1im ** n * w0^2) / (λ), zpos, n, λ)
end
"""
GaussianBeam(q; zpos, n=1.0, λ=633e-9)
Expand All @@ -78,7 +84,11 @@ julia> GaussianBeam(12 + 1im * 1.0 * π * 100e-6^2 / 633e-9)
GaussianBeam{Float64}(12.0 + 0.049630215696521214im, 0.0, 1.0, 6.33e-7)
```
"""
GaussianBeam(q; zpos=0.0, n=1.0, λ=633e-9) = GaussianBeam{real(typeof(q))}(q, zpos, n, λ)
function GaussianBeam(q; zpos=0.0, n=1.0, λ=633e-9)
zpos, n, λ = promote(zpos, n, λ)
q = Complex{typeof(zpos)}(q)
return GaussianBeam{real(typeof(q))}(q, zpos, n, λ)
end

"""
z(beam::GaussianBeam)
Expand Down

0 comments on commit 814316e

Please sign in to comment.