Repository: DCC-Lab/RayTracing

Issue:
Generating unnecessary images 
illumination = ImagingPath()

illumination.append(Space(d=10))
illumination.append(Lens(f=10, diameter=100, label="Collector"))
illumination.append(Space(d=10+30))
illumination.append(Lens(f=30, diameter=100, label="Condenser"))
illumination.append(Space(d=30+7))
illumination.append(Lens(f=7, diameter=100, label="Objective"))
illumination.append(Space(d=7+30))
illumination.append(Lens(f=30, diameter=100, label="Tube"))
illumination.append(Space(d=30+10))
illumination.append(Lens(f=10, diameter=100, label="Eyepiece"))
illumination.append(Space(d=10))
illumination.append(Aperture(diameter=20, label="Eye entrance"))
illumination.append(Space(d=10))

illumination.display(limitObjectToFieldOfView=True, onlyChiefAndMarginalRays=True)

Gives this : 

![what](https://user-images.githubusercontent.com/40174887/83067914-71223700-a035-11ea-865e-819e0cc073fc.png)

Because of this : 

![image (1)](https://user-images.githubusercontent.com/40174887/83067938-7aab9f00-a035-11ea-8d95-b2aab1c2b0db.png)


Comments:

Patch:
diff --git a/raytracing/figure.py b/raytracing/figure.py
index a0b9014..dee5eb4 100644
--- a/raytracing/figure.py
+++ b/raytracing/figure.py
@@ -180,6 +180,8 @@ class Figure:
         conjugates = self.path.intermediateConjugates()
         if len(conjugates) != 0:
             for (planePosition, magnification) in conjugates:
+                if not 0 <= planePosition <= self.path.L:
+                    continue
                 magnification = abs(magnification)
                 if displayRange < self.path._objectHeight * magnification:
                     displayRange = self.path._objectHeight * magnification


Test patch:
diff --git a/raytracing/tests/envtest.py b/raytracing/tests/envtest.py
index c20889c..5a57a3b 100644
--- a/raytracing/tests/envtest.py
+++ b/raytracing/tests/envtest.py
@@ -5,7 +5,6 @@ import tempfile
 
 class RaytracingTestCase(unittest.TestCase):
     tempDir = os.path.join(tempfile.gettempdir(), "tempDir")
-    removeAlreadyExists = False
 
     def __init__(self, tests=()):
         super(RaytracingTestCase, self).__init__(tests)
@@ -13,13 +12,7 @@ class RaytracingTestCase(unittest.TestCase):
     @classmethod
     def createTempDirectory(cls):
         if os.path.exists(cls.tempDir):
-            if cls.removeAlreadyExists:
-                cls.deleteTempDirectory()
-            else:
-                fulltempDir = os.path.join(os.getcwd(), cls.tempDir)
-                msg = f"'{fulltempDir}' directory already exists. " \
-                    f"Please set RaytracingTestCase.removeAlreadyExists to True if you want to delete this directory."
-                raise FileExistsError(msg)
+            cls.deleteTempDirectory()
         os.mkdir(cls.tempDir)
 
     @classmethod
diff --git a/raytracing/tests/testsEnvtest.py b/raytracing/tests/testsEnvtest.py
index dc54551..cb0ae26 100644
--- a/raytracing/tests/testsEnvtest.py
+++ b/raytracing/tests/testsEnvtest.py
@@ -55,27 +55,8 @@ class TestEnvtestClass(unittest.TestCase):
     def testTemptempDir(self):
         self.assertTrue(self.tempDir.endswith("tempDir"))
 
-    def testRemoveAlreadyExistsFalse(self):
-        envtest.RaytracingTestCase.removeAlreadyExists = False
-        self.assertFalse(envtest.RaytracingTestCase.removeAlreadyExists)
-
-    def testRemoveAlreadyExistsTrue(self):
-        envtest.RaytracingTestCase.removeAlreadyExists = True
-        self.assertTrue(envtest.RaytracingTestCase.removeAlreadyExists)
-
-    def testCreateTempDirectoryAlreadyExistsDoNotDelete(self):
-        msg = f"'{self.tempDir}' directory already exists. Please set RaytracingTestCase.removeAlreadyExists to True if"
-        msg += f" you want to delete this directory."
-        envtest.RaytracingTestCase.removeAlreadyExists = False
-        os.mkdir(self.tempDir)
-        with self.assertRaises(FileExistsError) as context:
-            envtest.RaytracingTestCase.createTempDirectory()
-        self.assertEqual(str(context.exception), msg)
-        os.rmdir(self.tempDir)  # Delete the directory!
-
     def testCreateTempDirectoryAlreadyExistsAndDelete(self):
         tempDir = envtest.RaytracingTestCase.tempDir
-        envtest.RaytracingTestCase.removeAlreadyExists = True
         os.mkdir(tempDir)
         try:
             envtest.RaytracingTestCase.createTempDirectory()
diff --git a/raytracing/tests/testsFigure.py b/raytracing/tests/testsFigure.py
index daf1098..0c29ffd 100644
--- a/raytracing/tests/testsFigure.py
+++ b/raytracing/tests/testsFigure.py
@@ -14,12 +14,12 @@ class TestFigure(unittest.TestCase):
 
         self.assertEqual(path.figure.displayRange(), largestDiameter)
 
-    def testDisplayRange(self):
+    def testDisplayRangeImageOutOfView(self):
         path = ImagingPath()
         path.append(Space(2))
         path.append(CurvedMirror(-5, 10))
 
-        self.assertAlmostEqual(path.figure.displayRange(), 5 * 10)
+        self.assertAlmostEqual(path.figure.displayRange(), 20)
 
         path.objectHeight = 1
         self.assertEqual(path.figure.displayRange(), 10)