Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Commit

Permalink
Fix new emitter switch (#151)
Browse files Browse the repository at this point in the history
* rename example files

* fix MaybeVector and add maybe.jl with docs

* fix zoom lens @show syss[1] typo
  • Loading branch information
alfredclwong authored Apr 28, 2021
1 parent 9aa3416 commit 3dbe82a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mdparse(@code_string draw_zoomlenses()) # hide
```

```@example example
syss = draw_zoomlenses(["assets/zoom$i.png" for i in 1:3]); @show sys[1]; nothing # hide
syss = draw_zoomlenses(["assets/zoom$i.png" for i in 1:3]); @show syss[1]; nothing # hide
```

![Zoom position 1 visualization](assets/zoom1.png)
Expand Down
4 changes: 2 additions & 2 deletions src/Examples/Examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using Unitful
using Plots
using LinearAlgebra

include("docs.jl")
include("other.jl")
include("docs_examples.jl")
include("other_examples.jl")

end #module Examples
export Examples
4 changes: 2 additions & 2 deletions src/Examples/docs.jl → src/Examples/docs_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function draw_cooketriplet(filename::Maybe{AbstractString} = nothing)
return sys
end

function draw_zoomlenses(filenames::MaybeVector{AbstractString} = cycle([nothing]))
function draw_zoomlenses(filenames::MaybeVector{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]
Expand Down Expand Up @@ -220,7 +220,7 @@ function draw_multiHOE(filename::Maybe{AbstractString} = nothing)
return nothing
end

function draw_stackedbeamsplitters(filenames::MaybeVector{AbstractString} = cycle([nothing]))
function draw_stackedbeamsplitters(filenames::MaybeVector{AbstractString} = repeat([nothing], 3))
# ReflectOrTransmit: nondeterministic
# Transmit: deterministic, all beamsplitters transmissive
# Reflect: deterministic, all beamsplitters reflective
Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions src/OpticSim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# See LICENSE in the project root for full license information.

module OpticSim
export Maybe, MaybeVector

import Unitful
using LinearAlgebra: eigen, svd, I, qr, dot, cross, norm, det, normalize, inv
Expand All @@ -19,14 +18,13 @@ using Revise
import GLMakie
import Makie.AbstractPlotting

const Maybe{T} = Union{T, Nothing}
const MaybeVector{T} = Union{Vector{<:T}, Iterators.Cycle{Vector{Nothing}}}
include("maybe.jl")
include("constants.jl")
include("utilities.jl")

include("GlassCat/GlassCat.jl")
import OpticSim.GlassCat: plot_indices, index, polyfit_indices, absairindex, absorption, info, glassid, glassname, glassforid, isair, findglass, modelglass, glassfromMIL, GlassID
import .GlassCat: plot_indices, index, polyfit_indices, absairindex, absorption, info, glassid, glassname, glassforid, isair, findglass, modelglass, glassfromMIL, GlassID

include("constants.jl")
include("utilities.jl")
include("Geometry/Geometry.jl")
include("Optical/Optical.jl")
include("Vis/Vis.jl")
Expand Down
21 changes: 21 additions & 0 deletions src/maybe.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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}}

0 comments on commit 3dbe82a

Please sign in to comment.