0024206: Exception is raised in the STEP loopback tests.
[occt.git] / src / ShapeAnalysis / ShapeAnalysis_Curve.cxx
index 9ec8432..4553e42 100755 (executable)
@@ -176,27 +176,46 @@ Standard_Real ShapeAnalysis_Curve::Project(const Adaptor3d_Curve& C3D,
                                           const Standard_Boolean AdjustToEnds) const
 
 {
+
   Standard_Real uMin = C3D.FirstParameter();
   Standard_Real uMax = C3D.LastParameter();
-  Standard_Real distmin;
-  if (!Precision::IsInfinite(uMin)||!Precision::IsInfinite(uMax)) {
-    Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end
-    gp_Pnt LowBound = C3D.Value(uMin);
-    gp_Pnt HigBound = C3D.Value(uMax);
-    distmin = LowBound.Distance(P3D);
-    if (distmin <= prec) {
-      param = uMin;
-      proj  = LowBound;
-      return distmin;
-    }
-    distmin = HigBound.Distance(P3D);
-    if (distmin <= prec) {
-      param = uMax;
-      proj  = HigBound;
-      return distmin;
-    } 
+  
+  if (Precision::IsInfinite(uMin) && Precision::IsInfinite(uMax))
+    return ProjectAct(C3D, P3D, preci, proj, param);
+
+  Standard_Real distmin_L = Precision::Infinite(), distmin_H = Precision::Infinite();
+  Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end
+  gp_Pnt LowBound = C3D.Value(uMin);
+  gp_Pnt HigBound = C3D.Value(uMax);
+  distmin_L = LowBound.Distance(P3D);
+  distmin_H = HigBound.Distance(P3D);
+
+  if (distmin_L <= prec) {
+    param = uMin;
+    proj  = LowBound;
+    return distmin_L;
   }
-  return ProjectAct(C3D, P3D, preci, proj, param);
+
+  if (distmin_H <= prec) {
+    param = uMax;
+    proj  = HigBound;
+    return distmin_H;
+  } 
+
+  Standard_Real distProj = ProjectAct(C3D, P3D, preci, proj, param);
+  if(  distProj < distmin_L +  Precision::Confusion() && distProj < distmin_H +  Precision::Confusion())
+    return distProj;
+
+  if( distmin_L < distmin_H)
+  {
+    param = uMin;
+    proj  = LowBound;
+    return distmin_L;
+  }
+  param = uMax;
+  proj  = HigBound;
+  return distmin_H;
+
 }
 
 //=======================================================================
@@ -212,6 +231,7 @@ Standard_Real ShapeAnalysis_Curve::ProjectAct(const Adaptor3d_Curve& C3D,
        
 {
   Standard_Boolean OK = Standard_False;
+  param = 0.;
   try {
     OCC_CATCH_SIGNALS
     Extrema_ExtPC myExtPC(P3D,C3D);
@@ -234,11 +254,11 @@ Standard_Real ShapeAnalysis_Curve::ProjectAct(const Adaptor3d_Curve& C3D,
     Standard_Failure::Caught()->Print(cout); cout << endl;
 #endif
   }
-
+  
   //szv#4:S4163:12Mar99 moved
   Standard_Real uMin = C3D.FirstParameter(), uMax = C3D.LastParameter();
   Standard_Boolean closed = Standard_False;  // si on franchit les bornes ...
-  Standard_Real distmin = RealLast(), valclosed = 0.;
+  Standard_Real distmin = Precision::Infinite(), valclosed = 0.;
   Standard_Real aModParam = param;
   Standard_Real aModMin = distmin;
   
@@ -386,7 +406,7 @@ Standard_Real ShapeAnalysis_Curve::NextProject(const Standard_Real paramPrev,
 {
   Standard_Real uMin = (cf < cl ? cf : cl);
   Standard_Real uMax = (cf < cl ? cl : cf);
-  Standard_Real distmin;
+  Standard_Real distmin = Precision::Infinite();
   if (C3D->IsKind(STANDARD_TYPE(Geom_BoundedCurve))) {
     Standard_Real prec = ( AdjustToEnds ? preci : Precision::Confusion() ); //:j8 abv 10 Dec 98: tr10_r0501_db.stp #9423: protection against densing of points near one end
     gp_Pnt LowBound = C3D->Value(uMin);