Repository: DCC-Lab/RayTracing

Issue:
ImagingPath: chiefRay doesn't return None when B is very close but not 0
When `B == 0` in an `ImagingPath` instance, there is no chief ray. But because we use a computer, some calculations can lead to something close to 0 but not quite 0. For example:
```python
path = ImagingPath(System4f(pi * 2, pi * 1.25)) # This is an imaging system with B = 0
path.append(System4f(pi, pi / 1.2)) # This is another imaging system with B = 0
path.append(Aperture(10))
self.assertIsNone(path.chiefRay()) # This fails because B is close to but not 0 (approx. -7e-16)
```

Discussion:

Patch:
diff --git a/raytracing/imagingpath.py b/raytracing/imagingpath.py
index aa348eb..5c3b21d 100644
--- a/raytracing/imagingpath.py
+++ b/raytracing/imagingpath.py
@@ -161,7 +161,7 @@ class ImagingPath(MatrixGroup):
         A = transferMatrixToApertureStop.A
         B = transferMatrixToApertureStop.B
 
-        if B == 0:
+        if transferMatrixToApertureStop.isImaging:
             return None
 
         if y is None:


Test patch:
diff --git a/raytracing/tests/testsImagingPath.py b/raytracing/tests/testsImagingPath.py
index a6b39da..4239a06 100644
--- a/raytracing/tests/testsImagingPath.py
+++ b/raytracing/tests/testsImagingPath.py
@@ -61,6 +61,12 @@ class TestImagingPath(unittest.TestCase):
         chiefRay = path.chiefRay()
         self.assertIsNone(chiefRay)
 
+    def testChiefRayBIs0(self):
+        path = ImagingPath(System4f(pi*2, pi*1.25))
+        path.append(System4f(pi, pi/1.2))
+        path.append(Aperture(10))
+        self.assertIsNone(path.chiefRay())
+
     def testChiefRayInfiniteFieldOfViewNoY(self):
         path = ImagingPath()
         path.append(System2f(10, path.maxHeight + 1))
@@ -81,5 +87,6 @@ class TestImagingPath(unittest.TestCase):
         path.append(Aperture(20))
         self.assertEqual(path.imageSize(), inf)
 
+
 if __name__ == '__main__':
     unittest.main()