diff --git a/src/ScaleAperture.jl b/src/ScaleAperture.jl index 17c9eb6..c5e9043 100644 --- a/src/ScaleAperture.jl +++ b/src/ScaleAperture.jl @@ -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) diff --git a/src/TransformAperture.jl b/src/TransformAperture.jl index 9191f3c..ba140e7 100644 --- a/src/TransformAperture.jl +++ b/src/TransformAperture.jl @@ -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 diff --git a/src/Zernike.jl b/src/Zernike.jl index c3ba93e..2ac4dfb 100644 --- a/src/Zernike.jl +++ b/src/Zernike.jl @@ -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 @@ -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