From 6b11bd468421941177ea4add1fc8a122202d2a30 Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Fri, 30 Apr 2021 10:51:13 +0100 Subject: [PATCH 1/2] remove Maybe and MaybeVector fixes #160 --- src/Examples/docs_examples.jl | 16 ++++++++-------- src/Geometry/Ray.jl | 2 +- src/GlassCat/sources.jl | 10 ++++------ src/maybe.jl | 21 --------------------- 4 files changed, 13 insertions(+), 36 deletions(-) delete mode 100644 src/maybe.jl diff --git a/src/Examples/docs_examples.jl b/src/Examples/docs_examples.jl index 0de3eb662..4be52e69c 100644 --- a/src/Examples/docs_examples.jl +++ b/src/Examples/docs_examples.jl @@ -5,7 +5,7 @@ # Group examples that are used in the docs (examples.md) export draw_cooketriplet, draw_schmidtcassegraintelescope, draw_lensconstruction, draw_zoomlenses, draw_HOEfocus, draw_HOEcollimate, draw_multiHOE, draw_stackedbeamsplitters -function draw_cooketriplet(filename::Maybe{AbstractString} = nothing) +function draw_cooketriplet(filename::Union{Nothing,AbstractString} = nothing) g1, g2 = SCHOTT.N_SK16, SCHOTT.N_SF2 sys = AxisymmetricOpticalSystem{Float64}(DataFrame( Surface = [:Object, 1, 2, 3, :Stop, 5, 6, :Image ], @@ -30,7 +30,7 @@ function draw_cooketriplet(filename::Maybe{AbstractString} = nothing) return sys end -function draw_zoomlenses(filenames::MaybeVector{AbstractString} = repeat([nothing], 3)) +function draw_zoomlenses(filenames::Vector{<:Union{Nothing,AbstractString}} = repeat([nothing], 3)) stops = [2.89, 3.99, 4.90] zooms = [9.48, 4.48, 2.00] dists = [4.46970613, 21.21, 43.81] @@ -57,7 +57,7 @@ function draw_zoomlenses(filenames::MaybeVector{AbstractString} = repeat([nothin return syss end -function draw_schmidtcassegraintelescope(filename::Maybe{AbstractString} = nothing) +function draw_schmidtcassegraintelescope(filename::Union{Nothing,AbstractString} = nothing) # glass entrance lens on telescope topsurf = Plane( SVector(0.0, 0.0, 1.0), @@ -105,7 +105,7 @@ function draw_schmidtcassegraintelescope(filename::Maybe{AbstractString} = nothi return nothing end -function draw_lensconstruction(filename::Maybe{AbstractString} = nothing) +function draw_lensconstruction(filename::Union{Nothing,AbstractString} = nothing) topsurface = leaf( AcceleratedParametricSurface( QTypeSurface( @@ -142,7 +142,7 @@ function draw_lensconstruction(filename::Maybe{AbstractString} = nothing) return nothing end -function draw_HOEfocus(filename::Maybe{AbstractString} = nothing) +function draw_HOEfocus(filename::Union{Nothing,AbstractString} = nothing) rect = Rectangle(5.0, 5.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, 0.0)) int = HologramInterface( SVector(0.0, -3.0, -20.0), ConvergingBeam, @@ -165,7 +165,7 @@ function draw_HOEfocus(filename::Maybe{AbstractString} = nothing) return nothing end -function draw_HOEcollimate(filename::Maybe{AbstractString} = nothing) +function draw_HOEcollimate(filename::Union{Nothing,AbstractString} = nothing) rect = Rectangle(5.0, 5.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, 0.0)) int = HologramInterface( SVector(0.1, -0.05, -1.0), CollimatedBeam, @@ -188,7 +188,7 @@ function draw_HOEcollimate(filename::Maybe{AbstractString} = nothing) return nothing end -function draw_multiHOE(filename::Maybe{AbstractString} = nothing) +function draw_multiHOE(filename::Union{Nothing,AbstractString} = nothing) rect = Rectangle(5.0, 5.0, SVector(0.0, 0.0, 1.0), SVector(0.0, 0.0, 0.0)) int1 = HologramInterface( SVector(-5.0, 0.0, -20.0), ConvergingBeam, @@ -220,7 +220,7 @@ function draw_multiHOE(filename::Maybe{AbstractString} = nothing) return nothing end -function draw_stackedbeamsplitters(filenames::MaybeVector{AbstractString} = repeat([nothing], 3)) +function draw_stackedbeamsplitters(filenames::Vector{<:Union{Nothing,AbstractString}} = repeat([nothing], 3)) # ReflectOrTransmit: nondeterministic # Transmit: deterministic, all beamsplitters transmissive # Reflect: deterministic, all beamsplitters reflective diff --git a/src/Geometry/Ray.jl b/src/Geometry/Ray.jl index a642a8f9b..44de7eaca 100644 --- a/src/Geometry/Ray.jl +++ b/src/Geometry/Ray.jl @@ -75,7 +75,7 @@ function closestpointonray(r::AbstractRay{T,N}, point::SVector{N,T}) where {T,N} end """ - distance(r::Ray{T,N}, point::SVector{N,T}) -> Union{T,Nothing} + distance(r::Ray{T,N}, point::SVector{N,T}) -> Union{Nothing,T} Returns distance to the position on the ray closest to point. If t < 0 returns nothing. """ diff --git a/src/GlassCat/sources.jl b/src/GlassCat/sources.jl index 7b8ab4c2a..2e2ab7586 100644 --- a/src/GlassCat/sources.jl +++ b/src/GlassCat/sources.jl @@ -7,16 +7,14 @@ import SHA import ZipFile using Pkg -const Maybe{T} = Union{T, Nothing} - """ - add_agf(sourcefile::AbstractString; name::Maybe{AbstractString} = nothing, rebuild::Bool = true) + add_agf(sourcefile::AbstractString; name::Union{Nothing,AbstractString} = nothing, rebuild::Bool = true) Adds an already downloaded AGF file to the sourcelist at data/sources.txt, generating the SHA256 checksum automatically. Optionally provide a `name` for the corresponding module, and `rebuild` AGFGlassCat.jl by default. """ -function add_agf(sourcefile::AbstractString; name::Maybe{AbstractString} = nothing, rebuild::Bool = true) +function add_agf(sourcefile::AbstractString; name::Union{Nothing,AbstractString} = nothing, rebuild::Bool = true) if !isfile(sourcefile) @error "AGF file not found at $sourcefile" return @@ -101,11 +99,11 @@ function verify_source(sourcefile::AbstractString, sha256sum::AbstractString) end """ - download_source(sourcefile::AbstractString, url::AbstractString, POST_data::Maybe{AbstractString} = nothing) + download_source(sourcefile::AbstractString, url::AbstractString, POST_data::Union{Nothing,AbstractString} = nothing) Download and unzip an AGF glass catalog from a publicly available source. Supports POST requests. """ -function download_source(sourcefile::AbstractString, url::AbstractString, POST_data::Maybe{AbstractString} = nothing) +function download_source(sourcefile::AbstractString, url::AbstractString, POST_data::Union{Nothing,AbstractString} = nothing) @info "Downloading source file from $url" try headers = ["Content-Type" => "application/x-www-form-urlencoded"] diff --git a/src/maybe.jl b/src/maybe.jl deleted file mode 100644 index d3ca18bcb..000000000 --- a/src/maybe.jl +++ /dev/null @@ -1,21 +0,0 @@ -# MIT license -# Copyright (c) Microsoft Corporation. All rights reserved. -# See LICENSE in the project root for full license information. - -export Maybe, MaybeVector - -""" -Haskell-style [option type](https://en.wikipedia.org/wiki/Option_type) primarily used to allow optional inputs/outputs -for functions. - -For example, in `src/Examples/docs_examples.jl`, we have `draw_cooketriplet(filename::Maybe{AbstractString} = nothing)`. -If the function is called with a `filename` argument, then it is passed as a string, and `Vis.save(filename)` saves an -image of the drawn example. If there is no argument, then the save call is dispatched to the empty `function -Vis.save(::Nothing) end`. This allows the user to run the example without saving a file. -""" -const Maybe{T} = Union{T, Nothing} - -""" -Extension of `Maybe{T}` which allows things like `[nothing, 1, 1.0, nothing] isa MaybeVector{Real}` -""" -const MaybeVector{T} = Vector{<:Maybe{T}} From 5ff29a741115ad87c8fa090406be9d08ff84a637 Mon Sep 17 00:00:00 2001 From: Alfred Wong Date: Fri, 30 Apr 2021 11:15:12 +0100 Subject: [PATCH 2/2] remove include statement --- src/OpticSim.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpticSim.jl b/src/OpticSim.jl index 91b90245c..d556b67d5 100644 --- a/src/OpticSim.jl +++ b/src/OpticSim.jl @@ -21,7 +21,6 @@ using Revise import GLMakie import Makie.AbstractPlotting -include("maybe.jl") include("constants.jl") include("utilities.jl")