diff --git a/src/Geometry/Primitives/AsphericSurface.jl b/src/Geometry/Primitives/AsphericSurface.jl index aaf74dfa5..e30564b40 100644 --- a/src/Geometry/Primitives/AsphericSurface.jl +++ b/src/Geometry/Primitives/AsphericSurface.jl @@ -58,7 +58,7 @@ struct AsphericSurface{T,N,Q,M} <: ParametricSurface{T,N} @assert one(T) - (1 / radius)^2 * (conic + one(T)) * semidiameter^2 > 0 "Invalid surface (conic/radius combination: $radius, $conic)" acs = [] - if aspherics===nothing || aspherics == [] #AxisymmetricOpticalSystem sends a null array + if aspherics===nothing #|| aspherics == [] #AxisymmetricOpticalSystem sends a null array M = CONIC else asphericTerms = [i for (i, ) in aspherics] diff --git a/src/Optical/OpticalSystem.jl b/src/Optical/OpticalSystem.jl index c9d9d5538..9680ecabb 100644 --- a/src/Optical/OpticalSystem.jl +++ b/src/Optical/OpticalSystem.jl @@ -279,6 +279,8 @@ function get_front_back_property(prescription::DataFrame, rownum::Int, property: return replace(properties, missing => default) end +turnEmptyIntoNothing(list) = length(list)==0 ? Nothing : list + """ AxisymmetricOpticalSystem{T,C<:CSGOpticalSystem{T}} <: AbstractOpticalSystem{T} @@ -374,12 +376,21 @@ struct AxisymmetricOpticalSystem{T,C<:CSGOpticalSystem{T}} <: AbstractOpticalSys frontaspherics::Vector{Pair{Int,T}}, backaspherics::Vector{Pair{Int,T}} = [ [parse(Int, k) => v for (k, v) in params] for params in [frontparams, backparams] ] - - newelement = AsphericLens( - material, vertices[i-1], frontradius, frontconic, frontaspherics, backradius, backconic, - backaspherics, thickness, semidiameter; lastmaterial, nextmaterial, frontsurfacereflectance, - backsurfacereflectance - )() + + fa = turnEmptyIntoNothing(frontaspherics) + ba = turnEmptyIntoNothing(backaspherics) + if fa === nothing && ba === nothing #it should be a CONIC. Note: if aspheric terms are present but all zero then an AshpericLens will be created + newelement = ConicLens( + material, vertices[i-1], frontradius, frontconic, backradius, backconic, thickness, + semidiameter; lastmaterial, nextmaterial, frontsurfacereflectance, backsurfacereflectance + )() + else + newelement = AsphericLens( + material, vertices[i-1], frontradius, frontconic, fa, backradius, backconic, + ba, thickness, semidiameter; lastmaterial, nextmaterial, frontsurfacereflectance, + backsurfacereflectance + )() + end else error( "Unsupported surface type \"$surface_type\". If you'd like to add support for this surface, ",