Fix division by zero case in dualcon.
authorNicholas Bishop <nicholasbishop@gmail.com>
Tue, 8 May 2012 22:11:16 +0000 (22:11 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Tue, 8 May 2012 22:11:16 +0000 (22:11 +0000)
intern/dualcon/intern/Projections.h

index be49fafb310914fc41535f9f3a88006e34488236..7740b0d16348097e333bfa6289ee1dd0ff536e16 100644 (file)
@@ -783,19 +783,17 @@ float getIntersectionPrimary(int edgeInd)
        LONG proj0 = cubeProj[i][0];
        LONG proj1 = cubeProj[i][0] + cubeProj[i][edgeInd + 1];
        LONG proj2 = inherit->trigProj[i][1];
+       LONG d = proj1 - proj0;
+       double alpha;
 
-       // double alpha = (double)( ( proj2 - proj0 ) * cubeProj[edgeInd][edgeInd + 1] ) / (double)( proj1 - proj0 ) ;
-       double alpha = (double)( (proj2 - proj0) ) / (double)(proj1 - proj0);
-
-       if (alpha < 0)
-       {
+       if (d == 0)
                alpha = 0.5;
-       }
-       else if (alpha > 1)
-       {
-               alpha = 0.5;
-       }
+       else {
+               alpha = (double)((proj2 - proj0)) / (double)d;
 
+               if (alpha < 0 || alpha > 1)
+                       alpha = 0.5;
+       }
 
        return (float)alpha;
 };