-
Notifications
You must be signed in to change notification settings - Fork 40
Fix bug when empty array passed to AsphericSurface #323
Conversation
Codecov Report
@@ Coverage Diff @@
## main #323 +/- ##
==========================================
- Coverage 55.11% 55.08% -0.04%
==========================================
Files 79 79
Lines 7267 7273 +6
==========================================
+ Hits 4005 4006 +1
- Misses 3262 3267 +5
Continue to review full report at Codecov.
|
The aspherics argument to AsphericLens and AsphericSurface both look like this:
The intent is that the argument should either be a non-empty vector or nothing. Rather than fixing the problem in AsphericSurface it might be more consistent to fix it in the call to AsphericLens from the constructor of AxisymmetricOpticalSystem, line 378 in OpticalSystem.jl:
Presumably one or both of An alternative would be to modify the constructor of AsphericSurface so instead of this:
the argument is this:
along with a change in the documentation saying that zero length vector inputs are acceptable. But that would change the interface of this function so we'd need to track down all the calls to AsphericSurface to make sure they were consistent. @friggog do you have an opinion? |
I agree this change should be made in the caller not the constructor definition as it is now |
@BrianGun, thanks for the suggestion. I'm working on a fix to |
@mattderstine Are you talking about the case when the surface is a conic? It looks like Spherical lenses are properly special cased to faster analytic intersection code, but conics are handled by AcceleratedParametricSurface, which will be much slower than an analytic intersection with a conic. Looks like the proper place to add this is in the AsphericLens function, which is where the special casing for spherical and aspherical surfaces currently is computed. We could add conics. Do you want to tackle this? I'd love to do it but I'm up to my eyeballs writing lenslet code. Ray conic surface intersection doesn't look too difficult, here's one reference among many others: http://skuld.bmsc.washington.edu/people/merritt/graphics/quadrics.html. |
@BrianGun I've removed the test in I can think about adding conics. My own raytrace code already has the equations for this. I follow the method from Welford's book, Aberrations of Optical Systems, but used Mathematica to find equations that look more like the spherical intersection equations that he derived. No promises on timing. I'd like to finish a solution (more of an alternate approach) for the problem with plotting of 2D concave surfaces and then see if I can properly visualize and analyze the cell phone camera lens from Chipman's book. I'm taking the long route to getting to the polarization code by attempting to implement stuff that others can use rather than just do work arounds along the way. |
@mattderstine is this the error you are seeing?
if so this error is because the array In AsphericLens() the code is making it to the part where an AcceleratedParametricSurface is created but the aspherics argument is an empty array:
|
That is the error that I was originally fixing. It happens because the code in
This seems to match to me. The flagged error is on the second Union{} where the call has a |
@mattderstine Not sure why I don't have the latest version of your PR. Not enough git fu on my part. |
I'm just faking it with git so it might be something that I did. I do see the commits(b7277e3) in this PR. |
@mattderstine found the error. Your function
is returning the type Nothing rather than the value nothing, which is the only instance of Nothing. Then Nothing is passed as an argument to the AsphericLens constructor instead of nothing and the type checker complains. if you do this
it should fix this bug. |
@BrianGun Thanks! I now know much more about nothing. You code does fix the error and it works as expected. I have added an assert to the AsphericSurface constructor and I think all is ready for merge. I have also changed the AxisymmetricLens constructor so that it calls a ConicLens if the aspheric term vector is empty on both surfaces. This has no advantage now, but when ConicLens is upgraded to use a direct solve of the intersection this should be faster. |
Can we add a test for this case? Feel like it should have been caught earlier, otherwise looks good |
@friggog did you mean an assertion to detect if an empty array is passed to AsphericSurface? @mattderstine added this in the latest commit. |
I'm approving the PR. Thanks @mattderstine, once again for your contribution! |
AxisymmetricOpticalSystem passes an empty array of aspheric terms to AsphericSurface. This fix properly handles that case.