Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: division by 0 in marginalRays
When we have an `ImagingPath` that has a transfer matrix to the aperture stop with `B == 0`, there is a division by 0 in the calculations of theta + and -. We should check when it's the case and return `None`.

Discussion:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index 6c89bff..b9ee7de 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -260,6 +260,9 @@ class ImagingPath(MatrixGroup):
         A = transferMatrixToApertureStop.A
         B = transferMatrixToApertureStop.B
 
+        if transferMatrixToApertureStop.isImaging:
+            return None
+
         thetaUp  = (stopDiameter / 2.0 - A * y) / B
         thetaDown = (-stopDiameter / 2.0 - A * y) / B
 


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index 2e24ab7..be8f0e1 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,6 +61,11 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testMarginalRaysIsImaging(self):
+        path = ImagingPath(System4f(10, 10))
+        path.append(Aperture(10))
+        self.assertIsNone(path.marginalRays())
+
     def testImageSizeDIs0(self):
         path = ImagingPath(System2f(f=10, diameter=10))
         path.append(Aperture(20))