Skip to content

Commit

Permalink
Validate the length of the input Zernike expansion coefficient vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Sagnac committed Jun 19, 2023
1 parent 3f89d92 commit 4e6120d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/ScaleAperture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ https://www.jeos.org/index.php/jeos_rp/article/view/07012

function Π(v::Vector{T}, ε::T) where T <: Float64
!(0.0 ε 1.0) && error("Bounds: 0.0 ≤ ε ≤ 1.0\n")
j_max::Int = length(v) - 1
n_max::Int = get_n(j_max)
v2 = Vector{Float64}(undef, j_max + 1)
len, n_max = validate_length(v)
v2 = Vector{Float64}(undef, len)
n = 0
m = 0
for i in eachindex(v)
Expand Down
3 changes: 1 addition & 2 deletions src/TransformAperture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ const ei = cis # ei(x) = exp(im*x)
function S(v::Vector{T}, ε::T, δ::Complex{T}, ϕ::T, ω::Tuple{T,T}) where T <: Float64
!(0.0 ε + abs(δ) 1.0) && error("Bounds: 0.0 ≤ ε + |δ| ≤ 1.0\n")
!(0.0 < ω[1] 1.0) && error("Bounds: 0.0 < ω[1] ≤ 1.0\n")
len = length(v)
n_max = get_n(len - 1)
len, n_max = validate_length(v)
remap = Dict{Tuple{Int, Int}, Int}()
order = Tuple{Int, Int, Int}[]
# normalization factors for complex Zernike polynomials
Expand Down
16 changes: 16 additions & 0 deletions src/Zernike.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function noll_to_j(noll::Int)
end

function standardize!(noll::Vector)
validate_length(noll)
invpermute!(noll, [noll_to_j(i) + 1 for i in eachindex(noll)])
end

Expand Down Expand Up @@ -130,6 +131,21 @@ function standardize(fringe::Vector)
return a
end

function validate_length(v::Vector)
len = length(v)
j_max = len - 1
n_max = get_n(j_max)
if j_max get_j(n_max, n_max)
error(
"""
Invalid number of coefficients.
Coefficients for Zernike polynomials up to m = n_max, n = n_max required.
"""
)
end
return len, n_max
end

function radicand(m, n)
# Kronecker delta δ_{m0}
δ(m) = m == 0
Expand Down

0 comments on commit 4e6120d

Please sign in to comment.