Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: imageSize fails when D is 0
When `D == 0`, there is no forward conjugate (nor backward), so we return `conjugateMatrix` as `None`. Because of that, `imageSize` raises an `AttributeError`. We should check if `conjugateMatrix` is `None`, but what should we return? Since there is no image, return `None`?

Discussion:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index 9960d83..6c89bff 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -585,6 +585,9 @@ class ImagingPath(MatrixGroup):
         """
         fieldOfView = self.fieldOfView()
         (distance, conjugateMatrix) = self.forwardConjugate()
+        if conjugateMatrix is None:
+            return float("+inf")
+
         magnification = conjugateMatrix.A
         return abs(fieldOfView * magnification)
 


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index b543b8b..2e24ab7 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,5 +61,10 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testImageSizeDIs0(self):
+        path = ImagingPath(System2f(f=10, diameter=10))
+        path.append(Aperture(20))
+        self.assertEqual(path.imageSize(), inf)
+
 if __name__ == '__main__':
     unittest.main()