Salome HOME
PAL10173. Protect computeParamByFunc() against divisionby zero when f(0)=0 and agains...
authoreap <eap@opencascade.com>
Tue, 15 Nov 2005 08:53:15 +0000 (08:53 +0000)
committereap <eap@opencascade.com>
Tue, 15 Nov 2005 08:53:15 +0000 (08:53 +0000)
src/StdMeshers/StdMeshers_Regular_1D.cxx

index 2bdf91da96956ac58406489b7ecdb57d4b526be3..c9765f03919b2a77be06104ea1435a7f74619675 100644 (file)
@@ -426,6 +426,11 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
 {
   if (!func.IsReady())
     return false;
 {
   if (!func.IsReady())
     return false;
+
+  // ########## TMP until pb division by zero when func(0.0)==0 is fixed #########
+  if (::Abs(func(0.0)) <= ::RealSmall() ) return false;
+  // ########## TMP until pb division by zero when func(0.0)==0 is fixed #########
+
   vector<double> xxx[2];
   int nbPnt = 1 + nbSeg;
   int rev, i;
   vector<double> xxx[2];
   int nbPnt = 1 + nbSeg;
   int rev, i;
@@ -465,6 +470,8 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
         // Decrease x1 ...
         x1_too_large = x1;
         x1 = (x1_too_small+x1_too_large)/2;
         // Decrease x1 ...
         x1_too_large = x1;
         x1 = (x1_too_small+x1_too_large)/2;
+        if ( x1 <= ::RealSmall() )
+          return false; // break infinite loop
         continue;
       }
 
         continue;
       }
 
@@ -516,7 +523,7 @@ static bool computeParamByFunc(Adaptor3d_Curve& C3d, double first, double last,
       return false;
     prevU = U;
   }
       return false;
     prevU = U;
   }
-  return false;
+  return true;
 }
 
 //=============================================================================
 }
 
 //=============================================================================