0024472: Wrong section curves
authornbv <nbv@opencascade.com>
Thu, 6 Feb 2014 07:12:09 +0000 (11:12 +0400)
committerapn <apn@opencascade.com>
Fri, 7 Feb 2014 07:15:22 +0000 (11:15 +0400)
1. Checking, if intersection curve is collapsed, is added. (file GeomInt_LineConstructor.cxx)
2. Earlier, intersection line was considered as valid if only mid-point of every interval of this line is into two intersected surfaces (with given tolerance). That's no good because after inserting of new points, old points, which is considered as valid only because they are into beginning or into end of interval (therefore, they was not checked), moved to mid of interval and became invalid. Therefore, checking for first and last points was added. (file GeomInt_LineConstructor.cxx)
3. Intersection line became valid (see bug description) after adding of new additional points into it (file IntPatch_PrmPrmIntersection.cxx). Methods for finding and adding of new points were added. (file IntWalk_PWalking_1.gxx)
Some test cases were changed.
Test cases for issue CR24472

src/GeomInt/GeomInt_IntSS.cxx
src/GeomInt/GeomInt_LineConstructor.cxx
src/IntPatch/IntPatch_PrmPrmIntersection.cxx
src/IntWalk/IntWalk_PWalking.cdl
src/IntWalk/IntWalk_PWalking_1.gxx
tests/bugs/modalg_1/bug19793_2
tests/bugs/modalg_4/pro19653
tests/bugs/modalg_5/bug24299 [new file with mode: 0755]
tests/bugs/modalg_5/bug24472 [new file with mode: 0755]
tests/bugs/moddata_1/bug13

index 9078897..ca99afc 100644 (file)
@@ -104,7 +104,8 @@ void GeomInt_IntSS::Perform(const Handle(Geom_Surface)& S1,
   // ============================================================
   if (myIntersector.IsDone()) {
     const Standard_Integer nblin = myIntersector.NbLines();
-    for (Standard_Integer i=1; i<= nblin; i++) {
+    for (Standard_Integer i=1; i<= nblin; i++)
+    {
       MakeCurve(i,dom1,dom2,Tol,Approx,ApproxS1,ApproxS2);
     }
   }
index 264c235..77b921a 100644 (file)
@@ -186,10 +186,22 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
     {
       firstp = GeomInt_LineTool::Vertex(L,i).ParameterOnLine();
       lastp =  GeomInt_LineTool::Vertex(L,i+1).ParameterOnLine();
-      if(firstp!=lastp)
-         { 
-        const Standard_Real pmid = (firstp+lastp)*0.5;
-        const gp_Pnt Pmid = ALine->Value(pmid);
+      const Standard_Real pmid = (firstp+lastp)*0.5;
+      const gp_Pnt Pmid = ALine->Value(pmid);
+
+      //Checking, if it is an "micro-curve" (can it be collapsed in one point?).
+      //If "yes" then first-, last- and midpoints are same point.
+      gp_Pnt  aP1 = ALine->Value(RealToInt(firstp)),
+              aP2 = ALine->Value(RealToInt(lastp));
+
+      Standard_Real aSQDist = aP1.SquareDistance(aP2);
+      aSQDist = Max(aSQDist, aP1.SquareDistance(Pmid));
+      aSQDist = Max(aSQDist, aP2.SquareDistance(Pmid));
+      
+      Standard_Boolean isMicro = aSQDist*100.0 < Tol;
+
+      if((Abs(firstp-lastp)>Precision::PConfusion()) && !isMicro)
+      { 
         Parameters(myHS1,myHS2,Pmid,u1,v1,u2,v2);
         Recadre(myHS1,myHS2,u1,v1,u2,v2);
         const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
@@ -206,29 +218,86 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
     return;
   }
   else if(typl == IntPatch_Walking)
-  { 
+  {
     Standard_Real u1,v1,u2,v2;
     Handle(IntPatch_WLine)& WLine =  *((Handle(IntPatch_WLine) *)&L);
     seqp.Clear();
+
+    i = 1;
+    
+    {
+      firstp = GeomInt_LineTool::Vertex(L,1).ParameterOnLine();
+      const IntSurf_PntOn2S& Pf = WLine->Point(RealToInt(firstp));
+
+      Pf.Parameters(u1,v1,u2,v2);
+
+//Inscribe parameters into main period for periodic surfaces
+      Recadre(myHS1,myHS2,u1,v1,u2,v2);
+
+      const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
+      const TopAbs_State in2 = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
+      if((in1 ==  TopAbs_OUT) || (in2 == TopAbs_OUT))
+      {
+        i = 2;
+      }
+    }
+    
     nbvtx = GeomInt_LineTool::NbVertex(L);
-    for(i=1;i<nbvtx;i++)
-       {
+    for(;i<nbvtx;i++)
+    {
       firstp = GeomInt_LineTool::Vertex(L,i).ParameterOnLine();
       lastp =  GeomInt_LineTool::Vertex(L,i+1).ParameterOnLine();
-      if(firstp!=lastp)
-      {  
-        const Standard_Integer pmid = (Standard_Integer )( (firstp+lastp)/2);
-        const IntSurf_PntOn2S& Pmid = WLine->Point(pmid);
+      const Standard_Integer pmid = RealToInt((firstp+lastp)*0.5);
+      const IntSurf_PntOn2S& Pmid = WLine->Point(pmid);
+
+      //Checking, if it is an "micro-curve" (can it be collapsed in one point?).
+      //If "yes" then first-, last- and midpoints are same point.
+      gp_Pnt  aP1 = WLine->Point(RealToInt(firstp)).Value(),
+              aP2 = WLine->Point(RealToInt(lastp)).Value();
+
+      Standard_Real aSQDist = aP1.SquareDistance(aP2);
+      aSQDist = Max(aSQDist, aP1.SquareDistance(Pmid.Value()));
+      aSQDist = Max(aSQDist, aP2.SquareDistance(Pmid.Value()));
+
+      Standard_Boolean isMicro = aSQDist*100.0 < Tol;
+
+      if((Abs(firstp-lastp)>Precision::PConfusion()) && !isMicro)
+      {
         Pmid.Parameters(u1,v1,u2,v2);
+//Inscribe parameters into main period for periodic surfaces
         Recadre(myHS1,myHS2,u1,v1,u2,v2);
-        const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
-        if(in1 !=  TopAbs_OUT) {  //-- !=ON donne Pb 
-          const TopAbs_State in2 = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
-          if(in2 != TopAbs_OUT) { //-- !=ON  
-            seqp.Append(firstp);
-            seqp.Append(lastp);
-          }
+
+        const TopAbs_State in1m = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
+        if(in1m ==  TopAbs_OUT)
+        {
+          continue;
+        }
+
+        const TopAbs_State in2m = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
+        if(in2m == TopAbs_OUT)
+        {
+          continue;
+        }
+
+        const IntSurf_PntOn2S& Plast = WLine->Point(RealToInt(lastp));
+        Plast.Parameters(u1,v1,u2,v2);
+//Inscribe parameters into main period for periodic surfaces
+        Recadre(myHS1,myHS2,u1,v1,u2,v2);
+
+        const TopAbs_State in1l = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
+        if(in1l ==  TopAbs_OUT)
+        {
+          continue;
+        }
+
+        const TopAbs_State in2l = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
+        if(in2l == TopAbs_OUT)
+        {
+          continue;
         }
+
+        seqp.Append(firstp);
+        seqp.Append(lastp);
       }
     }
     done = Standard_True;
@@ -245,46 +314,85 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
     {
       firstp = GeomInt_LineTool::Vertex(L,i).ParameterOnLine();
       lastp =  GeomInt_LineTool::Vertex(L,i+1).ParameterOnLine();
-      if(Abs(firstp-lastp)>Precision::PConfusion())
+
+      if((Abs(firstp-lastp)>Precision::PConfusion()))
       {
         intrvtested = Standard_True;
         const Standard_Real pmid = (firstp+lastp)*0.5;
-        gp_Pnt Pmid;
+        gp_Pnt Pmid, aP1, aP2;
         switch (typl)
         {
-          case IntPatch_Lin:       Pmid = ElCLib::Value(pmid,GLine->Line()); break;
-          case IntPatch_Circle:    Pmid = ElCLib::Value(pmid,GLine->Circle()); break;
-          case IntPatch_Ellipse:   Pmid = ElCLib::Value(pmid,GLine->Ellipse()); break;
-          case IntPatch_Hyperbola: Pmid = ElCLib::Value(pmid,GLine->Hyperbola()); break;
-          case IntPatch_Parabola:  Pmid = ElCLib::Value(pmid,GLine->Parabola()); break;
+          case IntPatch_Lin:
+            Pmid = ElCLib::Value(pmid,GLine->Line());
+            aP1 = ElCLib::Value(firstp,GLine->Line());
+            aP2 = ElCLib::Value(lastp,GLine->Line());
+            break;
+          case IntPatch_Circle:
+            Pmid = ElCLib::Value(pmid,GLine->Circle());
+            aP1 = ElCLib::Value(firstp,GLine->Circle());
+            aP2 = ElCLib::Value(lastp,GLine->Circle());
+            break;
+          case IntPatch_Ellipse:
+            Pmid = ElCLib::Value(pmid,GLine->Ellipse());
+            aP1 = ElCLib::Value(firstp,GLine->Ellipse());
+            aP2 = ElCLib::Value(lastp,GLine->Ellipse());
+            break;
+          case IntPatch_Hyperbola:
+            Pmid = ElCLib::Value(pmid,GLine->Hyperbola());
+            aP1 = ElCLib::Value(firstp,GLine->Hyperbola());
+            aP2 = ElCLib::Value(lastp,GLine->Hyperbola());
+            break;
+          case IntPatch_Parabola:
+            Pmid = ElCLib::Value(pmid,GLine->Parabola());
+            aP1 = ElCLib::Value(firstp,GLine->Parabola());
+            aP2 = ElCLib::Value(lastp,GLine->Parabola());
+            break;
           case IntPatch_Analytic:
           case IntPatch_Walking:
           case IntPatch_Restriction: break; // cases Analytic, Walking and Restriction are handled above
         }
-        Parameters(myHS1,myHS2,Pmid,u1,v1,u2,v2);
-        Recadre(myHS1,myHS2,u1,v1,u2,v2);
-        const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
-        if(in1 !=  TopAbs_OUT) { 
-          const TopAbs_State in2 = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
-          if(in2 != TopAbs_OUT) { 
-            seqp.Append(firstp);
-            seqp.Append(lastp);
+
+        Standard_Real aSQDist = aP1.SquareDistance(aP2);
+        aSQDist = Max(aSQDist, aP1.SquareDistance(Pmid));
+        aSQDist = Max(aSQDist, aP2.SquareDistance(Pmid));
+
+        if(aSQDist*100.0 > Tol)
+        {       //if it is not an "micro-curve" (can it be collapsed in one point?).
+                //If "yes" then first-, last- and midpoints are same point.
+          Parameters(myHS1,myHS2,Pmid,u1,v1,u2,v2);
+          Recadre(myHS1,myHS2,u1,v1,u2,v2);
+          const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
+          if(in1 !=  TopAbs_OUT) { 
+            const TopAbs_State in2 = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
+            if(in2 != TopAbs_OUT) { 
+              seqp.Append(firstp);
+              seqp.Append(lastp);
+            }
           }
         }
       }
     }
     if(typl == IntPatch_Circle || typl == IntPatch_Ellipse)
-    { 
+    {
+      const Standard_Real aT = M_PI + M_PI;
       firstp = GeomInt_LineTool::Vertex(L,nbvtx).ParameterOnLine();
-      lastp  = M_PI + M_PI + GeomInt_LineTool::Vertex(L,1).ParameterOnLine();
+      lastp  = aT + GeomInt_LineTool::Vertex(L,1).ParameterOnLine();
       const Standard_Real cadrinf = GeomInt_LineTool::FirstParameter(L);
       const Standard_Real cadrsup = GeomInt_LineTool::LastParameter(L);
       Standard_Real acadr = (firstp+lastp)*0.5;
-      while(acadr < cadrinf) { acadr+=M_PI+M_PI; }
-      while(acadr > cadrsup) { acadr-=M_PI+M_PI; } 
+      while(acadr < cadrinf)
+      {
+        acadr+=aT;
+      }
+      
+      while(acadr > cadrsup)
+      {
+        acadr-=aT;
+      } 
+      
       if(acadr>=cadrinf && acadr<=cadrsup)
       { 
-        if(Abs(firstp-lastp)>Precision::PConfusion())
+        if(Abs(firstp-lastp) > Precision::PConfusion())
         {
           intrvtested = Standard_True;
           const Standard_Real pmid = (firstp+lastp)*0.5;
@@ -296,16 +404,19 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
           Parameters(myHS1,myHS2,Pmid,u1,v1,u2,v2);
           Recadre(myHS1,myHS2,u1,v1,u2,v2);
           const TopAbs_State in1 = myDom1->Classify(gp_Pnt2d(u1,v1),Tol);
-          if(in1 !=  TopAbs_OUT) { 
+          if(in1 !=  TopAbs_OUT)
+          {
             const TopAbs_State in2 = myDom2->Classify(gp_Pnt2d(u2,v2),Tol);
-            if(in2 != TopAbs_OUT) { 
+            if(in2 != TopAbs_OUT)
+            { 
               seqp.Append(firstp);
               seqp.Append(lastp);
             }
           }
         }
       }
-    }      
+    }
+
     if (!intrvtested) {
       // on garde a priori. Il faudrait un point 2d sur chaque
       // surface pour prendre la decision. Sera fait dans 
@@ -370,28 +481,36 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
       {
         // on cumule
         GeomInt_ParameterAndOrientation& valj = seqpss.ChangeValue(j);
-        if (or1 != TopAbs_INTERNAL) {
-          if (valj.Orientation1() != TopAbs_INTERNAL) {
-            if (or1 != valj.Orientation1()) {
+        if (or1 != TopAbs_INTERNAL)
+        {
+          if (valj.Orientation1() != TopAbs_INTERNAL)
+          {
+            if (or1 != valj.Orientation1())
+            {
               valj.SetOrientation1(TopAbs_INTERNAL);
             }
           }
-          else {
+          else
+          {
             valj.SetOrientation1(or1);
           }
         }
        
-        if (or2 != TopAbs_INTERNAL) {
-          if (valj.Orientation2() != TopAbs_INTERNAL) {
-            if (or2 != valj.Orientation2()) {
+        if (or2 != TopAbs_INTERNAL)
+        {
+          if (valj.Orientation2() != TopAbs_INTERNAL)
+          {
+            if (or2 != valj.Orientation2())
+            {
               valj.SetOrientation2(TopAbs_INTERNAL);
             }
           }
-          else {
+          else
+          {
             valj.SetOrientation2(or2);
           }
-               }
-
+        }
+        
         inserted = Standard_True;
         break;
       }
@@ -403,7 +522,9 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
         break;
       }
     }
-    if (!inserted) {
+
+    if (!inserted)
+    {
       seqpss.Append(GeomInt_ParameterAndOrientation(prm,or1,or2));
     }
   }
@@ -505,10 +626,12 @@ void GeomInt_LineConstructor::Perform(const Handle(IntPatch_Line)& L)
         lastp = seqpss(i).Parameter();
         Standard_Real stofirst = Max(firstp, thefirst);
         Standard_Real stolast  = Min(lastp,  thelast) ;
-        if (stolast > stofirst) {
+        if (stolast > stofirst)
+        {
           seqp.Append(stofirst);
           seqp.Append(stolast);
         }
+        
         if (lastp > thelast)
           break;
       }
index f5812f9..b581ba6 100644 (file)
 #include <TColStd_HArray1OfReal.hxx>
 
 static void SectionPointToParameters(const Intf_SectionPoint& Sp,
-                                    const IntPatch_Polyhedron& Surf1,
-                                    const IntPatch_Polyhedron& Surf2,
-                                    Standard_Real& u1,
-                                    Standard_Real& v1,
-                                    Standard_Real& u2,
-                                    Standard_Real& v2);
+                                     const IntPatch_Polyhedron& Surf1,
+                                     const IntPatch_Polyhedron& Surf2,
+                                     Standard_Real& u1,
+                                     Standard_Real& v1,
+                                     Standard_Real& u2,
+                                     Standard_Real& v2);
 
 
 static 
-  void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
-                       const Handle(Adaptor3d_HSurface)& Surf2,
-                       IntPatch_SequenceOfLine& aSLin);
+void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
+                      const Handle(Adaptor3d_HSurface)& Surf2,
+                      IntPatch_SequenceOfLine& aSLin);
 
 static
-  IntSurf_PntOn2S MakeNewPoint(const IntSurf_PntOn2S& replacePnt,
-                               const IntSurf_PntOn2S& oldPnt,
-                               const Standard_Real* Periods);
+IntSurf_PntOn2S MakeNewPoint(const IntSurf_PntOn2S& replacePnt,
+                             const IntSurf_PntOn2S& oldPnt,
+                             const Standard_Real* Periods);
 
 static Standard_Boolean IsPointOnLine(const IntSurf_PntOn2S        &thePOn2S,
                                       const Handle(IntPatch_WLine) &theWLine,
@@ -83,11 +83,11 @@ IntPatch_PrmPrmIntersection::IntPatch_PrmPrmIntersection(): done(Standard_False)
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   Surf1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Standard_Real  TolTangency,
-                                          const Standard_Real  Epsilon,
-                                          const Standard_Real  Deflection,
-                                          const Standard_Real  Increment)
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Standard_Real  TolTangency,
+                                           const Standard_Real  Epsilon,
+                                           const Standard_Real  Deflection,
+                                           const Standard_Real  Increment)
 { 
   IntPatch_Polyhedron Poly1( Surf1, D1->NbSamplesU(), D1->NbSamplesV() );
   Perform( Surf1, Poly1, D1, TolTangency, Epsilon, Deflection, Increment );
@@ -98,14 +98,14 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   S
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   Surf1,
-                                          const IntPatch_Polyhedron& Poly1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Handle(Adaptor3d_HSurface)&   Surf2,
-                                          const Handle(Adaptor3d_TopolTool)& D2,
-                                          const Standard_Real  TolTangency,
-                                          const Standard_Real  Epsilon,
-                                          const Standard_Real  Deflection,
-                                          const Standard_Real  Increment)
+                                           const IntPatch_Polyhedron& Poly1,
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Handle(Adaptor3d_HSurface)&   Surf2,
+                                           const Handle(Adaptor3d_TopolTool)& D2,
+                                           const Standard_Real  TolTangency,
+                                           const Standard_Real  Epsilon,
+                                           const Standard_Real  Deflection,
+                                           const Standard_Real  Increment)
 { 
   IntPatch_Polyhedron Poly2( Surf2 );
   Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment);
@@ -116,14 +116,14 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   S
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   Surf1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Handle(Adaptor3d_HSurface)&   Surf2,
-                                          const IntPatch_Polyhedron& Poly2,
-                                          const Handle(Adaptor3d_TopolTool)& D2,
-                                          const Standard_Real  TolTangency,
-                                          const Standard_Real  Epsilon,
-                                          const Standard_Real  Deflection,
-                                          const Standard_Real  Increment)
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Handle(Adaptor3d_HSurface)&   Surf2,
+                                           const IntPatch_Polyhedron& Poly2,
+                                           const Handle(Adaptor3d_TopolTool)& D2,
+                                           const Standard_Real  TolTangency,
+                                           const Standard_Real  Epsilon,
+                                           const Standard_Real  Deflection,
+                                           const Standard_Real  Increment)
 { 
   IntPatch_Polyhedron Poly1( Surf1 );    
   Perform( Surf1, Poly1, D1, Surf2, Poly2, D2, TolTangency, Epsilon, Deflection, Increment );
@@ -134,15 +134,15 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&   S
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&    Surf1,
-                                          const IntPatch_Polyhedron&  Poly1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Handle(Adaptor3d_HSurface)&    Surf2,
-                                          const IntPatch_Polyhedron&  Poly2,
-                                          const Handle(Adaptor3d_TopolTool)& D2,
-                                          const Standard_Real   TolTangency,
-                                          const Standard_Real   Epsilon,
-                                          const Standard_Real   Deflection,
-                                          const Standard_Real   Increment)
+                                           const IntPatch_Polyhedron&  Poly1,
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Handle(Adaptor3d_HSurface)&    Surf2,
+                                           const IntPatch_Polyhedron&  Poly2,
+                                           const Handle(Adaptor3d_TopolTool)& D2,
+                                           const Standard_Real   TolTangency,
+                                           const Standard_Real   Epsilon,
+                                           const Standard_Real   Deflection,
+                                           const Standard_Real   Increment)
 { 
   IntPatch_TheInterfPolyhedron Interference(Poly1,Poly2);
   empt = Standard_True;
@@ -160,7 +160,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
   TColStd_Array1OfReal StartParams(1,4);
 
   IntPatch_ThePWalkingInter PW( Surf1, Surf2, TolTangency, Epsilon, Deflection, Increment );
-    
+
   Standard_Real    SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
   Standard_Real    incidence;
   Standard_Real    dminiPointLigne;
@@ -183,14 +183,14 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
     do { 
       triok=Standard_True;
       for(Standard_Integer b=2; b<=nbLigSec; b++) {
-       Standard_Integer nb_B = Interference.LineValue(TabL[b]).NumberOfPoints();
-       Standard_Integer nb_A = Interference.LineValue(TabL[b-1]).NumberOfPoints();
-       if( nb_B > nb_A ) { 
-         Standard_Integer tyu=TabL[b]; 
-         TabL[b]=TabL[b-1];
-         TabL[b-1]=tyu;
-         triok=Standard_False;
-       }
+        Standard_Integer nb_B = Interference.LineValue(TabL[b]).NumberOfPoints();
+        Standard_Integer nb_A = Interference.LineValue(TabL[b-1]).NumberOfPoints();
+        if( nb_B > nb_A ) { 
+          Standard_Integer tyu=TabL[b]; 
+          TabL[b]=TabL[b-1];
+          TabL[b-1]=tyu;
+          triok=Standard_False;
+        }
       }
     } while( triok==Standard_False );
 
@@ -201,7 +201,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
       Standard_Integer *TabPtDep = new Standard_Integer [nbp+1];
       Standard_Integer ilig;
       for( ilig = 1; ilig <= nbp; ilig++) 
-       TabPtDep[ilig]=0;
+        TabPtDep[ilig]=0;
 
       Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
       Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
@@ -214,108 +214,108 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
       VmaxLig2=VminLig2;
 
       for( ilig = 2; ilig <= nbp; ilig++ ) { 
-       SectionPointToParameters(LineSec.GetPoint(ilig),Poly1,Poly2,U1,V1,U2,V2);
+        SectionPointToParameters(LineSec.GetPoint(ilig),Poly1,Poly2,U1,V1,U2,V2);
 
-       if(U1>UmaxLig1) UmaxLig1=U1;
-       if(V1>VmaxLig1) VmaxLig1=V1;
-       if(U2>UmaxLig2) UmaxLig2=U2;
-       if(V2>VmaxLig2) VmaxLig2=V2;
+        if(U1>UmaxLig1) UmaxLig1=U1;
+        if(V1>VmaxLig1) VmaxLig1=V1;
+        if(U2>UmaxLig2) UmaxLig2=U2;
+        if(V2>VmaxLig2) VmaxLig2=V2;
 
-       if(U1<UminLig1) UminLig1=U1;
-       if(V1<VminLig1) VminLig1=V1;
-       if(U2<UminLig2) UminLig2=U2;
-       if(V2<VminLig2) VminLig2=V2;
+        if(U1<UminLig1) UminLig1=U1;
+        if(V1<VminLig1) VminLig1=V1;
+        if(U2<UminLig2) UminLig2=U2;
+        if(V2<VminLig2) VminLig2=V2;
       }
-       
+
       Standard_Integer nbps2 = (nbp>3)? (nbp/2) :  1;
       Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
       Standard_Integer IndicePointdeDepart1 = 0,IndicePointdeDepart2 = 0;
       Standard_Boolean lignetrouvee=Standard_False;
 
       do { 
-       NombreDePointsDeDepartDuCheminement++;
-       if(NombreDePointsDeDepartDuCheminement == 1) { 
-         incidence=3.0;
-         Standard_Integer nbp1_4=nbp/4;
-         Standard_Integer nbp3_4=nbp-nbp1_4;
-
-         Standard_Integer nsp;
-         for(nsp=nbp/2; nsp<nbp3_4; nsp++) { 
-           Standard_Real CurrentIncidence =  LineSec.GetPoint(nsp).Incidence();
-           if(CurrentIncidence < incidence) { 
-             nbps2 = nsp;
-             incidence = 0.9*CurrentIncidence;
-           }
-         }
-
-         for(nsp=nbp/2; nsp>nbp1_4; nsp--) { 
-           Standard_Real CurrentIncidence =  LineSec.GetPoint(nsp).Incidence();
-           if(CurrentIncidence < incidence) { 
-             nbps2 = nsp;
-             incidence = 0.9*CurrentIncidence;
-           }
-         }
-
-         if(nbp<3) 
-           NombreDePointsDeDepartDuCheminement=3;
-
-         IndicePointdeDepart1 = nbps2;
-       }
-       else if(NombreDePointsDeDepartDuCheminement == 2) { 
-         if(IndicePointdeDepart1 == 1) { 
-           nbps2 = nbp/2;
-           IndicePointdeDepart2 = nbps2;
-         }
-         else { 
-           nbps2 = 1;
-           IndicePointdeDepart2 = 1;
-         }
-       }
-       else if(NombreDePointsDeDepartDuCheminement == 3) {
-         if(IndicePointdeDepart1 == nbp)
-           nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
-         else
-           nbps2 = nbp;
-       }
-       else { 
-         nbps2 = NombreDePointsDeDepartDuCheminement-3;
-         NombreDePointsDeDepartDuCheminement++;
-       } 
-
-       if(TabPtDep[nbps2]==0) { 
-         TabPtDep[nbps2]=1;
-         SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly2,U1,V1,U2,V2);
-
-         StartParams(1) = U1;
-         StartParams(2) = V1;
-         StartParams(3) = U2;
-         StartParams(4) = V2;
-           
-         HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
-         dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
-                 
-         if(HasStartPoint) { 
-           StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-           NbLigCalculee = SLin.Length();
-           Standard_Integer l;
-           for( l=1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
-             const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+        NombreDePointsDeDepartDuCheminement++;
+        if(NombreDePointsDeDepartDuCheminement == 1) { 
+          incidence=3.0;
+          Standard_Integer nbp1_4=nbp/4;
+          Standard_Integer nbp3_4=nbp-nbp1_4;
+
+          Standard_Integer nsp;
+          for(nsp=nbp/2; nsp<nbp3_4; nsp++) { 
+            Standard_Real CurrentIncidence =  LineSec.GetPoint(nsp).Incidence();
+            if(CurrentIncidence < incidence) { 
+              nbps2 = nsp;
+              incidence = 0.9*CurrentIncidence;
+            }
+          }
+
+          for(nsp=nbp/2; nsp>nbp1_4; nsp--) { 
+            Standard_Real CurrentIncidence =  LineSec.GetPoint(nsp).Incidence();
+            if(CurrentIncidence < incidence) { 
+              nbps2 = nsp;
+              incidence = 0.9*CurrentIncidence;
+            }
+          }
+
+          if(nbp<3) 
+            NombreDePointsDeDepartDuCheminement=3;
+
+          IndicePointdeDepart1 = nbps2;
+        }
+        else if(NombreDePointsDeDepartDuCheminement == 2) { 
+          if(IndicePointdeDepart1 == 1) { 
+            nbps2 = nbp/2;
+            IndicePointdeDepart2 = nbps2;
+          }
+          else { 
+            nbps2 = 1;
+            IndicePointdeDepart2 = 1;
+          }
+        }
+        else if(NombreDePointsDeDepartDuCheminement == 3) {
+          if(IndicePointdeDepart1 == nbp)
+            nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
+          else
+            nbps2 = nbp;
+        }
+        else { 
+          nbps2 = NombreDePointsDeDepartDuCheminement-3;
+          NombreDePointsDeDepartDuCheminement++;
+        } 
+
+        if(TabPtDep[nbps2]==0) { 
+          TabPtDep[nbps2]=1;
+          SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly2,U1,V1,U2,V2);
+
+          StartParams(1) = U1;
+          StartParams(2) = V1;
+          StartParams(3) = U2;
+          StartParams(4) = V2;
+
+          HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
+          dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
+
+          if(HasStartPoint) { 
+            StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+            NbLigCalculee = SLin.Length();
+            Standard_Integer l;
+            for( l=1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
+              const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
 
               if (IsPointOnLine(StartPOn2S, testwline, Deflection)) {
                 dminiPointLigne = 0.0;
               }
-           } // for ( l ...
-
-           if(dminiPointLigne > SeuildPointLigne) { 
-             PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
-             if(PW.IsDone()) {
-               if(PW.NbPoints()>2) { 
-                 RejetLigne = Standard_False;
-                 Point3dDebut = PW.Value(1).Value();
+            } // for ( l ...
+
+            if(dminiPointLigne > SeuildPointLigne) { 
+              PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
+              if(PW.IsDone()) {
+                if(PW.NbPoints()>2) { 
+                  RejetLigne = Standard_False;
+                  Point3dDebut = PW.Value(1).Value();
                   const IntSurf_PntOn2S& PointFin = PW.Value(PW.NbPoints());
                   Point3dFin   = PointFin.Value();
-                 for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-                   const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+                  for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
+                    const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
 
                     // Check end point if it is on existing line.
                     // Start point is checked before.
@@ -325,69 +325,69 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                     }
 
                     const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-                   const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
-                   if( Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency ) { 
-                     if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency)
-                       RejetLigne = Standard_True; 
-                   }
-                 }
-
-                 if(!RejetLigne) { 
-                   // Calculation transition
-                   IntSurf_TypeTrans trans1,trans2;
-                   Standard_Real locu,locv;
-                   gp_Vec norm1,norm2,d1u,d1v;
-                   gp_Pnt ptbid;
-                   Standard_Integer indextg;
-                   gp_Vec tgline(PW.TangentAtLine(indextg));
-                   PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-                   Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                   norm1 = d1u.Crossed(d1v);
-                   PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-                   Surf2->D1(locu,locv,ptbid,d1u,d1v);
-                   norm2 = d1u.Crossed(d1v);
-                   if(tgline.DotCross(norm2,norm1)>0.) {
-                     trans1 = IntSurf_Out;
-                     trans2 = IntSurf_In;
-                   }
-                   else {
-                     trans1 = IntSurf_In;
-                     trans2 = IntSurf_Out;
-                   }
-
-                   Standard_Real TolTang = TolTangency;
-                   Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
-                   IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
-                   IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-
-                   if(wline->NbVertex() == 0) {
-                     IntPatch_Point vtx;
-                     IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(1);
-                     wline->AddVertex(vtx);
-
-                     POn2S = PW.Line()->Value(wline->NbPnts());
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(wline->NbPnts());
-                     wline->AddVertex(vtx);
-                   }
-
-                   lignetrouvee = Standard_True;
+                    const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
+                    if( Point3dDebut.Distance(verPointDebut.Value()) <= TolTangency ) { 
+                      if(Point3dFin.Distance(verPointFin.Value()) <= TolTangency)
+                        RejetLigne = Standard_True; 
+                    }
+                  }
+
+                  if(!RejetLigne) { 
+                    // Calculation transition
+                    IntSurf_TypeTrans trans1,trans2;
+                    Standard_Real locu,locv;
+                    gp_Vec norm1,norm2,d1u,d1v;
+                    gp_Pnt ptbid;
+                    Standard_Integer indextg;
+                    gp_Vec tgline(PW.TangentAtLine(indextg));
+                    PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                    Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                    norm1 = d1u.Crossed(d1v);
+                    PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                    Surf2->D1(locu,locv,ptbid,d1u,d1v);
+                    norm2 = d1u.Crossed(d1v);
+                    if(tgline.DotCross(norm2,norm1)>0.) {
+                      trans1 = IntSurf_Out;
+                      trans2 = IntSurf_In;
+                    }
+                    else {
+                      trans1 = IntSurf_In;
+                      trans2 = IntSurf_Out;
+                    }
+
+                    Standard_Real TolTang = TolTangency;
+                    Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
+                    IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
+                    IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
+
+                    if(wline->NbVertex() == 0) {
+                      IntPatch_Point vtx;
+                      IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                      POn2S.Parameters(pu1,pv1,pu2,pv2);
+                      vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                      vtx.SetParameters(pu1,pv1,pu2,pv2);
+                      vtx.SetParameter(1);
+                      wline->AddVertex(vtx);
+
+                      POn2S = PW.Line()->Value(wline->NbPnts());
+                      POn2S.Parameters(pu1,pv1,pu2,pv2);
+                      vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                      vtx.SetParameters(pu1,pv1,pu2,pv2);
+                      vtx.SetParameter(wline->NbPnts());
+                      wline->AddVertex(vtx);
+                    }
+
+                    lignetrouvee = Standard_True;
                     AddWLine(SLin, wline, Deflection);
-                   empt = Standard_False;
-                 }// !RejetLigne
-               }// PW.NbPoints()>2
-             }// done is True
-           }// dminiPointLigne > SeuildPointLigne
-         }// HasStartPoint
-       }// TabPtDep[nbps2]==0
+                    empt = Standard_False;
+                  }// !RejetLigne
+                }// PW.NbPoints()>2
+              }// done is True
+            }// dminiPointLigne > SeuildPointLigne
+          }// HasStartPoint
+        }// TabPtDep[nbps2]==0
       } while( nbp>5 && ( !( ( (NombreDePointsDeDepartDuCheminement >= 3) && lignetrouvee ) || 
-                       ( (NombreDePointsDeDepartDuCheminement-3>=nbp) && !lignetrouvee ) ) ) );
+        ( (NombreDePointsDeDepartDuCheminement-3>=nbp) && !lignetrouvee ) ) ) );
 
       delete [] TabPtDep;
     }// for( ls ...
@@ -397,7 +397,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 
   Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
   Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
-    
+
   UminLig1=VminLig1=UminLig2=VminLig2=RealLast();
   UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1;
 
@@ -411,7 +411,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
       if(V1>VmaxLig1) VmaxLig1=V1;
       if(U2>UmaxLig2) UmaxLig2=U2;
       if(V2>VmaxLig2) VmaxLig2=V2;
-       
+
       if(U1<UminLig1) UminLig1=U1;
       if(V1<VminLig1) VminLig1=V1;
       if(U2<UminLig2) UminLig2=U2;
@@ -429,31 +429,31 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
       StartParams(2) = V1;
       StartParams(3) = U2;
       StartParams(4) = V2;
-       
+
       HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
       if(HasStartPoint) { 
-       StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-       NbLigCalculee = SLin.Length();
-       dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
-       Standard_Integer l;
-       for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
-         const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+        StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+        NbLigCalculee = SLin.Length();
+        dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
+        Standard_Integer l;
+        for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++)        { 
+          const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
 
           if (IsPointOnLine(StartPOn2S, testwline, Deflection)) {
             dminiPointLigne = 0.0;
           }
-       }// for( l ...
-
-       if(dminiPointLigne > SeuildPointLigne) { 
-         PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
-         if(PW.IsDone()) {
-           if(PW.NbPoints()>2) { 
-             RejetLigne = Standard_False;
-             Point3dDebut = PW.Value(1).Value();
+        }// for( l ...
+
+        if(dminiPointLigne > SeuildPointLigne) { 
+          PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
+          if(PW.IsDone()) {
+            if(PW.NbPoints()>2)        { 
+              RejetLigne = Standard_False;
+              Point3dDebut = PW.Value(1).Value();
               const IntSurf_PntOn2S& PointFin = PW.Value(PW.NbPoints());
               Point3dFin   = PointFin.Value();
-             for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-               const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+              for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
+                const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
 
                 // Check end point if it is on existing line.
                 // Start point is checked before.
@@ -462,66 +462,66 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                   break;
                 }
 
-               const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-               const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
-               if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
-                 RejetLigne = Standard_True; 
-               else { 
-                 if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
-                   RejetLigne = Standard_True; 
-               }
-             }
-             
-             if(!RejetLigne) { 
-               IntSurf_TypeTrans trans1,trans2;
-               Standard_Real locu,locv;
-               gp_Vec norm1,norm2,d1u,d1v;
-               gp_Pnt ptbid;
-               Standard_Integer indextg;
-               gp_Vec tgline(PW.TangentAtLine(indextg));
-               PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-               Surf1->D1(locu,locv,ptbid,d1u,d1v);
-               norm1 = d1u.Crossed(d1v);
-               PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-               Surf2->D1(locu,locv,ptbid,d1u,d1v);
-               norm2 = d1u.Crossed(d1v);
-               if(tgline.DotCross(norm2,norm1)>0.) {
-                 trans1 = IntSurf_Out;
-                 trans2 = IntSurf_In;
-               }
-               else {
-                 trans1 = IntSurf_In;
-                 trans2 = IntSurf_Out;
-               }
-
-               Standard_Real TolTang = TolTangency;
-               Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
-               IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
-               IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-
-               if(wline->NbVertex() == 0) {
-                 IntPatch_Point vtx;
-                 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                 POn2S.Parameters(pu1,pv1,pu2,pv2);
-                 vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                 vtx.SetParameters(pu1,pv1,pu2,pv2);
-                 vtx.SetParameter(1);
-                 wline->AddVertex(vtx);
-                     
-                 POn2S = PW.Line()->Value(wline->NbPnts());
-                 POn2S.Parameters(pu1,pv1,pu2,pv2);
-                 vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                 vtx.SetParameters(pu1,pv1,pu2,pv2);
-                 vtx.SetParameter(wline->NbPnts());
-                 wline->AddVertex(vtx);
-               }
+                const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+                const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
+                if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
+                  RejetLigne = Standard_True; 
+                else { 
+                  if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
+                    RejetLigne = Standard_True; 
+                }
+              }
+
+              if(!RejetLigne) { 
+                IntSurf_TypeTrans trans1,trans2;
+                Standard_Real locu,locv;
+                gp_Vec norm1,norm2,d1u,d1v;
+                gp_Pnt ptbid;
+                Standard_Integer indextg;
+                gp_Vec tgline(PW.TangentAtLine(indextg));
+                PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                norm1 = d1u.Crossed(d1v);
+                PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                Surf2->D1(locu,locv,ptbid,d1u,d1v);
+                norm2 = d1u.Crossed(d1v);
+                if(tgline.DotCross(norm2,norm1)>0.) {
+                  trans1 = IntSurf_Out;
+                  trans2 = IntSurf_In;
+                }
+                else {
+                  trans1 = IntSurf_In;
+                  trans2 = IntSurf_Out;
+                }
+
+                Standard_Real TolTang = TolTangency;
+                Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
+                IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
+                IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
+
+                if(wline->NbVertex() == 0) {
+                  IntPatch_Point vtx;
+                  IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                  POn2S.Parameters(pu1,pv1,pu2,pv2);
+                  vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                  vtx.SetParameters(pu1,pv1,pu2,pv2);
+                  vtx.SetParameter(1);
+                  wline->AddVertex(vtx);
+
+                  POn2S = PW.Line()->Value(wline->NbPnts());
+                  POn2S.Parameters(pu1,pv1,pu2,pv2);
+                  vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                  vtx.SetParameters(pu1,pv1,pu2,pv2);
+                  vtx.SetParameter(wline->NbPnts());
+                  wline->AddVertex(vtx);
+                }
 
                 AddWLine(SLin, wline, Deflection);
-               empt = Standard_False;
-             }// if !RejetLigne
-           }// PW.NbPoints()>2
-         }// done is True
-       }// dminiPointLigne > SeuildPointLigne
+                empt = Standard_False;
+              }// if !RejetLigne
+            }// PW.NbPoints()>2
+          }// done is True
+        }// dminiPointLigne > SeuildPointLigne
       }// HasStartPoint
     }// for( pz ...
   }// for( z ...
@@ -532,12 +532,12 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&    Surf1,
-                                          const IntPatch_Polyhedron&  Poly1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Standard_Real   TolTangency,
-                                          const Standard_Real   Epsilon,
-                                          const Standard_Real   Deflection,
-                                          const Standard_Real   Increment)
+                                           const IntPatch_Polyhedron&  Poly1,
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Standard_Real   TolTangency,
+                                           const Standard_Real   Epsilon,
+                                           const Standard_Real   Deflection,
+                                           const Standard_Real   Increment)
 { 
   IntPatch_TheInterfPolyhedron Interference(Poly1);
   empt = Standard_True;
@@ -555,7 +555,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 
   TColStd_Array1OfReal StartParams(1,4);
   IntPatch_ThePWalkingInter PW(Surf1,Surf1,TolTangency,Epsilon,Deflection,Increment);
-   
+
   Standard_Real    SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
   Standard_Real    incidence;
   Standard_Real    dminiPointLigne;
@@ -577,210 +577,210 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
       Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
       Standard_Integer IndicePointdeDepart1 = 0, IndicePointdeDepart2 = 0;
       do { 
-       NombreDePointsDeDepartDuCheminement++;
-       if(NombreDePointsDeDepartDuCheminement == 1) { 
-         incidence = 0.0;
-         Standard_Integer nsp1;
-         for( nsp1= nbp/2; nsp1 >= 1; nsp1--) { 
-           SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
-           Standard_Real CurrentIncidence =  Abs(U1-U2)+Abs(V1-V2);
-           if(CurrentIncidence > incidence) { 
-             nbps2 = nsp1;
-             incidence = CurrentIncidence;
-           }
-         }
-         for( nsp1 = nbp/2; nsp1 <= nbp; nsp1++) { 
-           SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
-           Standard_Real CurrentIncidence =  Abs(U1-U2)+Abs(V1-V2);
-           if(CurrentIncidence > incidence) { 
-             nbps2 = nsp1;
-             incidence = CurrentIncidence;
-           }
-         }
-
-         if(nbp<3) 
-           NombreDePointsDeDepartDuCheminement=3;
-                 
-         IndicePointdeDepart1 = nbps2;
-       }
-       else if(NombreDePointsDeDepartDuCheminement == 2) { 
-         if(IndicePointdeDepart1 == 1) { 
-           nbps2 = nbp/2;
-           IndicePointdeDepart2 = nbps2;
-         }
-         else { 
-           nbps2 = 1;
-           IndicePointdeDepart2 = 1;
-         }
-       }
-       else {
-         if(IndicePointdeDepart1 == nbp)
-           nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
-         else
-           nbps2 = nbp;
-       }
-
-       SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly1,U1,V1,U2,V2);
-
-       StartParams(1) = U1;
-       StartParams(2) = V1;
-       StartParams(3) = U2;
-       StartParams(4) = V2;
-
-       HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
-       dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
-       if(HasStartPoint) { 
-         StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-         if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { 
-           NbLigCalculee = SLin.Length();
-           Standard_Integer l;
-           for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
-             const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
-             if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
-                 (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
-                 (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { 
-               NbPntOn2SOnLine = testwline->NbPnts();
-               Standard_Integer ll;
-               for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { 
-                 Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
-                 testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
-                 testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
-                 if(Au1>Bu1) {
-                   t=Au1;
-                   Au1=Bu1;
-                   Bu1=t;
-                 } 
-                 if(Av1>Bv1) {
-                   t=Av1;
-                   Av1=Bv1;
-                   Bv1=t;
-                 } 
-                 Au1-=1.0e-7;
-                 Av1-=1.0e-7;
-                 Bu1+=1.0e-7;
-                 Bv1+=1.0e-7;
-                 
-                 if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
-                   dminiPointLigne = 0.0; 
-                 else { 
-                   if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
-                     dminiPointLigne = 0.0;
-                 }
-               }// for( ll ...
-             }// if ...
-           }// for( l ...
-
-           if(dminiPointLigne > SeuildPointLigne) { 
-             PW.Perform(StartParams);
-             if(PW.IsDone()) {
-               if(PW.NbPoints()>2) { 
-                 RejetLigne = Standard_False;
-                 Point3dDebut = PW.Value(1).Value();
-                 Point3dFin   = PW.Value(PW.NbPoints()).Value();
-                 for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-                   const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
-                   const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-                   const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
-                   if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
-                     RejetLigne = Standard_True; 
-                   else { 
-                     if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
-                       RejetLigne = Standard_True; 
-                   }
-                 }
-
-                 if(!RejetLigne) { 
-                   IntSurf_TypeTrans trans1,trans2;
-                   Standard_Real locu,locv;
-                   gp_Vec norm1,norm2,d1u,d1v;
-                   gp_Pnt ptbid;
-                   Standard_Integer indextg;
-                   gp_Vec tgline(PW.TangentAtLine(indextg));
-                   PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-                   Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                   norm1 = d1u.Crossed(d1v);
-                   PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-                   Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                   norm2 = d1u.Crossed(d1v);
-                   if (tgline.DotCross(norm2,norm1)>0.) {
-                     trans1 = IntSurf_Out;
-                     trans2 = IntSurf_In;
-                   }
-                   else {
-                     trans1 = IntSurf_In;
-                     trans2 = IntSurf_Out;
-                   }
-
-                   IntSurf_LineOn2S LineOn2S;
-                   Standard_Integer nbpw,imin,imax,i;
-                   nbpw = PW.Line()->NbPoints();
-                   Standard_Real u1,v1,u2,v2;
-                   i=0;
-                   do { 
-                     i++;
-                     imin=i;
-                     const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
-                     Pi.Parameters(u1,v1,u2,v2);
-                   } while((i<nbpw)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
-                             
-                   if(imin>2)
-                     imin--;
-
-                   i=nbpw+1;
-                   do { 
-                     i--;
-                     imax=i;
-                     const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
-                     Pi.Parameters(u1,v1,u2,v2);
-                   } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
-                                     
-                   if(imax<nbpw)
-                     imax++;
-                   
-                   if(imin<imax) { 
-                     Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
-                     for(i=imin;i<=imax;i++) 
-                       PWLine->Add(PW.Line()->Value(i));
-                     
-                     Standard_Real TolTang = TolTangency;
-                     Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
-                     const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
-                     const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
-                     if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { 
-                       Standard_Real u1t,v1t,u2t,v2t; 
-                       POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
-                       IntPatch_Point vtx;
-                       vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
-                       vtx.SetParameters(u2t,v2t,u1t,v1t);
-                       vtx.SetParameter(wline->NbPnts());
-                       wline->SetPoint(wline->NbPnts(),vtx);
-                     }
-                     IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
-                     if(wline->NbVertex() == 0) {
-                       IntPatch_Point vtx;
-                       IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                       POn2S.Parameters(pu1,pv1,pu2,pv2);
-                       vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                       vtx.SetParameters(pu1,pv1,pu2,pv2);
-                       vtx.SetParameter(1);
-                       wline->AddVertex(vtx);
-                                             
-                       POn2S = PW.Line()->Value(wline->NbPnts());
-                       POn2S.Parameters(pu1,pv1,pu2,pv2);
-                       vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                       vtx.SetParameters(pu1,pv1,pu2,pv2);
-                       vtx.SetParameter(wline->NbPnts());
-                       wline->AddVertex(vtx);
-                     }
-                     SLin.Append(wline);
-                     empt = Standard_False;
-                   }// imin<imax
-                 }// !RejetLigne
-               }// PW.NbPoints()>2
-             }// done is True
-           }// dminiPointLigne > SeuildPointLigne
-         }// Abs || Abs
-       }// HasStartPoint
+        NombreDePointsDeDepartDuCheminement++;
+        if(NombreDePointsDeDepartDuCheminement == 1) { 
+          incidence = 0.0;
+          Standard_Integer nsp1;
+          for( nsp1= nbp/2; nsp1 >= 1; nsp1--) { 
+            SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
+            Standard_Real CurrentIncidence =  Abs(U1-U2)+Abs(V1-V2);
+            if(CurrentIncidence > incidence) { 
+              nbps2 = nsp1;
+              incidence = CurrentIncidence;
+            }
+          }
+          for( nsp1 = nbp/2; nsp1 <= nbp; nsp1++) { 
+            SectionPointToParameters(LineSec.GetPoint(nsp1),Poly1,Poly1,U1,V1,U2,V2);
+            Standard_Real CurrentIncidence =  Abs(U1-U2)+Abs(V1-V2);
+            if(CurrentIncidence > incidence) { 
+              nbps2 = nsp1;
+              incidence = CurrentIncidence;
+            }
+          }
+
+          if(nbp<3) 
+            NombreDePointsDeDepartDuCheminement=3;
+
+          IndicePointdeDepart1 = nbps2;
+        }
+        else if(NombreDePointsDeDepartDuCheminement == 2) { 
+          if(IndicePointdeDepart1 == 1) { 
+            nbps2 = nbp/2;
+            IndicePointdeDepart2 = nbps2;
+          }
+          else { 
+            nbps2 = 1;
+            IndicePointdeDepart2 = 1;
+          }
+        }
+        else {
+          if(IndicePointdeDepart1 == nbp)
+            nbps2 = (IndicePointdeDepart1+IndicePointdeDepart2)/2;
+          else
+            nbps2 = nbp;
+        }
+
+        SectionPointToParameters(LineSec.GetPoint(nbps2),Poly1,Poly1,U1,V1,U2,V2);
+
+        StartParams(1) = U1;
+        StartParams(2) = V1;
+        StartParams(3) = U2;
+        StartParams(4) = V2;
+
+        HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
+        dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
+        if(HasStartPoint) { 
+          StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+          if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { 
+            NbLigCalculee = SLin.Length();
+            Standard_Integer l;
+            for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
+              const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+              if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
+                (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
+                (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { 
+                  NbPntOn2SOnLine = testwline->NbPnts();
+                  Standard_Integer ll;
+                  for( ll=1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { 
+                    Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
+                    testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
+                    testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
+                    if(Au1>Bu1) {
+                      t=Au1;
+                      Au1=Bu1;
+                      Bu1=t;
+                    } 
+                    if(Av1>Bv1) {
+                      t=Av1;
+                      Av1=Bv1;
+                      Bv1=t;
+                    } 
+                    Au1-=1.0e-7;
+                    Av1-=1.0e-7;
+                    Bu1+=1.0e-7;
+                    Bv1+=1.0e-7;
+
+                    if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
+                      dminiPointLigne = 0.0; 
+                    else { 
+                      if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
+                        dminiPointLigne = 0.0;
+                    }
+                  }// for( ll ...
+              }// if ...
+            }// for( l ...
+
+            if(dminiPointLigne > SeuildPointLigne) { 
+              PW.Perform(StartParams);
+              if(PW.IsDone()) {
+                if(PW.NbPoints()>2) { 
+                  RejetLigne = Standard_False;
+                  Point3dDebut = PW.Value(1).Value();
+                  Point3dFin   = PW.Value(PW.NbPoints()).Value();
+                  for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
+                    const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+                    const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+                    const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
+                    if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
+                      RejetLigne = Standard_True; 
+                    else { 
+                      if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
+                        RejetLigne = Standard_True; 
+                    }
+                  }
+
+                  if(!RejetLigne) { 
+                    IntSurf_TypeTrans trans1,trans2;
+                    Standard_Real locu,locv;
+                    gp_Vec norm1,norm2,d1u,d1v;
+                    gp_Pnt ptbid;
+                    Standard_Integer indextg;
+                    gp_Vec tgline(PW.TangentAtLine(indextg));
+                    PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                    Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                    norm1 = d1u.Crossed(d1v);
+                    PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                    Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                    norm2 = d1u.Crossed(d1v);
+                    if (tgline.DotCross(norm2,norm1)>0.) {
+                      trans1 = IntSurf_Out;
+                      trans2 = IntSurf_In;
+                    }
+                    else {
+                      trans1 = IntSurf_In;
+                      trans2 = IntSurf_Out;
+                    }
+
+                    IntSurf_LineOn2S LineOn2S;
+                    Standard_Integer nbpw,imin,imax,i;
+                    nbpw = PW.Line()->NbPoints();
+                    Standard_Real u1,v1,u2,v2;
+                    i=0;
+                    do { 
+                      i++;
+                      imin=i;
+                      const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
+                      Pi.Parameters(u1,v1,u2,v2);
+                    } while((i<nbpw)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
+
+                    if(imin>2)
+                      imin--;
+
+                    i=nbpw+1;
+                    do { 
+                      i--;
+                      imax=i;
+                      const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
+                      Pi.Parameters(u1,v1,u2,v2);
+                    } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
+
+                    if(imax<nbpw)
+                      imax++;
+
+                    if(imin<imax) { 
+                      Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
+                      for(i=imin;i<=imax;i++) 
+                        PWLine->Add(PW.Line()->Value(i));
+
+                      Standard_Real TolTang = TolTangency;
+                      Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
+                      const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
+                      const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
+                      if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { 
+                        Standard_Real u1t,v1t,u2t,v2t; 
+                        POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
+                        IntPatch_Point vtx;
+                        vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
+                        vtx.SetParameters(u2t,v2t,u1t,v1t);
+                        vtx.SetParameter(wline->NbPnts());
+                        wline->SetPoint(wline->NbPnts(),vtx);
+                      }
+                      IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
+                      if(wline->NbVertex() == 0) {
+                        IntPatch_Point vtx;
+                        IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                        POn2S.Parameters(pu1,pv1,pu2,pv2);
+                        vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                        vtx.SetParameters(pu1,pv1,pu2,pv2);
+                        vtx.SetParameter(1);
+                        wline->AddVertex(vtx);
+
+                        POn2S = PW.Line()->Value(wline->NbPnts());
+                        POn2S.Parameters(pu1,pv1,pu2,pv2);
+                        vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                        vtx.SetParameters(pu1,pv1,pu2,pv2);
+                        vtx.SetParameter(wline->NbPnts());
+                        wline->AddVertex(vtx);
+                      }
+                      SLin.Append(wline);
+                      empt = Standard_False;
+                    }// imin<imax
+                  }// !RejetLigne
+                }// PW.NbPoints()>2
+              }// done is True
+            }// dminiPointLigne > SeuildPointLigne
+          }// Abs || Abs
+        }// HasStartPoint
       } while(nbp>5 && NombreDePointsDeDepartDuCheminement<3);
     }// for( ls ...
   }// nbLigSec>=1
@@ -798,159 +798,159 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 
       HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);    
       if(HasStartPoint) { 
-       StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-       if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { 
-         NbLigCalculee = SLin.Length();
-         dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
-         Standard_Integer l;
-         for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
-           const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
-           if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
-               (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
-               (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { 
-             NbPntOn2SOnLine = testwline->NbPnts();
-             Standard_Integer ll;
-             for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { 
-               Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
-               testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
-               testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
-               if(Au1>Bu1) {
-                 t=Au1;
-                 Au1=Bu1;
-                 Bu1=t;
-               } 
-               if(Av1>Bv1) {
-                 t=Av1;
-                 Av1=Bv1;
-                 Bv1=t;
-               } 
-               Au1-=1.0e-7;
-               Av1-=1.0e-7;
-               Bu1+=1.0e-7;
-               Bv1+=1.0e-7;
-               if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
-                 dminiPointLigne = 0.0; 
-               else { 
-                 if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
-                   dminiPointLigne = 0.0;
-               }
-             }// for( ll ...
-           }// if ...
-         }// for( l ...
-           
-         if(dminiPointLigne > SeuildPointLigne) { 
-           PW.Perform(StartParams);
-           if(PW.IsDone()) {
-             if(PW.NbPoints()>2) { 
-               RejetLigne = Standard_False;
-               Point3dDebut = PW.Value(1).Value();
-               Point3dFin   = PW.Value(PW.NbPoints()).Value();
-               for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-                 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
-                 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-                 const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
-                 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
-                   RejetLigne = Standard_True; 
-                 else { 
-                   if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
-                     RejetLigne = Standard_True; 
-                 }
-               }
-                 
-               if(!RejetLigne) { 
-                 IntSurf_TypeTrans trans1,trans2;
-                 Standard_Real locu,locv;
-                 gp_Vec norm1,norm2,d1u,d1v;
-                 gp_Pnt ptbid;
-                 Standard_Integer indextg;
-                 gp_Vec tgline(PW.TangentAtLine(indextg));
-                 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-                 Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                 norm1 = d1u.Crossed(d1v);
-                 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-                 Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                 norm2 = d1u.Crossed(d1v);
-                 if(tgline.DotCross(norm2,norm1)>0.) {
-                   trans1 = IntSurf_Out;
-                   trans2 = IntSurf_In;
-                 }
-                 else {
-                   trans1 = IntSurf_In;
-                   trans2 = IntSurf_Out;
-                 }
-
-                 IntSurf_LineOn2S LineOn2S;
-                 Standard_Integer nbp,imin,imax,i;
-                 nbp = PW.Line()->NbPoints();
-                 Standard_Real u1,v1,u2,v2;
-                 i=0;
-                 do { 
-                   i++;
-                   imin=i;
-                   const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
-                   Pi.Parameters(u1,v1,u2,v2);
-                 } while((i<nbp)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
-
-                 if(imin>2)
-                   imin--;
-                                 
-                 i=nbp+1;
-                 do { 
-                   i--;
-                   imax=i;
-                   const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
-                   Pi.Parameters(u1,v1,u2,v2);
-                 } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
-
-                 if(imax<nbp)
-                   imax++;
-
-                 if(imin<imax) { 
-                   Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
-                   for(i=imin;i<=imax;i++)
-                     PWLine->Add(PW.Line()->Value(i));
-                                     
-                   Standard_Real TolTang = TolTangency;
-                   Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
-                   const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
-                   const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
-                   if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { 
-                     Standard_Real u1t,v1t,u2t,v2t; 
-                     POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
-                     IntPatch_Point vtx;
-                     vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
-                     vtx.SetParameters(u2t,v2t,u1t,v1t);
-                     vtx.SetParameter(wline->NbPnts());
-                     wline->SetPoint(wline->NbPnts(),vtx);
-                   }
-
-                   IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
-
-                   if(wline->NbVertex() == 0) {
-                     IntPatch_Point vtx;
-                     IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(1);
-                     wline->AddVertex(vtx);
-                       
-                     POn2S = PW.Line()->Value(wline->NbPnts());
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(wline->NbPnts());
-                     wline->AddVertex(vtx);
-                   }
-
-                   SLin.Append(wline);
-                   empt = Standard_False;
-                 }// imin<imax
-               }// !RejetLigne
-             }// PW.NbPoints()>2
-           }// done a True
-         }// dminiPointLigne > SeuildPointLigne
-       }// Abs || Abs
+        StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+        if(Abs(pu1-pu2)>1e-7 || Abs(pv1-pv2)>1e-7) { 
+          NbLigCalculee = SLin.Length();
+          dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
+          Standard_Integer l;
+          for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
+            const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+            if( (testwline->IsOutSurf1Box(gp_Pnt2d(pu1,pv1))==Standard_False) &&
+              (testwline->IsOutSurf2Box(gp_Pnt2d(pu2,pv2))==Standard_False) &&
+              (testwline->IsOutBox(StartPOn2S.Value())==Standard_False) ) { 
+                NbPntOn2SOnLine = testwline->NbPnts();
+                Standard_Integer ll;
+                for( ll = 1; (ll < NbPntOn2SOnLine) && (dminiPointLigne >= SeuildPointLigne); ll++) { 
+                  Standard_Real t,Au1,Av1,Au2,Av2,Bu1,Bv1,Bu2,Bv2;
+                  testwline->Point(ll).Parameters(Au1,Av1,Au2,Av2);
+                  testwline->Point(ll+1).Parameters(Bu1,Bv1,Bu2,Bv2);
+                  if(Au1>Bu1) {
+                    t=Au1;
+                    Au1=Bu1;
+                    Bu1=t;
+                  } 
+                  if(Av1>Bv1) {
+                    t=Av1;
+                    Av1=Bv1;
+                    Bv1=t;
+                  } 
+                  Au1-=1.0e-7;
+                  Av1-=1.0e-7;
+                  Bu1+=1.0e-7;
+                  Bv1+=1.0e-7;
+                  if((pu1>=Au1) && (pu1<=Bu1) && (pv1>=Av1) && (pv1<=Bv1))
+                    dminiPointLigne = 0.0; 
+                  else { 
+                    if((pu2>=Au1) && (pu2<=Bu1) && (pv2>=Av1) && (pv2<=Bv1))
+                      dminiPointLigne = 0.0;
+                  }
+                }// for( ll ...
+            }// if ...
+          }// for( l ...
+
+          if(dminiPointLigne > SeuildPointLigne) { 
+            PW.Perform(StartParams);
+            if(PW.IsDone()) {
+              if(PW.NbPoints()>2) { 
+                RejetLigne = Standard_False;
+                Point3dDebut = PW.Value(1).Value();
+                Point3dFin   = PW.Value(PW.NbPoints()).Value();
+                for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
+                  const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+                  const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+                  const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
+                  if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
+                    RejetLigne = Standard_True; 
+                  else { 
+                    if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
+                      RejetLigne = Standard_True; 
+                  }
+                }
+
+                if(!RejetLigne)        { 
+                  IntSurf_TypeTrans trans1,trans2;
+                  Standard_Real locu,locv;
+                  gp_Vec norm1,norm2,d1u,d1v;
+                  gp_Pnt ptbid;
+                  Standard_Integer indextg;
+                  gp_Vec tgline(PW.TangentAtLine(indextg));
+                  PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                  Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                  norm1 = d1u.Crossed(d1v);
+                  PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                  Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                  norm2 = d1u.Crossed(d1v);
+                  if(tgline.DotCross(norm2,norm1)>0.) {
+                    trans1 = IntSurf_Out;
+                    trans2 = IntSurf_In;
+                  }
+                  else {
+                    trans1 = IntSurf_In;
+                    trans2 = IntSurf_Out;
+                  }
+
+                  IntSurf_LineOn2S LineOn2S;
+                  Standard_Integer nbp,imin,imax,i;
+                  nbp = PW.Line()->NbPoints();
+                  Standard_Real u1,v1,u2,v2;
+                  i=0;
+                  do { 
+                    i++;
+                    imin=i;
+                    const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
+                    Pi.Parameters(u1,v1,u2,v2);
+                  } while((i<nbp)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
+
+                  if(imin>2)
+                    imin--;
+
+                  i=nbp+1;
+                  do { 
+                    i--;
+                    imax=i;
+                    const IntSurf_PntOn2S& Pi   = PW.Line()->Value(i);
+                    Pi.Parameters(u1,v1,u2,v2);
+                  } while((i>2)&&(Abs(u1-u2)<=1e-6 && Abs(v1-v2)<=1e-6));
+
+                  if(imax<nbp)
+                    imax++;
+
+                  if(imin<imax) { 
+                    Handle_IntSurf_LineOn2S PWLine = new IntSurf_LineOn2S();
+                    for(i=imin;i<=imax;i++)
+                      PWLine->Add(PW.Line()->Value(i));
+
+                    Standard_Real TolTang = TolTangency;
+                    Handle(IntPatch_WLine) wline = new IntPatch_WLine(PWLine,Standard_False,trans1,trans2);
+                    const IntSurf_PntOn2S& POn2SDeb = wline->Point(1);
+                    const IntSurf_PntOn2S& POn2SFin = wline->Point(wline->NbPnts());
+                    if((POn2SDeb.Value()).Distance(POn2SFin.Value()) <= TolTangency) { 
+                      Standard_Real u1t,v1t,u2t,v2t; 
+                      POn2SDeb.Parameters(u1t,v1t,u2t,v2t);
+                      IntPatch_Point vtx;
+                      vtx.SetValue(POn2SDeb.Value(),TolTang,Standard_False);
+                      vtx.SetParameters(u2t,v2t,u1t,v1t);
+                      vtx.SetParameter(wline->NbPnts());
+                      wline->SetPoint(wline->NbPnts(),vtx);
+                    }
+
+                    IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf1,Standard_True,TolTang);
+
+                    if(wline->NbVertex() == 0) {
+                      IntPatch_Point vtx;
+                      IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                      POn2S.Parameters(pu1,pv1,pu2,pv2);
+                      vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                      vtx.SetParameters(pu1,pv1,pu2,pv2);
+                      vtx.SetParameter(1);
+                      wline->AddVertex(vtx);
+
+                      POn2S = PW.Line()->Value(wline->NbPnts());
+                      POn2S.Parameters(pu1,pv1,pu2,pv2);
+                      vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                      vtx.SetParameters(pu1,pv1,pu2,pv2);
+                      vtx.SetParameter(wline->NbPnts());
+                      wline->AddVertex(vtx);
+                    }
+
+                    SLin.Append(wline);
+                    empt = Standard_False;
+                  }// imin<imax
+                }// !RejetLigne
+              }// PW.NbPoints()>2
+            }// done a True
+          }// dminiPointLigne > SeuildPointLigne
+        }// Abs || Abs
       }// HasStartPoint
     }// for ( pz ...
   }// for( z ...
@@ -961,11 +961,11 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 // purpose  : 
 //==================================================================================
 Handle_IntPatch_Line IntPatch_PrmPrmIntersection::NewLine (const Handle(Adaptor3d_HSurface)&    Surf1,
-                                                          const Handle(Adaptor3d_HSurface)&    Surf2,
-                                                          const Standard_Integer NumLine,
-                                                          const Standard_Integer Low,
-                                                          const Standard_Integer High,
-                                                          const Standard_Integer NbPntsToInsert) const 
+                                                           const Handle(Adaptor3d_HSurface)&    Surf2,
+                                                           const Standard_Integer NumLine,
+                                                           const Standard_Integer Low,
+                                                           const Standard_Integer High,
+                                                           const Standard_Integer NbPntsToInsert) const 
 { 
   Standard_Integer NbPnts = NbPntsToInsert + High - Low;
   if(NumLine>NbLines() || NumLine<1  || Low>=High ) 
@@ -995,70 +995,70 @@ Handle_IntPatch_Line IntPatch_PrmPrmIntersection::NewLine (const Handle(Adaptor3
   U2(Low) = u2;
   V2(Low) = v2;
   AC(Low) =0.0;
-  
+
   IntPatch_ThePWalkingInter PW(Surf1,Surf2,0.000001,0.000001,0.001,0.001);
-  
+
   Standard_Integer i;
   for(i=Low+1; i<=High; i++)
-    {
-      const IntSurf_PntOn2S& Pointi=TheLine->Point(i);
-      Pointi.Parameters(u1,v1,u2,v2);
-      U1(i) = u1;
-      V1(i) = v1;
-      U2(i) = u2;
-      V2(i) = v2;
-    
-      Standard_Real du1=u1-U1(i-1);
-      Standard_Real dv1=v1-V1(i-1);
-    
-      AC(i) = AC(i-1) + Sqrt((du1*du1)+(dv1*dv1));
-    }
+  {
+    const IntSurf_PntOn2S& Pointi=TheLine->Point(i);
+    Pointi.Parameters(u1,v1,u2,v2);
+    U1(i) = u1;
+    V1(i) = v1;
+    U2(i) = u2;
+    V2(i) = v2;
+
+    Standard_Real du1=u1-U1(i-1);
+    Standard_Real dv1=v1-V1(i-1);
+
+    AC(i) = AC(i-1) + Sqrt((du1*du1)+(dv1*dv1));
+  }
 
   Handle(IntSurf_LineOn2S) ResultPntOn2SLine = new IntSurf_LineOn2S();
-  
+
   IntSurf_PntOn2S StartPOn2S;  
   TColStd_Array1OfReal StartParams(1,4);
-  
+
   ResultPntOn2SLine->Add(TheLine->Point(Low));
-  
+
   ds = AC(High) / (NbPnts-1);
   Standard_Integer Indice = Low;
-  
+
   Standard_Real dsmin = ds*0.3;
   Standard_Real smax  = AC(High);
 
   for(i=2,s=ds; (i<NbPnts)&&(s<smax); i++,s+=ds)
+  { 
+    while(AC(Indice+1) <= s)
     { 
-      while(AC(Indice+1) <= s)
-       { 
-         ResultPntOn2SLine->Add(TheLine->Point(Indice));
-         Indice++;
-       }
-      Standard_Real a = s - AC(Indice);
-      Standard_Real b = AC(Indice+1) - s;
-      Standard_Real nab = 1.0/(a+b);
-      //----------------------------------------------------------
-      //-- Verification :  Si Dist au prochain  point < dsmin   --
-      //--                 Si Dist au precedent point < dsmin   --
-      //--                                                      --
-      //----------------------------------------------------------
-      if((nab > ds)&&(a>dsmin)&&(b>dsmin))
-       {
-         StartParams(1) = (U1(Indice) * b   +  U1(Indice+1) * a) * nab;
-         StartParams(2) = (V1(Indice) * b   +  V1(Indice+1) * a) * nab;
-         StartParams(3) = (U2(Indice) * b   +  U2(Indice+1) * a) * nab;
-         StartParams(4) = (V2(Indice) * b   +  V2(Indice+1) * a) * nab;
-      
-         Standard_Boolean HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
-         if(HasStartPoint)
-           ResultPntOn2SLine->Add(StartPOn2S);
-       }
-      else
-       s+=dsmin; 
+      ResultPntOn2SLine->Add(TheLine->Point(Indice));
+      Indice++;
     }
-  
+    Standard_Real a = s - AC(Indice);
+    Standard_Real b = AC(Indice+1) - s;
+    Standard_Real nab = 1.0/(a+b);
+    //----------------------------------------------------------
+    //-- Verification :  Si Dist au prochain  point < dsmin   --
+    //--                 Si Dist au precedent point < dsmin   --
+    //--                                                      --
+    //----------------------------------------------------------
+    if((nab > ds)&&(a>dsmin)&&(b>dsmin))
+    {
+      StartParams(1) = (U1(Indice) * b   +  U1(Indice+1) * a) * nab;
+      StartParams(2) = (V1(Indice) * b   +  V1(Indice+1) * a) * nab;
+      StartParams(3) = (U2(Indice) * b   +  U2(Indice+1) * a) * nab;
+      StartParams(4) = (V2(Indice) * b   +  V2(Indice+1) * a) * nab;
+
+      Standard_Boolean HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
+      if(HasStartPoint)
+        ResultPntOn2SLine->Add(StartPOn2S);
+    }
+    else
+      s+=dsmin; 
+  }
+
   ResultPntOn2SLine->Add(TheLine->Point(High));
-  
+
   return(new IntPatch_WLine(ResultPntOn2SLine,Standard_False));
 }
 
@@ -1067,20 +1067,20 @@ Handle_IntPatch_Line IntPatch_PrmPrmIntersection::NewLine (const Handle(Adaptor3
 // purpose  : 
 //==================================================================================
 void SectionPointToParameters(const Intf_SectionPoint& Sp,
-                             const IntPatch_Polyhedron& Poly1,
-                             const IntPatch_Polyhedron& Poly2,
-                             Standard_Real& u1,
-                             Standard_Real& v1,
-                             Standard_Real& u2,
-                             Standard_Real& v2)
+                              const IntPatch_Polyhedron& Poly1,
+                              const IntPatch_Polyhedron& Poly2,
+                              Standard_Real& u1,
+                              Standard_Real& v1,
+                              Standard_Real& u2,
+                              Standard_Real& v2)
 {
   Intf_PIType       typ;
   Standard_Integer  Adr1,Adr2;
   Standard_Real     Param,u,v;
   gp_Pnt P(Sp.Pnt());
-  
+
   Standard_Integer Pt1,Pt2,Pt3;
-  
+
   Sp.InfoFirst(typ,Adr1,Adr2,Param);
   switch(typ) { 
   case Intf_VERTEX:   //-- Adr1 est le numero du vertex
@@ -1111,9 +1111,9 @@ void SectionPointToParameters(const Intf_SectionPoint& Sp,
       ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale);
       cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale);
       cabc = ca + cb + cc;
-      
+
       ca/=cabc;     cb/=cabc;       cc/=cabc;
-      
+
       u1 = ca * ua + cb * ub + cc * uc;
       v1 = ca * va + cb * vb + cc * vc;
       break;
@@ -1124,8 +1124,8 @@ void SectionPointToParameters(const Intf_SectionPoint& Sp,
       break;
     }
   }
-  
-  
+
+
   Sp.InfoSecond(typ,Adr1,Adr2,Param);
   switch(typ) { 
   case Intf_VERTEX:   //-- Adr1 est le numero du vertex
@@ -1156,9 +1156,9 @@ void SectionPointToParameters(const Intf_SectionPoint& Sp,
       ca = (gp_Vec(PB,PC).Crossed(gp_Vec(PB,P))).Dot(Normale);
       cb = (gp_Vec(PC,PA).Crossed(gp_Vec(PC,P))).Dot(Normale);
       cabc = ca + cb + cc;
-      
+
       ca/=cabc;     cb/=cabc;       cc/=cabc;
-      
+
       u2 = ca * ua + cb * ub + cc * uc;
       v2 = ca * va + cb * vb + cc * vc;
       break;
@@ -1176,12 +1176,12 @@ void SectionPointToParameters(const Intf_SectionPoint& Sp,
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::RemplitLin(const Standard_Integer x1,
-                                            const Standard_Integer y1,
-                                            const Standard_Integer z1,
-                                            const Standard_Integer x2,
-                                            const Standard_Integer y2,
-                                            const Standard_Integer z2,
-                                            IntPatch_PrmPrmIntersection_T3Bits& Map) const 
+                                             const Standard_Integer y1,
+                                             const Standard_Integer z1,
+                                             const Standard_Integer x2,
+                                             const Standard_Integer y2,
+                                             const Standard_Integer z2,
+                                             IntPatch_PrmPrmIntersection_T3Bits& Map) const 
 {
   int xg,yg,zg;
   xg=x1-x2; if(xg<0) xg=-xg; 
@@ -1204,15 +1204,15 @@ void IntPatch_PrmPrmIntersection::RemplitLin(const Standard_Integer x1,
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::RemplitTri(const Standard_Integer x1,
-                                            const Standard_Integer y1,
-                                            const Standard_Integer z1,
-                                            const Standard_Integer x2,
-                                            const Standard_Integer y2,
-                                            const Standard_Integer z2,
-                                            const Standard_Integer x3,
-                                            const Standard_Integer y3,
-                                            const Standard_Integer z3,
-                                            IntPatch_PrmPrmIntersection_T3Bits& Map) const 
+                                             const Standard_Integer y1,
+                                             const Standard_Integer z1,
+                                             const Standard_Integer x2,
+                                             const Standard_Integer y2,
+                                             const Standard_Integer z2,
+                                             const Standard_Integer x3,
+                                             const Standard_Integer y3,
+                                             const Standard_Integer z3,
+                                             IntPatch_PrmPrmIntersection_T3Bits& Map) const 
 { 
   if(x1==x2 && x1==x3 && y1==y2 && y1==y3 && z1==z2 && z1==z3) {
     if(DansGrille(x1) && DansGrille(y1) && DansGrille(z1)) { 
@@ -1255,15 +1255,15 @@ void IntPatch_PrmPrmIntersection::RemplitTri(const Standard_Integer x1,
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Remplit(const Standard_Integer a,
-                                         const Standard_Integer b,
-                                         const Standard_Integer c,
-                                         IntPatch_PrmPrmIntersection_T3Bits& Map) const 
+                                          const Standard_Integer b,
+                                          const Standard_Integer c,
+                                          IntPatch_PrmPrmIntersection_T3Bits& Map) const 
 { 
   int iax,iay,iaz,ibx,iby,ibz,icx,icy,icz;
   if(a!=-1) Map.Add(a);
   if(b!=-1) Map.Add(b);
   if(c!=-1) Map.Add(c);
-  
+
   if(a!=-1 && b!=-1 && c!=-1 ) { 
     IntegerGrille(a,iax,iay,iaz);
     IntegerGrille(b,ibx,iby,ibz);
@@ -1279,13 +1279,13 @@ void IntPatch_PrmPrmIntersection::Remplit(const Standard_Integer a,
 //purpose  : 
 //=======================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&    Surf1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Handle(Adaptor3d_HSurface)&    Surf2,
-                                          const Handle(Adaptor3d_TopolTool)& D2,
-                                          const Standard_Real   TolTangency,
-                                          const Standard_Real   Epsilon,
-                                          const Standard_Real   Deflection,
-                                          const Standard_Real   Increment,
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Handle(Adaptor3d_HSurface)&    Surf2,
+                                           const Handle(Adaptor3d_TopolTool)& D2,
+                                           const Standard_Real   TolTangency,
+                                           const Standard_Real   Epsilon,
+                                           const Standard_Real   Deflection,
+                                           const Standard_Real   Increment,
                                            IntSurf_ListOfPntOn2S& LOfPnts,
                                            const Standard_Boolean RestrictLine)
 {
@@ -1293,14 +1293,14 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
     done = Standard_True;
     return;
   }
-    
+
   empt = Standard_True;
   SLin.Clear();  
-  
+
   Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
   Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
   Standard_Real U1,U2,V1,V2;
-  
+
   UminLig1 = Surf1->FirstUParameter();
   VminLig1 = Surf1->FirstVParameter();
   UmaxLig1 = Surf1->LastUParameter();
@@ -1315,7 +1315,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
   Periods[1] = (Surf1->IsVPeriodic())? Surf1->VPeriod() : 0.;
   Periods[2] = (Surf2->IsUPeriodic())? Surf2->UPeriod() : 0.;
   Periods[3] = (Surf2->IsVPeriodic())? Surf2->VPeriod() : 0.;
-  
+
   IntSurf_ListIteratorOfListOfPntOn2S IterLOP1(LOfPnts);
 
   for(; IterLOP1.More(); IterLOP1.Next()){
@@ -1325,15 +1325,15 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
     if(V1>VmaxLig1) VmaxLig1=V1;
     if(U2>UmaxLig2) UmaxLig2=U2;
     if(V2>VmaxLig2) VmaxLig2=V2;
-    
+
     if(U1<UminLig1) UminLig1=U1;
     if(V1<VminLig1) VminLig1=V1;
     if(U2<UminLig2) UminLig2=U2;
     if(V2<VminLig2) VminLig2=V2; 
   }
-  
+
   Standard_Real SeuildPointLigne = 15.0 * Increment * Increment;
-  
+
   Standard_Integer NbLigCalculee = 0, ver;
   Standard_Real pu1,pu2,pv1,pv2, dminiPointLigne;
   Standard_Boolean HasStartPoint,RejetLigne;
@@ -1342,18 +1342,18 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 
   TColStd_Array1OfReal StartParams(1,4);
   IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment);  
-    
+
   IntSurf_ListIteratorOfListOfPntOn2S IterLOP2(LOfPnts);
   for(; IterLOP2.More(); IterLOP2.Next() ){
-    
+
     IntSurf_PntOn2S cPnt = IterLOP2.Value();
     cPnt.Parameters(U1, V1, U2, V2);
-    
+
     StartParams(1) = U1;
     StartParams(2) = V1;
     StartParams(3) = U2;
     StartParams(4) = V2;
-    
+
     HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
     dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
     if(HasStartPoint) {
@@ -1367,7 +1367,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
           dminiPointLigne = 0.0;
         }
       }// for( l ...
-      
+
       if(dminiPointLigne > SeuildPointLigne) {
         PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
         if(PW.IsDone())        {
@@ -1393,7 +1393,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                   RejetLigne = Standard_True; 
               }
             }
-            
+
             if(!RejetLigne) {
               IntSurf_TypeTrans trans1,trans2;
               Standard_Real locu,locv;
@@ -1415,14 +1415,14 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                 trans1 = IntSurf_In;
                 trans2 = IntSurf_Out;
               }
-              
+
               Standard_Real TolTang = TolTangency;
               Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
               if (RestrictLine){
                 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
                 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
               }
-              
+
               if(wline->NbVertex() == 0) {
                 IntPatch_Point vtx;
                 IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
@@ -1431,7 +1431,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                 vtx.SetParameters(pu1,pv1,pu2,pv2);
                 vtx.SetParameter(1);
                 wline->AddVertex(vtx);
-                
+
                 POn2S = PW.Line()->Value(wline->NbPnts());
                 POn2S.Parameters(pu1,pv1,pu2,pv2);
                 vtx.SetValue(Point3dFin,TolTang,Standard_False);
@@ -1476,7 +1476,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                       }
                     }
                   }
-                  
+
                   if( VDMin != 0 ) {
                     const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin);
                     const Handle(IntPatch_WLine)&  aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
@@ -1486,11 +1486,11 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                     Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.;
                     wline->Point(ciVpar).Parameters(u11,v11,u12,v12);
                     aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22);
-                    
+
                     Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S();
                     IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar);
                     Standard_Integer cNbP = wline->NbPnts();
-                    
+
                     TColStd_SequenceOfInteger VPold;
                     Standard_Integer iPo;
                     for( iPo = 1; iPo <= cnbV; iPo++ ) {
@@ -1498,16 +1498,16 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                       Standard_Integer IPo = (Standard_Integer) Po;
                       VPold.Append(IPo);
                     }
-                    
+
                     Standard_Boolean removeNext = Standard_False;
                     Standard_Boolean removePrev = Standard_False;
                     if( ciV == 1) {
                       Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
                       if(dPar > 10) {
-                               removeNext = Standard_True;
-                               for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
-                                 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
-                             }
+                        removeNext = Standard_True;
+                        for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
+                          VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
+                      }
                     }
                     else if( ciV == cnbV) {
                       Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
@@ -1539,7 +1539,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                       } 
                     }
                     Standard_Integer pI = (Standard_Integer) ciVpar;
-                    
+
                     Standard_Integer iP;
                     for( iP = 1; iP <= cNbP; iP++) {
                       if( pI == iP )
@@ -1554,15 +1554,15 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                       else
                         newL2s->Add(wline->Point(iP));
                     }
-                    
+
                     IntPatch_Point newVtx;
                     gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value();
                     newVtx.SetValue(Pnt3dV,TolTang,Standard_False);
                     newVtx.SetParameters(u21,v21,u22,v22);
                     newVtx.SetParameter(VPold.Value(ciV));
-                    
+
                     Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2);
-                    
+
                     Standard_Integer iV;
                     for( iV = 1; iV <= cnbV; iV++ ) {
                       if( iV == ciV )
@@ -1573,12 +1573,12 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
                         NWLine->AddVertex(theVtx);
                       }
                     }
-                    
+
                     wline = NWLine;
                   }
                 }
               }// SLin.Length > 0
-              
+
               AddWLine(SLin, wline, Deflection);
               empt = Standard_False;
             }// !RejetLigne
@@ -1595,75 +1595,73 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)&
 //purpose  : 
 //=======================================================================
 void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)&    Surf1,
-                                         const Handle(Adaptor3d_TopolTool)& D1,
-                                         const Handle(Adaptor3d_HSurface)&    Surf2,
-                                         const Handle(Adaptor3d_TopolTool)& D2,
-                                         const Standard_Real   U1Depart,
-                                         const Standard_Real   V1Depart,
-                                         const Standard_Real   U2Depart,
-                                         const Standard_Real   V2Depart,
-                                         const Standard_Real   TolTangency,
-                                         const Standard_Real   Epsilon,
-                                         const Standard_Real   Deflection,
-                                         const Standard_Real   Increment) { 
-  
-  
-  
-//    Standard_Integer NbU1 = D1->NbSamplesU();
-//    Standard_Integer NbV1 = D1->NbSamplesV();
-//    Standard_Integer NbU2 = D2->NbSamplesU();
-//    Standard_Integer NbV2 = D2->NbSamplesV();
+                                          const Handle(Adaptor3d_TopolTool)& D1,
+                                          const Handle(Adaptor3d_HSurface)&    Surf2,
+                                          const Handle(Adaptor3d_TopolTool)& D2,
+                                          const Standard_Real   U1Depart,
+                                          const Standard_Real   V1Depart,
+                                          const Standard_Real   U2Depart,
+                                          const Standard_Real   V2Depart,
+                                          const Standard_Real   TolTangency,
+                                          const Standard_Real   Epsilon,
+                                          const Standard_Real   Deflection,
+                                          const Standard_Real   Increment)
+{
+  //    Standard_Integer NbU1 = D1->NbSamplesU();
+  //    Standard_Integer NbV1 = D1->NbSamplesV();
+  //    Standard_Integer NbU2 = D2->NbSamplesU();
+  //    Standard_Integer NbV2 = D2->NbSamplesV();
 
   //-- Traitement des Lignes de sections
   empt = Standard_True;
   done = Standard_True;
   SLin.Clear();  
-  
+
   //------------------------------------------------------------
 
   Standard_Real pu1,pu2,pv1,pv2;
-  
+
   TColStd_Array1OfReal StartParams(1,4);
-  
-//    Standard_Integer MaxOscill = NbU1;
-//    if(MaxOscill < NbU2) MaxOscill=NbU2;
-//    if(MaxOscill < NbV1) MaxOscill=NbV1;
-//    if(MaxOscill < NbV2) MaxOscill=NbV2;
-  
-//    Standard_Real nIncrement=Increment;
-//    if(MaxOscill>10) { 
-//  #ifdef DEB 
-//      cout<<"\n IntPatch_PrmPrmIntersection.gxx : Increment:"<<Increment<<" -> "<<Increment/(0.5*MaxOscill)<<endl;
-//  #endif
-//      nIncrement/=0.5*MaxOscill;
-//    }
-  
+
+  //    Standard_Integer MaxOscill = NbU1;
+  //    if(MaxOscill < NbU2) MaxOscill=NbU2;
+  //    if(MaxOscill < NbV1) MaxOscill=NbV1;
+  //    if(MaxOscill < NbV2) MaxOscill=NbV2;
+
+  //    Standard_Real nIncrement=Increment;
+  //    if(MaxOscill>10) { 
+  //  #ifdef DEB 
+  //      cout<<"\n IntPatch_PrmPrmIntersection.gxx : Increment:"<<Increment<<" -> "<<Increment/(0.5*MaxOscill)<<endl;
+  //  #endif
+  //      nIncrement/=0.5*MaxOscill;
+  //    }
+
   IntPatch_ThePWalkingInter PW(Surf1,Surf2,
-                              TolTangency,
-                              Epsilon,
-                              Deflection,
-                              Increment); //nIncrement);
-  
-  
+    TolTangency,
+    Epsilon,
+    Deflection,
+    Increment); //nIncrement);
+
+
   //Standard_Real    SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
   //Standard_Real    incidence;
   //Standard_Real    dminiPointLigne;
-  
+
   Standard_Boolean HasStartPoint;//,RejetLigne;
-  
+
   IntSurf_PntOn2S StartPOn2S;
-  
+
   //Standard_Integer ver;
-  
+
   gp_Pnt Point3dDebut,Point3dFin;
-  
+
   //------------------------------------------------------------
-  
+
   StartParams(1) = U1Depart;
   StartParams(2) = V1Depart;
   StartParams(3) = U2Depart;
   StartParams(4) = V2Depart;
-  
+
   //-----------------------------------------------------------------------
   //-- Calcul du premier point de cheminement a partir du point approche --
   //-----------------------------------------------------------------------
@@ -1674,10 +1672,10 @@ void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)&    S
     //-- On verifie qu il n appartient pas           --
     //--  a une ligne de cheminement deja calculee.  --
     //-------------------------------------------------
-    
+
     PW.Perform(StartParams);
     if(PW.IsDone()) {
-      
+
       Point3dDebut = PW.Value(1).Value();
       Point3dFin   = PW.Value(PW.NbPoints()).Value();
 
@@ -1694,43 +1692,43 @@ void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)&    S
       Surf2->D1(locu,locv,ptbid,d1u,d1v);
       norm2 = d1u.Crossed(d1v);
       if (tgline.DotCross(norm2,norm1)>0.) {
-       trans1 = IntSurf_Out;
-       trans2 = IntSurf_In;
+        trans1 = IntSurf_Out;
+        trans2 = IntSurf_In;
       }
       else {
-       trans1 = IntSurf_In;
-       trans2 = IntSurf_Out;
+        trans1 = IntSurf_In;
+        trans2 = IntSurf_Out;
       }
-      
-      
-      
+
+
+
       Standard_Real TolTang = TolTangency;
       Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
       IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
       IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-      
+
       //---------------
       if(wline->NbVertex() == 0) {
-       IntPatch_Point vtx;
-       IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-       POn2S.Parameters(pu1,pv1,pu2,pv2);
-       vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-       vtx.SetParameters(pu1,pv1,pu2,pv2);
-       vtx.SetParameter(1);
-       wline->AddVertex(vtx);
-       
-       POn2S = PW.Line()->Value(wline->NbPnts());
-       POn2S.Parameters(pu1,pv1,pu2,pv2);
-       vtx.SetValue(Point3dFin,TolTang,Standard_False);
-       vtx.SetParameters(pu1,pv1,pu2,pv2);
-       vtx.SetParameter(wline->NbPnts());
-       wline->AddVertex(vtx);
+        IntPatch_Point vtx;
+        IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+        POn2S.Parameters(pu1,pv1,pu2,pv2);
+        vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+        vtx.SetParameters(pu1,pv1,pu2,pv2);
+        vtx.SetParameter(1);
+        wline->AddVertex(vtx);
+
+        POn2S = PW.Line()->Value(wline->NbPnts());
+        POn2S.Parameters(pu1,pv1,pu2,pv2);
+        vtx.SetValue(Point3dFin,TolTang,Standard_False);
+        vtx.SetParameters(pu1,pv1,pu2,pv2);
+        vtx.SetParameter(wline->NbPnts());
+        wline->AddVertex(vtx);
       }
-      
+
       //---------------
       SLin.Append(wline);
       empt = Standard_False;
-      
+
     }
   }
 }
@@ -1739,8 +1737,8 @@ void IntPatch_PrmPrmIntersection::Perform(const Handle(Adaptor3d_HSurface)&    S
 // purpose  : 
 //==================================================================================
 void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
-                     const Handle(Adaptor3d_HSurface)& Surf2,
-                     IntPatch_SequenceOfLine& aSLin)
+                      const Handle(Adaptor3d_HSurface)& Surf2,
+                      IntPatch_SequenceOfLine& aSLin)
 {
   Standard_Boolean bIsPeriodic[4], bModified, bIsNull, bIsPeriod;
   Standard_Integer i, j, k, aNbLines, aNbPx, aIndx, aIndq;
@@ -1789,8 +1787,8 @@ void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
       aIndx=1;
       aIndq=2;
       if (j) {
-       aIndx=aNbPx;
-       aIndq=aNbPx-1;
+        aIndx=aNbPx;
+        aIndq=aNbPx-1;
       }
       //
       const IntSurf_PntOn2S& aPSx=aL->Value(aIndx);
@@ -1800,41 +1798,41 @@ void AdjustOnPeriodic(const Handle(Adaptor3d_HSurface)& Surf1,
       aPSq.Parameters(uq[0], uq[1], uq[2], uq[3]);
       //
       for (k=0; k<4; ++k) {
-       bIsNull=Standard_False;
-       bIsPeriod=Standard_False;
-       //
-       if (!bIsPeriodic[k]) {
-         continue;
-       }
-       //
-       if (fabs(ux[k])<aEps) {
-         bModified=Standard_True;
-         bIsNull=Standard_True;
-       }
-       //
-       else if (fabs(ux[k]-aPeriod[k])<aEps) {
-         bModified=Standard_True;
-         bIsPeriod=Standard_True;
-       }
-       //
-       if (bModified) {
-         du=fabs(ux[k]-uq[k]);
-         if (du > dPeriod[k]) {
-           if(bIsNull){
-             ux[k]=aPeriod[k];
-           }
-           if(bIsPeriod) {
-             ux[k]=0.;
-           }
-         }
-       }
+        bIsNull=Standard_False;
+        bIsPeriod=Standard_False;
+        //
+        if (!bIsPeriodic[k]) {
+          continue;
+        }
+        //
+        if (fabs(ux[k])<aEps) {
+          bModified=Standard_True;
+          bIsNull=Standard_True;
+        }
+        //
+        else if (fabs(ux[k]-aPeriod[k])<aEps) {
+          bModified=Standard_True;
+          bIsPeriod=Standard_True;
+        }
+        //
+        if (bModified) {
+          du=fabs(ux[k]-uq[k]);
+          if (du > dPeriod[k]) {
+            if(bIsNull){
+              ux[k]=aPeriod[k];
+            }
+            if(bIsPeriod) {
+              ux[k]=0.;
+            }
+          }
+        }
       }//for (k=0; k<4; ++k) 
       if (bModified) {
-       IntSurf_PntOn2S aPntOn2S;
-       //
-       aPntOn2S=aPSx;  
-       aPntOn2S.SetValue(ux[0], ux[1], ux[2], ux[3]);
-       aL->Value(aIndx, aPntOn2S);
+        IntSurf_PntOn2S aPntOn2S;
+        //
+        aPntOn2S=aPSx;  
+        aPntOn2S.SetValue(ux[0], ux[1], ux[2], ux[3]);
+        aL->Value(aIndx, aPntOn2S);
       }
     }//for (j=0; j<1; ++j) {
   }//for (i=1; i<=aNbLines; ++i)
@@ -1850,7 +1848,7 @@ IntSurf_PntOn2S MakeNewPoint(const IntSurf_PntOn2S& replacePnt,
 {
   IntSurf_PntOn2S NewPoint;
   NewPoint.SetValue(replacePnt.Value());
-  
+
   Standard_Real OldParams[4], NewParams[4];
   oldPnt.Parameters(OldParams[0], OldParams[1], OldParams[2], OldParams[3]);
   replacePnt.Parameters(NewParams[0], NewParams[1], NewParams[2], NewParams[3]);
@@ -1868,8 +1866,8 @@ IntSurf_PntOn2S MakeNewPoint(const IntSurf_PntOn2S& replacePnt,
       }
     }
 
-  NewPoint.SetValue(NewParams[0], NewParams[1], NewParams[2], NewParams[3]);
-  return NewPoint;
+    NewPoint.SetValue(NewParams[0], NewParams[1], NewParams[2], NewParams[3]);
+    return NewPoint;
 }
 
 //==================================================================================
@@ -1877,24 +1875,26 @@ IntSurf_PntOn2S MakeNewPoint(const IntSurf_PntOn2S& replacePnt,
 // purpose  : base SS Int. function
 //==================================================================================
 void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Surf1,
-                                          const Handle(Adaptor3d_TopolTool)& D1,
-                                          const Handle(Adaptor3d_HSurface)& Surf2,
-                                          const Handle(Adaptor3d_TopolTool)& D2,
-                                          const Standard_Real   TolTangency,
-                                          const Standard_Real   Epsilon,
-                                          const Standard_Real   Deflection,
-                                          const Standard_Real   Increment,
+                                           const Handle(Adaptor3d_TopolTool)& D1,
+                                           const Handle(Adaptor3d_HSurface)& Surf2,
+                                           const Handle(Adaptor3d_TopolTool)& D2,
+                                           const Standard_Real   TolTangency,
+                                           const Standard_Real   Epsilon,
+                                           const Standard_Real   Deflection,
+                                           const Standard_Real   Increment,
                                            const Standard_Boolean ClearFlag) 
 {
-  Standard_Integer NbU1, NbV1, NbU2, NbV2, Limit; 
+  Standard_Integer Limit = 2500;
+  Standard_Integer NbU1 = 10, NbV1 = 10, NbU2 = 10, NbV2 = 10;
   //
-  D1->SamplePnts(Deflection, 10, 10);
-  D2->SamplePnts(Deflection, 10, 10);
+  D1->SamplePnts(Deflection, NbU1, NbV1);
+  D2->SamplePnts(Deflection, NbU2, NbV2);
   //
   NbU1 = D1->NbSamplesU();
   NbV1 = D1->NbSamplesV();
   NbU2 = D2->NbSamplesU();
   NbV2 = D2->NbSamplesV();
+
   TColStd_Array1OfReal anUpars1(1, NbU1), aVpars1(1, NbV1);
   TColStd_Array1OfReal anUpars2(1, NbU2), aVpars2(1, NbV2);
   //
@@ -1908,25 +1908,30 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
   Periods[1] = (Surf1->IsVPeriodic())? Surf1->VPeriod() : 0.;
   Periods[2] = (Surf2->IsUPeriodic())? Surf2->UPeriod() : 0.;
   Periods[3] = (Surf2->IsVPeriodic())? Surf2->VPeriod() : 0.;
-  
+
   //---------------------------------------------
-  Limit = 2500;
-  if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit)) {  
+  if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit))
+  {
     empt = Standard_True;
-    if (ClearFlag){
+    if (ClearFlag)
+    {
       SLin.Clear();
     }
     //
     IntPolyh_Intersection* pInterference = NULL;
 
-    if ( D1->IsUniformSampling() || D2->IsUniformSampling() ) {
+    if ( D1->IsUniformSampling() || D2->IsUniformSampling() )
+    {
       pInterference = new IntPolyh_Intersection(Surf1,NbU1,NbV1,Surf2,NbU2,NbV2);
     }
-    else {
+    else
+    {
       pInterference = new IntPolyh_Intersection(Surf1, anUpars1, aVpars1, 
-                                               Surf2, anUpars2, aVpars2 );
+        Surf2, anUpars2, aVpars2 );
     }
-    if ( !pInterference ) {
+
+    if ( !pInterference )
+    {
       done = Standard_False;
       return;
     }
@@ -1934,411 +1939,486 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
     IntPolyh_Intersection& Interference = *pInterference;
     //
     done = Interference.IsDone();
-    if( !done ) {
-      if (pInterference) {
-       delete pInterference;
-       pInterference = NULL;
+    if( !done )
+    {
+      if (pInterference)
+      {
+        delete pInterference;
+        pInterference = NULL;
       }
+
       return;
     }
-    
+
     Standard_Integer nbLigSec = Interference.NbSectionLines();
     Standard_Integer nbTanZon = Interference.NbTangentZones();
     Standard_Real SeuildPointLigne = 15.0 * Increment * Increment;
 
     Standard_Integer NbLigCalculee = 0, ver;
-    Standard_Real U1,U2,V1,V2, pu1,pu2,pv1,pv2, incidence, dminiPointLigne;
-    Standard_Boolean HasStartPoint,RejetLigne;
+    Standard_Real pu1,pu2,pv1,pv2, incidence, dminiPointLigne;
+    Standard_Boolean HasStartPoint = Standard_False, RejectLine = Standard_False;
     IntSurf_PntOn2S StartPOn2S;
     gp_Pnt Point3dDebut,Point3dFin;
 
     TColStd_Array1OfReal StartParams(1,4);
     IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,Increment);
 
-    if(nbLigSec>=1) {  
+    if(nbLigSec>=1)
+    {
       Standard_Integer *TabL = new Standard_Integer [nbLigSec+1];
-      Standard_Integer ls;
-      for(ls=1; ls<=nbLigSec; ++ls){
-       TabL[ls]=ls;
+      for(Standard_Integer ls=1; ls<=nbLigSec; ++ls)
+      {
+        TabL[ls]=ls;
       }
       //----------------------------------------1.1
-      Standard_Boolean triok;
-      do { 
-       Standard_Integer b, nb_B, nb_A, tyu;
-       //
-       triok=Standard_True;
-       for( b = 2; b <= nbLigSec; ++b ) { 
-         nb_B = Interference.NbPointsInLine(TabL[b]);
-         nb_A = Interference.NbPointsInLine(TabL[b-1]);
-         if( nb_B > nb_A ) { 
-           tyu=TabL[b]; 
-           TabL[b]=TabL[b-1];
-           TabL[b-1]=tyu;
-           triok=Standard_False;
-         }
-       }
-      } while(triok==Standard_False);
+      {
+        Standard_Boolean triok;
+        Standard_Integer nb_A, nb_B, tyu;
+        do
+        {
+          triok=Standard_True;
+          for(Standard_Integer b = 2; b <= nbLigSec; ++b )
+          {
+            nb_B = Interference.NbPointsInLine(TabL[b]);
+            nb_A = Interference.NbPointsInLine(TabL[b-1]);
+
+            if( nb_B > nb_A )
+            {
+              tyu=TabL[b];
+              TabL[b]=TabL[b-1];
+              TabL[b-1]=tyu;
+              triok=Standard_False;
+            }
+          }
+        }
+        while(triok==Standard_False);
+      }
+
       //----------------------------------------
       // 1.2 For the line "ls" get 2D-bounds U,V for surfaces 1,2
       //
-      for( ls = 1; ls <= nbLigSec; ++ls) {
-       Standard_Integer nbp, ilig, *TabPtDep;
-       //
-       nbp = Interference.NbPointsInLine(TabL[ls]);
-       if (!nbp) {
-         continue;
-       }
-       //
-       TabPtDep = new Standard_Integer [nbp+1];
-       for( ilig = 1; ilig <= nbp; ++ilig ) {
-         TabPtDep[ilig]=0;
-       }
-       //
-       Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
-       Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
-       Standard_Real _x,_y,_z;
-       //
-       Interference.GetLinePoint(TabL[ls], 1, 
-                                 _x,_y,_z, 
-                                 UminLig1, VminLig1, UminLig2, VminLig2, 
-                                 incidence);
-       
-       UmaxLig1=UminLig1;
-       VmaxLig1=VminLig1;
-       UmaxLig2=UminLig2;
-       VmaxLig2=VminLig2;
-       //
-       for( ilig = 2; ilig <= nbp; ilig++ ) { 
-         Interference.GetLinePoint(TabL[ls],ilig,_x,_y,_z,U1,V1,U2,V2,incidence);
-         //
-         if(U1>UmaxLig1) UmaxLig1=U1;
-         if(V1>VmaxLig1) VmaxLig1=V1;
-         if(U2>UmaxLig2) UmaxLig2=U2;
-         if(V2>VmaxLig2) VmaxLig2=V2;
-         //
-         if(U1<UminLig1) UminLig1=U1;
-         if(V1<VminLig1) VminLig1=V1;
-         if(U2<UminLig2) UminLig2=U2;
-         if(V2<VminLig2) VminLig2=V2;
-       }//for( ilig = 2; ilig <= nbp; ilig++ ) { 
-       //
-       //----------------------------------------
-       // 1.3
-       Standard_Integer nbps2 = (nbp>3)? (nbp/2) :  1;
-       Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
-       Standard_Boolean lignetrouvee=Standard_False;
-       const Standard_Integer NbDePointsDeDepartDuChmLimit = 5;
-       //
-       do { 
-         NombreDePointsDeDepartDuCheminement++;
-         switch (NombreDePointsDeDepartDuCheminement) {
-         case 1:
-           nbps2 = (nbp > 1) ? nbp/2 : 1;
-           if(nbp<3) 
-             NombreDePointsDeDepartDuCheminement = NbDePointsDeDepartDuChmLimit;
-           break;
-         case 2:
-           nbps2 = 1;
-           break;
-         case 3:
-           nbps2 = nbp-1;
-           break;
-         case 4:
-           nbps2 = 3 * nbp / 4;
-           break;
-         case 5:
-           nbps2 = nbp / 4;
-           break;
-         default:
-           nbps2 = NombreDePointsDeDepartDuCheminement-3;
-           NombreDePointsDeDepartDuCheminement++;
-         }
-         //
-         if(TabPtDep[nbps2] == 0) {
-           TabPtDep[nbps2] = 1;
-           Interference.GetLinePoint(TabL[ls],nbps2,_x,_y,_z,U1,V1,U2,V2,incidence);
-                     
-           StartParams(1) = U1;
-           StartParams(2) = V1;
-           StartParams(3) = U2;
-           StartParams(4) = V2;
-
-           HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
-           dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
-           if(HasStartPoint) {
-             StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-             NbLigCalculee = SLin.Length();
-             Standard_Integer l;
-             for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++) { 
-               const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
-
-                if (IsPointOnLine(StartPOn2S, testwline, Deflection)) {
+      for(Standard_Integer ls = 1; ls <= nbLigSec; ++ls)
+      {
+        Standard_Integer nbp = Interference.NbPointsInLine(TabL[ls]);
+        if (!nbp)
+        {
+          continue;
+        }
+        //
+        Standard_Integer *TabPtDep = new Standard_Integer [nbp+1];
+        for(Standard_Integer ilig = 1; ilig <= nbp; ++ilig )
+        {
+          TabPtDep[ilig]=0;
+        }
+        //
+        Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
+        Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
+        Standard_Real _x,_y,_z;
+        //
+        Interference.GetLinePoint(TabL[ls], 1, _x, _y, _z,
+          UminLig1, VminLig1, UminLig2, VminLig2, 
+          incidence);
+
+        UmaxLig1=UminLig1;
+        VmaxLig1=VminLig1;
+        UmaxLig2=UminLig2;
+        VmaxLig2=VminLig2;
+        //
+        for(Standard_Integer ilig = 2; ilig <= nbp; ilig++ )
+        {
+          Standard_Real U1, U2, V1, V2;
+          Interference.GetLinePoint(TabL[ls],ilig,_x,_y,_z,U1,V1,U2,V2,incidence);
+          //
+          if(U1>UmaxLig1) UmaxLig1=U1;
+          if(V1>VmaxLig1) VmaxLig1=V1;
+          if(U2>UmaxLig2) UmaxLig2=U2;
+          if(V2>VmaxLig2) VmaxLig2=V2;
+          //
+          if(U1<UminLig1) UminLig1=U1;
+          if(V1<VminLig1) VminLig1=V1;
+          if(U2<UminLig2) UminLig2=U2;
+          if(V2<VminLig2) VminLig2=V2;
+        }//for( ilig = 2; ilig <= nbp; ilig++ ) { 
+        //
+        //----------------------------------------
+        // 1.3
+        Standard_Integer nbps2 = (nbp>3)? (nbp/2) :  1;
+        Standard_Integer NombreDePointsDeDepartDuCheminement = 0;
+        Standard_Boolean lignetrouvee=Standard_False;
+        const Standard_Integer NbDePointsDeDepartDuChmLimit = 5;
+        //
+        do
+        {
+          NombreDePointsDeDepartDuCheminement++;
+          switch (NombreDePointsDeDepartDuCheminement)
+          {
+          case 1:
+            nbps2 = (nbp > 1) ? nbp/2 : 1;
+            if(nbp<3) 
+              NombreDePointsDeDepartDuCheminement = NbDePointsDeDepartDuChmLimit;
+
+            break;
+          case 2:
+            nbps2 = 1;
+            break;
+          case 3:
+            nbps2 = nbp-1;
+            break;
+
+          case 4:
+            nbps2 = 3 * nbp / 4;
+            break;
+
+          case 5:
+            nbps2 = nbp / 4;
+            break;
+          default:
+            nbps2 = NombreDePointsDeDepartDuCheminement-3;
+            NombreDePointsDeDepartDuCheminement++;
+          }
+
+          //
+          if(TabPtDep[nbps2] == 0)
+          {
+            Standard_Real U1, U2, V1, V2;
+
+            TabPtDep[nbps2] = 1;
+            Interference.GetLinePoint(TabL[ls],nbps2,_x,_y,_z,U1,V1,U2,V2,incidence);
+
+            StartParams(1) = U1;
+            StartParams(2) = V1;
+            StartParams(3) = U2;
+            StartParams(4) = V2;
+
+            HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);
+            dminiPointLigne = SeuildPointLigne + SeuildPointLigne;
+            if(HasStartPoint)
+            {
+              StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+              NbLigCalculee = SLin.Length();
+              Standard_Integer l;
+              for( l = 1; (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); l++)
+              {
+                const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+
+                if (IsPointOnLine(StartPOn2S, testwline, Deflection))
+                {
                   dminiPointLigne = 0.0;
                 }
-             }// for( l ...
-
-             if(dminiPointLigne > SeuildPointLigne) {
-               PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
-               //
-               Standard_Boolean bPWIsDone;
-               Standard_Integer iPWNbPoints, aNbPointsVer;
-               Standard_Real aD11, aD12, aD21, aD22, aDx;
-               //
-               bPWIsDone=PW.IsDone();
-               if(bPWIsDone) {
-                 iPWNbPoints=PW.NbPoints();
-                 //
-                 if( iPWNbPoints > 2 ) {
-                   RejetLigne = Standard_False;
-                   Point3dDebut = PW.Value(1).Value();
-                   Point3dFin   = PW.Value(iPWNbPoints).Value();
-                   for( ver = 1; (!RejetLigne) && (ver<= NbLigCalculee); ++ver) { 
-                     const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
-                     //
-                     aNbPointsVer=verwline->NbPnts();
-                     if (aNbPointsVer<3) {
-                       continue;
-                     }
-                     //
-                     const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-                     const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
-                     //xf
-                     const gp_Pnt& aP21=verPointDebut.Value();
-                     const gp_Pnt& aP22=verPointFin.Value();
-                     //
-                     aD11=Point3dDebut.Distance(aP21);
-                     aD12=Point3dDebut.Distance(aP22);
-                     aD21=Point3dFin.Distance(aP21);
-                     aD22=Point3dFin.Distance(aP22);
-                     //
-                     if((aD11<=TolTangency && aD22<=TolTangency) ||
-                        (aD12<=TolTangency && aD21<=TolTangency)) {
-                       Standard_Integer m, mx;
-                       //
-                       mx=aNbPointsVer/2;
-                       if (aNbPointsVer%2) {
-                         ++mx; 
-                       }
-                       //
-                       const gp_Pnt& aPx=verwline->Point(mx).Value();
-                       for(m=1; m<iPWNbPoints; ++m){
-                         const gp_Pnt& aP1=PW.Value(m).Value();
-                         const gp_Pnt& aP2=PW.Value(m+1).Value();
-                         gp_Vec aVec12(aP1, aP2);
-                         if (aVec12.SquareMagnitude()<1.e-20){
-                           continue;
-                         }
-                         //
-                         gp_Dir aDir12(aVec12);
-                         gp_Lin aLin12(aP1, aDir12);
-                         aDx=aLin12.Distance(aPx);
-                         //modified by NIZNHY-PKV Tue May 10 11:08:07 2011f
-                         if (aDx<=2.*Epsilon) {
-                         //if (aDx<=TolTangency) {
-                         //modified by NIZNHY-PKV Tue May 10 11:08:13 2011t  
-                           RejetLigne = Standard_True;
-                           break;
-                         }
-                       }//for(m=1; m<iPWNbPoints; ++m){
-                     }//if((aD11<=TolTangency && aD22<=TolTangency) ||...
-                   }// for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-                   //
-                   if(!RejetLigne) {
-                     IntSurf_TypeTrans trans1,trans2;
-                     Standard_Real locu,locv;
-                     gp_Vec norm1,norm2,d1u,d1v;
-                     gp_Pnt ptbid;
-                     Standard_Integer indextg;
-                     gp_Vec tgline(PW.TangentAtLine(indextg));
-                     PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-                     Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                     norm1 = d1u.Crossed(d1v);
-                     PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-                     Surf2->D1(locu,locv,ptbid,d1u,d1v);
-                     norm2 = d1u.Crossed(d1v);
-                     if( tgline.DotCross(norm2,norm1) >= 0. ) {
-                       trans1 = IntSurf_Out;
-                       trans2 = IntSurf_In;
-                     }
-                     else {
-                       trans1 = IntSurf_In;
-                       trans2 = IntSurf_Out;
-                     }
-
-                     Standard_Real TolTang = TolTangency;
-                     Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
-                     IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
-                     IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-
-                     if(wline->NbVertex() == 0) {
-                       IntPatch_Point vtx;
-                       IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                       POn2S.Parameters(pu1,pv1,pu2,pv2);
-                       vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                       vtx.SetParameters(pu1,pv1,pu2,pv2);
-                       vtx.SetParameter(1);
-                       wline->AddVertex(vtx);
-                       
-                       POn2S = PW.Line()->Value(wline->NbPnts());
-                       POn2S.Parameters(pu1,pv1,pu2,pv2);
-                       vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                       vtx.SetParameters(pu1,pv1,pu2,pv2);
-                       vtx.SetParameter(wline->NbPnts());
-                       wline->AddVertex(vtx);
-                     }
-                     
-                     lignetrouvee = Standard_True;
-
-                     Standard_Integer slinlen = SLin.Length();
-                     if( slinlen > 0 ) {
-                       Standard_Integer cnbV = wline->NbVertex();
-                       Standard_Integer ciV;
-                       for( ciV = 1; ciV <= cnbV; ciV++ ) {
-                         Standard_Real pntDMin = 1.e+100;
-                         Standard_Integer VDMin = 0;
-                         Standard_Integer WLDMin = 0;
-                         gp_Pnt cPV = wline->Vertex(ciV).Value();
-                         Standard_Integer iL;
-                         for( iL = 1; iL <= slinlen; iL++) {
-                           const Handle(IntPatch_Line)& aSLine = SLin.Value(iL);
-                           IntPatch_IType aType = aSLine->ArcType();
-                           if( aType != IntPatch_Walking)
-                             continue;
-                           const Handle(IntPatch_WLine)&  aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
-                           Standard_Integer tnbV = aWLine->NbVertex();
-                           Standard_Integer tiV;
-                           for( tiV = 1; tiV <= tnbV; tiV++ ) {
-                             gp_Pnt tPV = aWLine->Vertex(tiV).Value();
-                             Standard_Real tDistance = cPV.Distance(tPV);
-                             Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance);
-                             Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance);
-                             Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance);
-                             Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance);
-                             Standard_Real RmaxS1 = Max(uRs1,vRs1);
-                             Standard_Real RmaxS2 = Max(uRs2,vRs2);
-                             if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4) {
-                               if( pntDMin > tDistance && tDistance > 1.e-9) {
-                                 pntDMin = tDistance;
-                                 VDMin = tiV;
-                                 WLDMin = iL;
-                               }
-                             }
-                           }
-                         }
-                         
-                         if( VDMin != 0 ) {
-                           const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin);
-                           const Handle(IntPatch_WLine)&  aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
-                           Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine();
-                           Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine();
-                           Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.;
-                           Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.;
-                           wline->Point(ciVpar).Parameters(u11,v11,u12,v12);
-                           aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22);
-
-                           Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S();
-                           IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar);
-                           Standard_Integer cNbP = wline->NbPnts();
-
-                           TColStd_SequenceOfInteger VPold;
-                           Standard_Integer iPo;
-                           for( iPo = 1; iPo <= cnbV; iPo++ ) {
-                             Standard_Real Po = wline->Vertex(iPo).ParameterOnLine();
-                             Standard_Integer IPo = (Standard_Integer) Po;
-                             VPold.Append(IPo);
-                           }
-                           
-                           Standard_Boolean removeNext = Standard_False;
-                           Standard_Boolean removePrev = Standard_False;
-                           if( ciV == 1) {
-                             Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
-                             if(dPar > 10) {
-                               removeNext = Standard_True;
-                               for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
-                                 VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
-                             }
-                           }
-                           else if( ciV == cnbV) {
-                             Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
-                             if(dPar > 10) {
-                               removePrev = Standard_True;
-                               VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
-                             }
-                           }
-                           else {
-                             Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
-                             Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
-                             if(dParMi > 10) {
-                               removePrev = Standard_True;
-                               VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
-                             }
-                             if(dParMa > 10) {
-                               removeNext = Standard_True;
-                               for( iPo = (ciV+1); iPo <= cnbV; iPo++ ) {
-                                 if(dParMi > 10)
-                                   VPold.SetValue(iPo, VPold.Value(iPo) - 2 );
-                                 else
-                                   VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
-                               }
-                             }
-                             else {
-                               if(dParMi > 10)
-                                 for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
-                                   VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
-                             } 
-                           }
-                           Standard_Integer pI = (Standard_Integer) ciVpar;
-
-                           Standard_Integer iP;
-                           for( iP = 1; iP <= cNbP; iP++) {
-                             if( pI == iP )
+              }// for( l ...
+
+              if(dminiPointLigne > SeuildPointLigne)
+              {
+                PW.Perform(StartParams, UminLig1, VminLig1, UminLig2, VminLig2,
+                  UmaxLig1, VmaxLig1, UmaxLig2, VmaxLig2);
+
+                //
+                Standard_Boolean bPWIsDone;
+                Standard_Integer iPWNbPoints, aNbPointsVer;
+                Standard_Real aD11, aD12, aD21, aD22, aDx;
+                //
+                bPWIsDone=PW.IsDone();
+
+                if(bPWIsDone)
+                {
+                  iPWNbPoints=PW.NbPoints();
+                  //
+                  if( iPWNbPoints > 2 )
+                  {
+                    const Standard_Integer aMinNbPoints = 40;
+                    if(iPWNbPoints < aMinNbPoints)
+                    {
+                      PW.SeekAdditionalPoints(Surf1, Surf2, aMinNbPoints);
+                      iPWNbPoints = PW.NbPoints();
+                    }
+                    
+                    RejectLine = Standard_False;
+                    Point3dDebut = PW.Value(1).Value();
+                    Point3dFin   = PW.Value(iPWNbPoints).Value();
+                    for( ver = 1; (!RejectLine) && (ver<= NbLigCalculee); ++ver)
+                    {
+                      const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+                      //
+                      aNbPointsVer=verwline->NbPnts();
+                      if (aNbPointsVer<3)
+                      {
+                        continue;
+                      }
+                      //
+                      const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+                      const IntSurf_PntOn2S& verPointFin = verwline->Point(verwline->NbPnts());
+                      //xf
+                      const gp_Pnt& aP21=verPointDebut.Value();
+                      const gp_Pnt& aP22=verPointFin.Value();
+                      //
+                      aD11=Point3dDebut.Distance(aP21);
+                      aD12=Point3dDebut.Distance(aP22);
+                      aD21=Point3dFin.Distance(aP21);
+                      aD22=Point3dFin.Distance(aP22);
+                      //
+                      if((aD11<=TolTangency && aD22<=TolTangency) ||
+                        (aD12<=TolTangency && aD21<=TolTangency))
+                      {
+                        Standard_Integer m, mx;
+                        //
+                        mx=aNbPointsVer/2;
+                        if (aNbPointsVer%2)
+                        {
+                          ++mx; 
+                        }
+                        //
+                        const gp_Pnt& aPx=verwline->Point(mx).Value();
+                        for(m=1; m<iPWNbPoints; ++m)
+                        {
+                          const gp_Pnt& aP1=PW.Value(m).Value();
+                          const gp_Pnt& aP2=PW.Value(m+1).Value();
+                          gp_Vec aVec12(aP1, aP2);
+                          if (aVec12.SquareMagnitude()<1.e-20)
+                          {
+                            continue;
+                          }
+
+                          //
+                          gp_Dir aDir12(aVec12);
+                          gp_Lin aLin12(aP1, aDir12);
+                          aDx=aLin12.Distance(aPx);
+
+                          //modified by NIZNHY-PKV Tue May 10 11:08:07 2011f
+                          if (aDx<=2.*Epsilon)
+                          {
+                            //if (aDx<=TolTangency) {
+                            //modified by NIZNHY-PKV Tue May 10 11:08:13 2011t
+
+                            RejectLine = Standard_True;
+                            break;
+                          }
+                        }//for(m=1; m<iPWNbPoints; ++m){
+                      }//if((aD11<=TolTangency && aD22<=TolTangency) ||...
+                    }// for( ver = 1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
+                    //
+
+                    if(!RejectLine)
+                    {
+                      IntSurf_TypeTrans trans1,trans2;
+                      Standard_Real locu,locv;
+                      gp_Vec norm1,norm2,d1u,d1v;
+                      gp_Pnt ptbid;
+                      Standard_Integer indextg;
+                      gp_Vec tgline(PW.TangentAtLine(indextg));
+                      PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                      Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                      norm1 = d1u.Crossed(d1v);
+                      PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                      Surf2->D1(locu,locv,ptbid,d1u,d1v);
+                      norm2 = d1u.Crossed(d1v);
+                      if( tgline.DotCross(norm2,norm1) >= 0. )
+                      {
+                        trans1 = IntSurf_Out;
+                        trans2 = IntSurf_In;
+                      }
+                      else
+                      {
+                        trans1 = IntSurf_In;
+                        trans2 = IntSurf_Out;
+                      }
+
+                      Standard_Real TolTang = TolTangency;
+                      Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
+                      IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
+                      IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
+
+                      if(wline->NbVertex() == 0)
+                      {
+                        IntPatch_Point vtx;
+                        IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                        POn2S.Parameters(pu1,pv1,pu2,pv2);
+                        vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                        vtx.SetParameters(pu1,pv1,pu2,pv2);
+                        vtx.SetParameter(1);
+                        wline->AddVertex(vtx);
+
+                        POn2S = PW.Line()->Value(wline->NbPnts());
+                        POn2S.Parameters(pu1,pv1,pu2,pv2);
+                        vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                        vtx.SetParameters(pu1,pv1,pu2,pv2);
+                        vtx.SetParameter(wline->NbPnts());
+                        wline->AddVertex(vtx);
+                      }
+
+                      lignetrouvee = Standard_True;
+
+                      Standard_Integer slinlen = SLin.Length();
+                      if( slinlen > 0 )
+                      {
+                        Standard_Integer cnbV = wline->NbVertex();
+                        Standard_Integer ciV;
+                        for( ciV = 1; ciV <= cnbV; ciV++ )
+                        {
+                          Standard_Real pntDMin = 1.e+100;
+                          Standard_Integer VDMin = 0;
+                          Standard_Integer WLDMin = 0;
+                          gp_Pnt cPV = wline->Vertex(ciV).Value();
+                          Standard_Integer iL;
+                          for( iL = 1; iL <= slinlen; iL++)
+                          {
+                            const Handle(IntPatch_Line)& aSLine = SLin.Value(iL);
+                            IntPatch_IType aType = aSLine->ArcType();
+                            if( aType != IntPatch_Walking)
+                              continue;
+                            const Handle(IntPatch_WLine)&  aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
+                            Standard_Integer tnbV = aWLine->NbVertex();
+                            Standard_Integer tiV;
+                            for( tiV = 1; tiV <= tnbV; tiV++ )
+                            {
+                              gp_Pnt tPV = aWLine->Vertex(tiV).Value();
+                              Standard_Real tDistance = cPV.Distance(tPV);
+                              Standard_Real uRs1 = Surf1->Surface().UResolution(tDistance);
+                              Standard_Real vRs1 = Surf1->Surface().VResolution(tDistance);
+                              Standard_Real uRs2 = Surf2->Surface().UResolution(tDistance);
+                              Standard_Real vRs2 = Surf2->Surface().VResolution(tDistance);
+                              Standard_Real RmaxS1 = Max(uRs1,vRs1);
+                              Standard_Real RmaxS2 = Max(uRs2,vRs2);
+                              if(RmaxS1 < 1.e-4 && RmaxS2 < 1.e-4)
+                              {
+                                if( pntDMin > tDistance && tDistance > 1.e-9)
+                                {
+                                  pntDMin = tDistance;
+                                  VDMin = tiV;
+                                  WLDMin = iL;
+                                }
+                              }
+                            }
+                          }
+
+                          if( VDMin != 0 )
+                          {
+                            const Handle(IntPatch_Line)& aSLine = SLin.Value(WLDMin);
+                            const Handle(IntPatch_WLine)&  aWLine = (*((Handle(IntPatch_WLine)*)&aSLine));
+                            Standard_Integer tiVpar = (Standard_Integer)aWLine->Vertex(VDMin).ParameterOnLine();
+                            Standard_Integer ciVpar = (Standard_Integer)wline->Vertex(ciV).ParameterOnLine();
+                            Standard_Real u11 = 0., u12 = 0., v11 = 0., v12 = 0.;
+                            Standard_Real u21 = 0., u22 = 0., v21 = 0., v22 = 0.;
+                            wline->Point(ciVpar).Parameters(u11,v11,u12,v12);
+                            aWLine->Point(tiVpar).Parameters(u21,v21,u22,v22);
+
+                            Handle(IntSurf_LineOn2S) newL2s = new IntSurf_LineOn2S();
+                            IntSurf_PntOn2S replacePnt = aWLine->Point(tiVpar);
+                            Standard_Integer cNbP = wline->NbPnts();
+
+                            TColStd_SequenceOfInteger VPold;
+                            Standard_Integer iPo;
+                            for( iPo = 1; iPo <= cnbV; iPo++ )
+                            {
+                              Standard_Real Po = wline->Vertex(iPo).ParameterOnLine();
+                              Standard_Integer IPo = (Standard_Integer) Po;
+                              VPold.Append(IPo);
+                            }
+
+                            Standard_Boolean removeNext = Standard_False;
+                            Standard_Boolean removePrev = Standard_False;
+                            if( ciV == 1)
+                            {
+                              Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
+                              if(dPar > 10)
+                              {
+                                removeNext = Standard_True;
+                                for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
+                                  VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
+                              }
+                            }
+                            else if( ciV == cnbV)
+                            {
+                              Standard_Integer dPar = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
+                              if(dPar > 10)
+                              {
+                                removePrev = Standard_True;
+                                VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
+                              }
+                            }
+                            else
+                            {
+                              Standard_Integer dParMi = Abs( VPold.Value(ciV) - VPold.Value(ciV-1));
+                              Standard_Integer dParMa = Abs( VPold.Value(ciV) - VPold.Value(ciV+1));
+                              if(dParMi > 10)
+                              {
+                                removePrev = Standard_True;
+                                VPold.SetValue(ciV, VPold.Value(ciV) - 1 );
+                              }
+
+                              if(dParMa > 10)
+                              {
+                                removeNext = Standard_True;
+                                for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
+                                {
+                                  if(dParMi > 10)
+                                    VPold.SetValue(iPo, VPold.Value(iPo) - 2 );
+                                  else
+                                    VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
+                                }
+                              }
+                              else
+                              {
+                                if(dParMi > 10)
+                                  for( iPo = (ciV+1); iPo <= cnbV; iPo++ )
+                                    VPold.SetValue(iPo, VPold.Value(iPo) - 1 );
+                              } 
+                            }
+
+                            Standard_Integer pI = ciVpar;
+
+                            Standard_Integer iP;
+                            for( iP = 1; iP <= cNbP; iP++)
+                            {
+                              if( pI == iP )
                               {
                                 IntSurf_PntOn2S newPnt = MakeNewPoint(replacePnt, wline->Point(iP), Periods);
                                 newL2s->Add(newPnt);
                               }
-                             else if(removeNext && iP == (pI + 1))
-                               continue;
-                             else if(removePrev && iP == (pI - 1))
-                               continue;
-                             else
-                               newL2s->Add(wline->Point(iP));
-                           }
-
-                           IntPatch_Point newVtx;
-                           gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value();
-                           newVtx.SetValue(Pnt3dV,TolTang,Standard_False);
-                           newVtx.SetParameters(u21,v21,u22,v22);
-                           newVtx.SetParameter(VPold.Value(ciV));
-
-                           Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2);
-
-                           Standard_Integer iV;
-                           for( iV = 1; iV <= cnbV; iV++ ) {
-                             if( iV == ciV )
-                               NWLine->AddVertex(newVtx);
-                             else {
-                               IntPatch_Point theVtx = wline->Vertex(iV);
-                               theVtx.SetParameter(VPold.Value(iV));
-                               NWLine->AddVertex(theVtx);
-                             }
-                           }
-
-                           wline = NWLine;
-                         }
-                       }
-                     }// SLin.Length > 0
+                              else if(removeNext && iP == (pI + 1))
+                                continue;
+                              else if(removePrev && iP == (pI - 1))
+                                continue;
+                              else
+                                newL2s->Add(wline->Point(iP));
+                            }
+
+                            IntPatch_Point newVtx;
+                            gp_Pnt Pnt3dV = aWLine->Vertex(VDMin).Value();
+                            newVtx.SetValue(Pnt3dV,TolTang,Standard_False);
+                            newVtx.SetParameters(u21,v21,u22,v22);
+                            newVtx.SetParameter(VPold.Value(ciV));
+
+                            Handle(IntPatch_WLine) NWLine = new IntPatch_WLine(newL2s,Standard_False,trans1,trans2);
+
+                            Standard_Integer iV;
+                            for( iV = 1; iV <= cnbV; iV++ )
+                            {
+                              if( iV == ciV )
+                                NWLine->AddVertex(newVtx);
+                              else
+                              {
+                                IntPatch_Point theVtx = wline->Vertex(iV);
+                                theVtx.SetParameter(VPold.Value(iV));
+                                NWLine->AddVertex(theVtx);
+                              }
+                            }
+
+                            wline = NWLine;
+                          }//if( VDMin != 0 )
+                        }//for( ciV = 1; ciV <= cnbV; ciV++ )
+                      }// SLin.Length > 0
 
                       AddWLine(SLin, wline, Deflection);
-                     empt = Standard_False;
-                   }// !RejetLigne
-                 }// PW points > 2
-               }// done is True
-             }// dminiPointLigne > SeuildPointLigne
-           }// HasStartPoint
-         }// if TabPtDep[nbps2] == 0
-       } while(nbp>5 && !( (NombreDePointsDeDepartDuCheminement >= NbDePointsDeDepartDuChmLimit && lignetrouvee) || 
-                           (NombreDePointsDeDepartDuCheminement-3 >= nbp && (!lignetrouvee))));
-       delete [] TabPtDep;
+                      empt = Standard_False;
+                    }// !RejetLigne
+                  }// PW points > 2
+                }// done is True
+              }// dminiPointLigne > SeuildPointLigne
+            }// HasStartPoint
+          }// if TabPtDep[nbps2] == 0
+        } while(nbp>5 && !( (NombreDePointsDeDepartDuCheminement >= NbDePointsDeDepartDuChmLimit && lignetrouvee) || 
+          (NombreDePointsDeDepartDuCheminement-3 >= nbp && (!lignetrouvee))));
+        delete [] TabPtDep;
       }// for( ls ...
 
       delete [] TabL;
@@ -2353,182 +2433,206 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
     //--------------------------------------------------------------------
     Standard_Real UminLig1,VminLig1,UmaxLig1,VmaxLig1;
     Standard_Real UminLig2,VminLig2,UmaxLig2,VmaxLig2;
-    
+
     UminLig1=VminLig1=UminLig2=VminLig2=RealLast();
     UmaxLig1=VmaxLig1=UmaxLig2=VmaxLig2=-UminLig1;
 
     // NbPointsInTangentZone always == 1 (eap)
-    
+
     Standard_Integer z;
-    for( z=1; z <= nbTanZon; z++) { 
+    for( z=1; z <= nbTanZon; z++)
+    { 
       //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z);
       //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) {
-       Standard_Integer pz=1;
-       Standard_Real _x,_y,_z;
-       Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
-
-       if(U1>UmaxLig1) UmaxLig1=U1;
-       if(V1>VmaxLig1) VmaxLig1=V1;
-       if(U2>UmaxLig2) UmaxLig2=U2;
-       if(V2>VmaxLig2) VmaxLig2=V2;
-       
-       if(U1<UminLig1) UminLig1=U1;
-       if(V1<VminLig1) VminLig1=V1;
-       if(U2<UminLig2) UminLig2=U2;
-       if(V2<VminLig2) VminLig2=V2;
+      Standard_Integer pz=1;
+      Standard_Real _x,_y,_z;
+      Standard_Real U1, U2, V1, V2;
+      Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
+
+      if(U1>UmaxLig1) UmaxLig1=U1;
+      if(V1>VmaxLig1) VmaxLig1=V1;
+      if(U2>UmaxLig2) UmaxLig2=U2;
+      if(V2>VmaxLig2) VmaxLig2=V2;
+
+      if(U1<UminLig1) UminLig1=U1;
+      if(V1<VminLig1) VminLig1=V1;
+      if(U2<UminLig2) UminLig2=U2;
+      if(V2<VminLig2) VminLig2=V2;
       //}
     }
-    for(z=1; z <= nbTanZon; z++) {    
 
+    for(z=1; z <= nbTanZon; z++)
+    {
       //Standard_Integer NbPointsInTangentZone=Interference.NbPointsInTangentZone(z);
       //for(Standard_Integer pz=1; pz<=NbPointsInTangentZone; pz++) { 
-       Standard_Integer pz=1;
-       Standard_Real _x,_y,_z;
-       Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
-
-       StartParams(1) = U1;
-       StartParams(2) = V1;
-       StartParams(3) = U2;
-       StartParams(4) = V2;
-       
-       //-----------------------------------------------------------------------
-       //-- Calcul du premier point de cheminement a partir du point approche --
-       //-----------------------------------------------------------------------
-       HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);   
-       if(HasStartPoint) { 
-         //-------------------------------------------------
-         //-- Un point a ete trouve                       --
-         //-- On verifie qu il n appartient pas           --
-         //--  a une ligne de cheminement deja calculee.  --
-         //-------------------------------------------------
-         StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-         
-         NbLigCalculee = SLin.Length();
-         dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
-
-         for(Standard_Integer l=1; 
-             (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); 
-             l++) { 
-           const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
-
-            if (IsPointOnLine(StartPOn2S, testwline, Deflection)) {
-              dminiPointLigne = 0.0;
-            }
-         }
-
-         //-- Fin d exploration des lignes
-         if(dminiPointLigne > SeuildPointLigne) { 
-           //---------------------------------------------------
-           //-- Le point de depart du nouveau cheminement     --
-           //-- n est present dans aucune ligne deja calculee.--
-           //---------------------------------------------------
-           PW.Perform(StartParams,
-                        UminLig1,VminLig1,UminLig2,VminLig2,
-                        UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
-           if(PW.IsDone()) {
-             if(PW.NbPoints()>2) { 
-               //-----------------------------------------------
-               //-- Verification a posteriori : 
-               //-- On teste si le point de depart et de fin de 
-               //-- la ligne de cheminement est present dans une 
-               //-- autre ligne . 
-               //-----------------------------------------------
-               RejetLigne = Standard_False;
-               Point3dDebut = PW.Value(1).Value();
-                const IntSurf_PntOn2S& PointFin = PW.Value(PW.NbPoints());
-                Point3dFin   = PointFin.Value();
-               
-               for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-                 const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
-                 //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
-
-                  // Check end point if it is on existing line.
-                  // Start point is checked before.
-                  if (IsPointOnLine(PointFin, verwline, Deflection)) {
-                    RejetLigne = Standard_True; 
-                    break;
+      Standard_Integer pz=1;
+      Standard_Real _x,_y,_z;
+      Standard_Real U1, U2, V1, V2;
+      Interference.GetTangentZonePoint(z,pz,_x,_y,_z,U1,V1,U2,V2);
+
+      StartParams(1) = U1;
+      StartParams(2) = V1;
+      StartParams(3) = U2;
+      StartParams(4) = V2;
+
+      //-----------------------------------------------------------------------
+      //-- Calcul du premier point de cheminement a partir du point approche --
+      //-----------------------------------------------------------------------
+      HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);    
+      if(HasStartPoint)
+      {
+        //-------------------------------------------------
+        //-- Un point a ete trouve                       --
+        //-- On verifie qu il n appartient pas           --
+        //--  a une ligne de cheminement deja calculee.  --
+        //-------------------------------------------------
+        StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
+
+        NbLigCalculee = SLin.Length();
+        dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
+
+        for(Standard_Integer l=1; 
+          (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); 
+          l++)
+        {
+          const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
+
+          if (IsPointOnLine(StartPOn2S, testwline, Deflection))
+          {
+            dminiPointLigne = 0.0;
+          }
+        }
+
+        //-- Fin d exploration des lignes
+        if(dminiPointLigne > SeuildPointLigne)
+        {
+          //---------------------------------------------------
+          //-- Le point de depart du nouveau cheminement     --
+          //-- n est present dans aucune ligne deja calculee.--
+          //---------------------------------------------------
+          PW.Perform(StartParams,UminLig1,VminLig1,UminLig2,VminLig2,
+            UmaxLig1,VmaxLig1,UmaxLig2,VmaxLig2);
+
+          if(PW.IsDone())
+          {
+            if(PW.NbPoints()>2)
+            { 
+              const Standard_Integer aMinNbPoints = 40;
+              if(PW.NbPoints() < aMinNbPoints)
+              {
+                PW.SeekAdditionalPoints(Surf1, Surf2, aMinNbPoints);
+              }
+
+              //-----------------------------------------------
+              //-- Verification a posteriori : 
+              //-- On teste si le point de depart et de fin de 
+              //-- la ligne de cheminement est present dans une 
+              //-- autre ligne . 
+              //-----------------------------------------------
+              RejectLine = Standard_False;
+              Point3dDebut = PW.Value(1).Value();
+              const IntSurf_PntOn2S& PointFin = PW.Value(PW.NbPoints());
+              Point3dFin   = PointFin.Value();
+
+              for(ver=1 ; (!RejectLine) && (ver<= NbLigCalculee) ; ver++)
+              {
+                const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+                //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
+
+                // Check end point if it is on existing line.
+                // Start point is checked before.
+                if (IsPointOnLine(PointFin, verwline, Deflection))
+                {
+                  RejectLine = Standard_True; 
+                  break;
+                }
+
+                const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+                const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
+                if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
+                {
+                  RejectLine = Standard_True; 
+                }
+                else
+                {
+                  if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
+                  {
+                    RejectLine = Standard_True; 
                   }
+                }
+              }
 
-                 const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-                 const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
-                 if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) { 
-                   RejetLigne = Standard_True; 
-                 }
-                 else { 
-                   if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) { 
-                     RejetLigne = Standard_True; 
-                   }
-                 }
-               }
-               
-               if(!RejetLigne) { 
-
-                 IntSurf_TypeTrans trans1,trans2;
-                 Standard_Real locu,locv;
-                 gp_Vec norm1,norm2,d1u,d1v;
-                 gp_Pnt ptbid;
-                 Standard_Integer indextg;
-                 gp_Vec tgline(PW.TangentAtLine(indextg));
-                 PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-                 Surf1->D1(locu,locv,ptbid,d1u,d1v);
-                 norm1 = d1u.Crossed(d1v);
-                 PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-                 Surf2->D1(locu,locv,ptbid,d1u,d1v);
-                 norm2 = d1u.Crossed(d1v);
-                 if (tgline.DotCross(norm2,norm1)>0.) {
-                   trans1 = IntSurf_Out;
-                   trans2 = IntSurf_In;
-                 }
-                 else {
-                   trans1 = IntSurf_In;
-                   trans2 = IntSurf_Out;
-                 }
-                 
-                 
-                 
-                 Standard_Real TolTang = TolTangency;
-                 Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
-                 IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
-                 IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-                 
-                 //---------------
-                    if(wline->NbVertex() == 0) {
-                     IntPatch_Point vtx;
-                     IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(1);
-                     wline->AddVertex(vtx);
-                     
-                     POn2S = PW.Line()->Value(wline->NbPnts());
-                     POn2S.Parameters(pu1,pv1,pu2,pv2);
-                     vtx.SetValue(Point3dFin,TolTang,Standard_False);
-                     vtx.SetParameters(pu1,pv1,pu2,pv2);
-                     vtx.SetParameter(wline->NbPnts());
-                     wline->AddVertex(vtx);
-                   }
-                   
-                 //---------------
-                  AddWLine(SLin, wline, Deflection);
-                 empt = Standard_False;
-                 
-               }
-               else { 
-                 //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
-               }
-               //------------------------------------------------------------          
-             }
-           }  //--  le cheminement a reussi (done a True)
-         }  //--  le point approche ne renvoie pas sur une ligne existante
-       } //-- Si HasStartPoint
+              if(!RejectLine)
+              { 
+                IntSurf_TypeTrans trans1,trans2;
+                Standard_Real locu,locv;
+                gp_Vec norm1,norm2,d1u,d1v;
+                gp_Pnt ptbid;
+                Standard_Integer indextg;
+                gp_Vec tgline(PW.TangentAtLine(indextg));
+                PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+                Surf1->D1(locu,locv,ptbid,d1u,d1v);
+                norm1 = d1u.Crossed(d1v);
+                PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+                Surf2->D1(locu,locv,ptbid,d1u,d1v);
+                norm2 = d1u.Crossed(d1v);
+                if (tgline.DotCross(norm2,norm1)>0.)
+                {
+                  trans1 = IntSurf_Out;
+                  trans2 = IntSurf_In;
+                }
+                else
+                {
+                  trans1 = IntSurf_In;
+                  trans2 = IntSurf_Out;
+                }
+
+                Standard_Real TolTang = TolTangency;
+                Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
+                IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
+                IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
+
+                //---------------
+                if(wline->NbVertex() == 0)
+                {
+                  IntPatch_Point vtx;
+                  IntSurf_PntOn2S POn2S = PW.Line()->Value(1);
+                  POn2S.Parameters(pu1,pv1,pu2,pv2);
+                  vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                  vtx.SetParameters(pu1,pv1,pu2,pv2);
+                  vtx.SetParameter(1);
+                  wline->AddVertex(vtx);
+
+                  POn2S = PW.Line()->Value(wline->NbPnts());
+                  POn2S.Parameters(pu1,pv1,pu2,pv2);
+                  vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                  vtx.SetParameters(pu1,pv1,pu2,pv2);
+                  vtx.SetParameter(wline->NbPnts());
+                  wline->AddVertex(vtx);
+                }
+
+                //---------------
+                AddWLine(SLin, wline, Deflection);
+                empt = Standard_False;
+              }
+              else
+              {
+                //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
+              }
+              //------------------------------------------------------------           
+            }
+          }  //--  le cheminement a reussi (done a True)
+        }  //--  le point approche ne renvoie pas sur une ligne existante
+      } //-- Si HasStartPoint
       //} //-- Boucle Sur les Points de la Tangent Zone
     } //-- Boucle sur Les Tangent Zones
 
-    if ( pInterference ) {
+    if ( pInterference )
+    {
       delete pInterference;
       pInterference = NULL;
     }
+
     return;
   }// if((NbU1*NbV1<=Limit && NbV2*NbU2<=Limit)) {  
 
@@ -2537,20 +2641,20 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
   empt = Standard_True;
   done = Standard_True;
   SLin.Clear();  
-  
+
   Standard_Integer NbLigCalculee = 0;
   Standard_Real U1,U2,V1,V2;
   Standard_Real pu1,pu2,pv1,pv2;
-  
+
   TColStd_Array1OfReal StartParams(1,4);
   Standard_Integer MaxOscill = NbU1;
   if(MaxOscill < NbU2) MaxOscill=NbU2;
   if(MaxOscill < NbV1) MaxOscill=NbV1;
   if(MaxOscill < NbV2) MaxOscill=NbV2;
-  
+
   Standard_Real nIncrement=Increment;
   //if(MaxOscill>10)
-    //nIncrement/=0.5*MaxOscill;
+  //nIncrement/=0.5*MaxOscill;
 
   IntPatch_ThePWalkingInter PW(Surf1,Surf2,TolTangency,Epsilon,Deflection,nIncrement);
   Standard_Real    SeuildPointLigne = 15.0 * Increment * Increment; //-- 10 est insuffisant
@@ -2571,138 +2675,148 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
     StartParams(2) = V1;
     StartParams(3) = U2;
     StartParams(4) = V2;
-    
+
     //-----------------------------------------------------------------------
     //-- Calcul du premier point de cheminement a partir du point approche --
     //-----------------------------------------------------------------------
     HasStartPoint = PW.PerformFirstPoint(StartParams,StartPOn2S);      
-    if(HasStartPoint) { 
+    if(HasStartPoint)
+    { 
       //-------------------------------------------------
       //-- Un point a ete trouve                       --
       //-- On verifie qu il n appartient pas           --
       //--  a une ligne de cheminement deja calculee.  --
       //-------------------------------------------------
       StartPOn2S.Parameters(pu1,pv1,pu2,pv2);
-      
+
       NbLigCalculee = SLin.Length();
       dminiPointLigne = SeuildPointLigne + SeuildPointLigne; 
-      
+
       for(Standard_Integer l=1; 
-         (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); 
-         l++) { 
+        (l <= NbLigCalculee) && (dminiPointLigne >= SeuildPointLigne); 
+        l++)
+      {
         const Handle(IntPatch_WLine)& testwline = *((Handle(IntPatch_WLine)*)&SLin.Value(l));
 
-        if (IsPointOnLine(StartPOn2S, testwline, Deflection)) {
+        if (IsPointOnLine(StartPOn2S, testwline, Deflection))
+        {
           dminiPointLigne = 0.0;
         }
       }
 
       //-- Fin d exploration des lignes
-      if(dminiPointLigne > SeuildPointLigne) { 
-       //---------------------------------------------------
-       //-- Le point de depart du nouveau cheminement     --
-       //-- n est present dans aucune ligne deja calculee.--
-       //---------------------------------------------------
-       PW.Perform(StartParams);
-       if(PW.IsDone()) {
-         if(PW.NbPoints()>2) { 
-           //-----------------------------------------------
-           //-- Verification a posteriori : 
-           //-- On teste si le point de depart et de fin de 
-           //-- la ligne de cheminement est present dans une 
-           //-- autre ligne . 
-           //-----------------------------------------------
-           RejetLigne = Standard_False;
-           Point3dDebut = PW.Value(1).Value();
+      if(dminiPointLigne > SeuildPointLigne)
+      { 
+        //---------------------------------------------------
+        //-- Le point de depart du nouveau cheminement     --
+        //-- n est present dans aucune ligne deja calculee.--
+        //---------------------------------------------------
+        PW.Perform(StartParams);
+        if(PW.IsDone())
+        {
+          if(PW.NbPoints()>2)
+          {
+            //-----------------------------------------------
+            //-- Verification a posteriori : 
+            //-- On teste si le point de depart et de fin de 
+            //-- la ligne de cheminement est present dans une 
+            //-- autre ligne . 
+            //-----------------------------------------------
+            RejetLigne = Standard_False;
+            Point3dDebut = PW.Value(1).Value();
             const IntSurf_PntOn2S& PointFin = PW.Value(PW.NbPoints());
             Point3dFin   = PointFin.Value();
-           
-           for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++) { 
-             const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
-             //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
+
+            for(ver=1 ; (!RejetLigne) && (ver<= NbLigCalculee) ; ver++)
+            {
+              const Handle(IntPatch_WLine)& verwline = *((Handle(IntPatch_WLine)*)&SLin.Value(ver));
+              //-- Handle(IntPatch_WLine) verwline=Handle(IntPatch_WLine)::DownCast(SLin.Value(ver));
 
               // Check end point if it is on existing line.
               // Start point is checked before.
-              if (IsPointOnLine(PointFin, verwline, Deflection)) {
+              if (IsPointOnLine(PointFin, verwline, Deflection))
+              {
                 RejetLigne = Standard_True; 
                 break;
               }
 
-             const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
-             const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
-             if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency) { 
-               RejetLigne = Standard_True; 
-             }
-             else { 
-               if(Point3dFin.Distance(verPointFin.Value()) < TolTangency) { 
-                 RejetLigne = Standard_True; 
-               }
-             }
-           }
-           
-           if(!RejetLigne) { 
-             
-             IntSurf_TypeTrans trans1,trans2;
-             Standard_Real locu,locv;
-             gp_Vec norm1,norm2,d1u,d1v;
-             gp_Pnt ptbid;
-             Standard_Integer indextg;
-             gp_Vec tgline(PW.TangentAtLine(indextg));
-             PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
-             Surf1->D1(locu,locv,ptbid,d1u,d1v);
-             norm1 = d1u.Crossed(d1v);
-             PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
-             Surf2->D1(locu,locv,ptbid,d1u,d1v);
-             norm2 = d1u.Crossed(d1v);
-             if (tgline.DotCross(norm2,norm1)>0.) {
-               trans1 = IntSurf_Out;
-               trans2 = IntSurf_In;
-             }
-             else {
-               trans1 = IntSurf_In;
-               trans2 = IntSurf_Out;
-             }
-             
-             
-             
-             Standard_Real TolTang = TolTangency;
-             Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
-             IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
-             IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
-             
-             //---------------
-             if(wline->NbVertex() == 0) {
-               IntPatch_Point vtx;
-               const IntSurf_PntOn2S& POn2Sf = PW.Line()->Value(1);
-               POn2Sf.Parameters(pu1,pv1,pu2,pv2);
-               vtx.SetValue(Point3dDebut,TolTang,Standard_False);
-               vtx.SetParameters(pu1,pv1,pu2,pv2);
-               vtx.SetParameter(1);
-               wline->AddVertex(vtx);
-               
-               const IntSurf_PntOn2S& POn2Sl = PW.Line()->Value(wline->NbPnts());
-               POn2Sl.Parameters(pu1,pv1,pu2,pv2);
-               vtx.SetValue(Point3dFin,TolTang,Standard_False);
-               vtx.SetParameters(pu1,pv1,pu2,pv2);
-               vtx.SetParameter(wline->NbPnts());
-               wline->AddVertex(vtx);
-             }
-             
-             //---------------
+              const IntSurf_PntOn2S& verPointDebut = verwline->Point(1);
+              const IntSurf_PntOn2S& verPointFin   = verwline->Point(verwline->NbPnts());
+              if(Point3dDebut.Distance(verPointDebut.Value()) < TolTangency)
+              {
+                RejetLigne = Standard_True; 
+              }
+              else
+              {
+                if(Point3dFin.Distance(verPointFin.Value()) < TolTangency)
+                {
+                  RejetLigne = Standard_True; 
+                }
+              }
+            }
+
+            if(!RejetLigne)
+            {
+              IntSurf_TypeTrans trans1,trans2;
+              Standard_Real locu,locv;
+              gp_Vec norm1,norm2,d1u,d1v;
+              gp_Pnt ptbid;
+              Standard_Integer indextg;
+              gp_Vec tgline(PW.TangentAtLine(indextg));
+              PW.Line()->Value(indextg).ParametersOnS1(locu,locv);
+              Surf1->D1(locu,locv,ptbid,d1u,d1v);
+              norm1 = d1u.Crossed(d1v);
+              PW.Line()->Value(indextg).ParametersOnS2(locu,locv);
+              Surf2->D1(locu,locv,ptbid,d1u,d1v);
+              norm2 = d1u.Crossed(d1v);
+              if (tgline.DotCross(norm2,norm1)>0.)
+              {
+                trans1 = IntSurf_Out;
+                trans2 = IntSurf_In;
+              }
+              else {
+                trans1 = IntSurf_In;
+                trans2 = IntSurf_Out;
+              }
+
+              Standard_Real TolTang = TolTangency;
+              Handle(IntPatch_WLine) wline = new IntPatch_WLine(PW.Line(),Standard_False,trans1,trans2);
+              IntPatch_RstInt::PutVertexOnLine(wline,Surf1,D1,Surf2,Standard_True,TolTang);
+              IntPatch_RstInt::PutVertexOnLine(wline,Surf2,D2,Surf1,Standard_False,TolTang);
+
+              //---------------
+              if(wline->NbVertex() == 0)
+              {
+                IntPatch_Point vtx;
+                const IntSurf_PntOn2S& POn2Sf = PW.Line()->Value(1);
+                POn2Sf.Parameters(pu1,pv1,pu2,pv2);
+                vtx.SetValue(Point3dDebut,TolTang,Standard_False);
+                vtx.SetParameters(pu1,pv1,pu2,pv2);
+                vtx.SetParameter(1);
+                wline->AddVertex(vtx);
+
+                const IntSurf_PntOn2S& POn2Sl = PW.Line()->Value(wline->NbPnts());
+                POn2Sl.Parameters(pu1,pv1,pu2,pv2);
+                vtx.SetValue(Point3dFin,TolTang,Standard_False);
+                vtx.SetParameters(pu1,pv1,pu2,pv2);
+                vtx.SetParameter(wline->NbPnts());
+                wline->AddVertex(vtx);
+              }
+
+              //---------------
               AddWLine(SLin, wline, Deflection);
-             empt = Standard_False;
-             
-           }
-           else { 
-             //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
-           }
-           //------------------------------------------------------------              
-         }
-       }  //--  le cheminement a reussi (done a True)
+              empt = Standard_False;
+            }
+            else
+            { 
+              //-- cout<<" ----- REJET DE LIGNE (POINT DE DEPART) ----- "<<endl;
+            }
+            //------------------------------------------------------------             
+          }
+        }  //--  le cheminement a reussi (done a True)
       }  //--  le point approche ne renvoie pas sur une ligne existante
     } //-- Si HasStartPoint
   } //-- Boucle sur Les Tangent Zones
-    
 }
 //modified by NIZNHY-PKV Wed May 25 09:39:07 2011f
 //=======================================================================
@@ -2710,7 +2824,7 @@ void IntPatch_PrmPrmIntersection::Perform (const Handle(Adaptor3d_HSurface)& Sur
 //purpose  : 
 //=======================================================================
 class IntPatch_InfoPD {
- public:
+public:
   //----------------------------------------C-tor
   IntPatch_InfoPD(const Standard_Integer aNBI) {
     Standard_Integer aNBI2, i, j;
@@ -2726,12 +2840,12 @@ class IntPatch_InfoPD {
     //
     for (i=0; i<myNBI; ++i) {
       for (j=0; j<myNBI; ++j) {
-       xP1DS2(i, j)=0;
-       xP2DS1(i, j)=0;
-       xIP1(i, j)=0;
-       xIP2(i, j)=0;
-       xP1(i, j).SetCoord(0., 0., 0.);
-       xP2(i, j).SetCoord(0., 0., 0.);
+        xP1DS2(i, j)=0;
+        xP2DS1(i, j)=0;
+        xIP1(i, j)=0;
+        xIP2(i, j)=0;
+        xP1(i, j).SetCoord(0., 0., 0.);
+        xP2(i, j).SetCoord(0., 0., 0.);
       }
     }
   };
@@ -2746,8 +2860,8 @@ class IntPatch_InfoPD {
   };
   //---------------------------------------- Index
   Standard_Integer Index(const Standard_Integer i,
-                        const Standard_Integer j) const { 
-    return i*myNBI+j;
+    const Standard_Integer j) const { 
+      return i*myNBI+j;
   };
   //---------------------------------------- NBI
   Standard_Integer NBI() const { 
@@ -2755,35 +2869,35 @@ class IntPatch_InfoPD {
   };
   //----------------------------------------xP1DS2
   char& xP1DS2(const Standard_Integer i,
-              const Standard_Integer j) { 
-    return myP1DS2[Index(i,j)];
+    const Standard_Integer j) { 
+      return myP1DS2[Index(i,j)];
   };
   //----------------------------------------xP2DS1
   char& xP2DS1(const Standard_Integer i,
-              const Standard_Integer j) { 
-    return myP2DS1[Index(i,j)];
+    const Standard_Integer j) { 
+      return myP2DS1[Index(i,j)];
   };
   //----------------------------------------xIP1
   Standard_Integer& xIP1(const Standard_Integer i,
-                        const Standard_Integer j) { 
-    return myIP1[Index(i,j)];
+    const Standard_Integer j) { 
+      return myIP1[Index(i,j)];
   };
   //----------------------------------------xIP2
   Standard_Integer& xIP2(const Standard_Integer i,
-                        const Standard_Integer j) { 
-    return myIP2[Index(i,j)];
+    const Standard_Integer j) { 
+      return myIP2[Index(i,j)];
   };
   //----------------------------------------xP1
   gp_Pnt& xP1(const Standard_Integer i,
-             const Standard_Integer j) { 
-    return myP1[Index(i,j)];
+    const Standard_Integer j) { 
+      return myP1[Index(i,j)];
   };
   //----------------------------------------xP1
   gp_Pnt& xP2(const Standard_Integer i,
-             const Standard_Integer j) { 
-    return myP2[Index(i,j)];
+    const Standard_Integer j) { 
+      return myP2[Index(i,j)];
   };
- protected:
+protected:
   Standard_Integer myNBI;
   char *myP1DS2;
   char *myP2DS1;
@@ -2798,12 +2912,12 @@ class IntPatch_InfoPD {
 // purpose  : 
 //==================================================================================
 void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S,
-                                             const Handle(Adaptor3d_HSurface)& S1,
-                                             const Standard_Integer SU_1,
-                                             const Standard_Integer SV_1,
-                                             const Handle(Adaptor3d_HSurface)& S2,
-                                             const Standard_Integer SU_2,
-                                             const Standard_Integer SV_2) const 
+                                              const Handle(Adaptor3d_HSurface)& S1,
+                                              const Standard_Integer SU_1,
+                                              const Standard_Integer SV_1,
+                                              const Handle(Adaptor3d_HSurface)& S2,
+                                              const Standard_Integer SU_2,
+                                              const Standard_Integer SV_2) const 
 { 
   Standard_Integer i, j, xNBI;
   //modified by NIZNHY-PKV Tue May 24 11:37:38 2011f
@@ -2854,13 +2968,13 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       aIPD.xP1(i, j)= S1->Value(U,V);
       Box1.Add(aIPD.xP1(i, j));
       if(i>0 && j>0) { 
-       aIPD.xP1(i, j)    .Coord(x0,y0,z0);
-       aIPD.xP1(i-1, j-1).Coord(x1,y1,z1);
-       //
-       d=Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
-       if(d>dmaxOn1) {
-         dmaxOn1 = d;
-       }
+        aIPD.xP1(i, j)    .Coord(x0,y0,z0);
+        aIPD.xP1(i-1, j-1).Coord(x1,y1,z1);
+        //
+        d=Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
+        if(d>dmaxOn1) {
+          dmaxOn1 = d;
+        }
       }
     }
   }
@@ -2878,12 +2992,12 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       aIPD.xP2(i, j) = S2->Value(U,V);
       Box2.Add(aIPD.xP2(i, j));
       if(i>0 && j>0) { 
-       aIPD.xP2(i, j)    .Coord(x0,y0,z0);
-       aIPD.xP2(i-1, j-1).Coord(x1,y1,z1);
-       d =  Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
-       if(d>dmaxOn2) {
-         dmaxOn2 = d;
-       }
+        aIPD.xP2(i, j)    .Coord(x0,y0,z0);
+        aIPD.xP2(i-1, j-1).Coord(x1,y1,z1);
+        d =  Abs(x1-x0)+Abs(y1-y0)+Abs(z1-z0);
+        if(d>dmaxOn2) {
+          dmaxOn2 = d;
+        }
       }
     }
   }
@@ -2891,7 +3005,7 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
   //--------
   //
   if(Box1.IsOut(Box2)) {
-    
+
     return;
   }
   //
@@ -2967,13 +3081,13 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       aIPD.xP1DS2(i, j) = (char)CodeReject(x20,y20,z20,x21,y21,z21,P.X(),P.Y(),P.Z());
       int ix = (int)((P.X()-x0  + dx2 )/dx);
       if(DansGrille(ix)) { 
-       int iy = (int)((P.Y()-y0 + dy2)/dy);
-       if(DansGrille(iy)) {
-         int iz = (int)((P.Z()-z0 + dz2)/dz);
-         if(DansGrille(iz)) {
-           aIPD.xIP1(i, j) = GrilleInteger(ix,iy,iz);
-         }
-       }
+        int iy = (int)((P.Y()-y0 + dy2)/dy);
+        if(DansGrille(iy)) {
+          int iz = (int)((P.Z()-z0 + dz2)/dz);
+          if(DansGrille(iz)) {
+            aIPD.xIP1(i, j) = GrilleInteger(ix,iy,iz);
+          }
+        }
       }
     }
   }
@@ -2985,13 +3099,13 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       aIPD.xP2DS1(i, j) = (char)CodeReject(x10,y10,z10,x11,y11,z11,P.X(),P.Y(),P.Z());
       int ix = (int)((P.X()-x0 + dx2)/dx);
       if(DansGrille(ix)) { 
-       int iy = (int)((P.Y()-y0 + dy2)/dy);
-       if(DansGrille(iy)) {
-         int iz = (int)((P.Z()-z0 + dz2)/dz);
-         if(DansGrille(iz)) {
-           aIPD.xIP2(i, j) =  GrilleInteger(ix,iy,iz);
-         }
-       }
+        int iy = (int)((P.Y()-y0 + dy2)/dy);
+        if(DansGrille(iy)) {
+          int iz = (int)((P.Z()-z0 + dz2)/dz);
+          if(DansGrille(iz)) {
+            aIPD.xIP2(i, j) =  GrilleInteger(ix,iy,iz);
+          }
+        }
       }
     }
   }
@@ -2999,18 +3113,18 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
   for(i=0;i<SU1-1;i+=1) {
     for(j=0;j<SV1-1;j+=1) { 
       if(!((aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j)) || 
-          (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))){
-       Remplit(aIPD.xIP1(i, j),
-               aIPD.xIP1(i+1, j),
-               aIPD.xIP1(i+1, j+1),
-               M1);
+        (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))){
+          Remplit(aIPD.xIP1(i, j),
+            aIPD.xIP1(i+1, j),
+            aIPD.xIP1(i+1, j+1),
+            M1);
       }
       if(!((aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i, j+1)) || 
-          (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))) {
-       Remplit(aIPD.xIP1(i, j),
-               aIPD.xIP1(i, j+1),
-               aIPD.xIP1(i+1, j+1),
-               M1);    
+        (aIPD.xP1DS2(i, j) & aIPD.xP1DS2(i+1, j+1)))) {
+          Remplit(aIPD.xIP1(i, j),
+            aIPD.xIP1(i, j+1),
+            aIPD.xIP1(i+1, j+1),
+            M1);       
       }
     }
   }    
@@ -3018,18 +3132,18 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
   for(i=0;i<SU2-1;i+=1) {
     for(j=0;j<SV2-1;j+=1) { 
       if(!((aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j)) ||
-          (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
-       Remplit(aIPD.xIP2(i, j),
-               aIPD.xIP2(i+1, j),
-               aIPD.xIP2(i+1, j+1),
-               M2);
+        (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
+          Remplit(aIPD.xIP2(i, j),
+            aIPD.xIP2(i+1, j),
+            aIPD.xIP2(i+1, j+1),
+            M2);
       }
       if(!((aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i, j+1)) || 
-          (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
-       Remplit(aIPD.xIP2(i, j),
-               aIPD.xIP2(i, j+1),
-               aIPD.xIP2(i+1, j+1),
-               M2);    
+        (aIPD.xP2DS1(i, j) & aIPD.xP2DS1(i+1, j+1)))){
+          Remplit(aIPD.xIP2(i, j),
+            aIPD.xIP2(i, j+1),
+            aIPD.xIP2(i+1, j+1),
+            M2);       
       }
     }
   }    
@@ -3051,30 +3165,30 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       int nb=0;
       int LIM=3;
       if(   DansGrille(i-1) && DansGrille(j-1) && DansGrille(k-1) 
-        && DansGrille(i+1) && DansGrille(j+1) && DansGrille(k+1)) { 
-       int si,sj,sk;
-       for(si=-1; si<= 1 && nb<LIM; si++) { 
-         for(sj=-1; sj<= 1 && nb<LIM; sj++) { 
-           for(sk=-1; sk<= 1 && nb<LIM; sk++) { 
-             long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
-             if(M1.Val(lu) && M2.Val(lu)) { 
-               nb++;
-             }
-           }
-         }
-       }
-       if(nb>=LIM) { 
-         for(si=-1; si<= 1; si++) { 
-           for(sj=-1; sj<= 1; sj++) { 
-             for(sk=-1; sk<= 1; sk++) { 
-               if(si || sj || sk) { 
-                 long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
-                 M1.Raz(lu);
-               }
-             }
-           }
-         }
-       }
+        && DansGrille(i+1) && DansGrille(j+1) && DansGrille(k+1)) { 
+          int si,sj,sk;
+          for(si=-1; si<= 1 && nb<LIM; si++) { 
+            for(sj=-1; sj<= 1 && nb<LIM; sj++) { 
+              for(sk=-1; sk<= 1 && nb<LIM; sk++) { 
+                long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
+                if(M1.Val(lu) && M2.Val(lu)) { 
+                  nb++;
+                }
+              }
+            }
+          }
+          if(nb>=LIM) { 
+            for(si=-1; si<= 1; si++) { 
+              for(sj=-1; sj<= 1; sj++) { 
+                for(sk=-1; sk<= 1; sk++) { 
+                  if(si || sj || sk) { 
+                    long unsigned lu=GrilleInteger(i+si,j+sj,k+sk);
+                    M1.Raz(lu);
+                  }
+                }
+              }
+            }
+          }
       }
       //
       gp_Pnt P(dx*i + x0, dy*j + y0, dz*k+z0);
@@ -3083,113 +3197,113 @@ void IntPatch_PrmPrmIntersection::PointDepart(Handle(IntSurf_LineOn2S)& LineOn2S
       Standard_Integer nv1=0, nv2=0;
       int nbsur1 = 0;
       for(nu=0;nu1<0 && nu<SU1;nu++) { 
-       for(nv=0;nu1<0 && nv<SV1;nv++) { 
-         if( aIPD.xIP1(nu, nv) ==(Standard_Integer) newind )  { 
-           nbsur1++;
-           aIPD.xIP1(nu, nv)=indicepointtraite;
-           nu1=nu; nv1=nv;
-         }
-       }
+        for(nv=0;nu1<0 && nv<SV1;nv++) { 
+          if( aIPD.xIP1(nu, nv) ==(Standard_Integer) newind )  { 
+            nbsur1++;
+            aIPD.xIP1(nu, nv)=indicepointtraite;
+            nu1=nu; nv1=nv;
+          }
+        }
       }
       if(nu1>=0) { 
-       int nbsur2 = 0;
-       for(nu=0;nu2<0 && nu<SU2;nu++) { 
-         for(nv=0;nu2<0 && nv<SV2;nv++) { 
-           if( aIPD.xIP2(nu, nv)==(Standard_Integer) newind )  { 
-             nbsur2++;
-             aIPD.xIP2(nu, nv)=indicepointtraite;
-             nu2=nu; nv2=nv;
-           }
-         }
-       }
+        int nbsur2 = 0;
+        for(nu=0;nu2<0 && nu<SU2;nu++) { 
+          for(nv=0;nu2<0 && nv<SV2;nv++) { 
+            if( aIPD.xIP2(nu, nv)==(Standard_Integer) newind )  { 
+              nbsur2++;
+              aIPD.xIP2(nu, nv)=indicepointtraite;
+              nu2=nu; nv2=nv;
+            }
+          }
+        }
       }
       if(nu1>=0 && nu2>=0) { 
-       IntSurf_PntOn2S POn2S;
-       POn2S.SetValue(P, 
-                      S1->FirstUParameter()+nu1*du1,
-                      S1->FirstVParameter()+nv1*dv1,
-                      S2->FirstUParameter()+nu2*du2,
-                      S2->FirstVParameter()+nv2*dv2);
-       LineOn2S->Add(POn2S);
-       Compt++;
+        IntSurf_PntOn2S POn2S;
+        POn2S.SetValue(P, 
+          S1->FirstUParameter()+nu1*du1,
+          S1->FirstVParameter()+nv1*dv1,
+          S2->FirstUParameter()+nu2*du2,
+          S2->FirstVParameter()+nv2*dv2);
+        LineOn2S->Add(POn2S);
+        Compt++;
       }
       else { 
-       //-- aucun point du triangle n a ete trouve assez proche
-       //-- on recherche les 3 points les plus proches de P 
-       //-- dans chacun des tableaux 
-                 Standard_Real Dist3[3],u3[3] = { 0.0, 0.0, 0.0 },v3[3] = { 0.0, 0.0, 0.0 };
-       Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
-       for(U=resu0,i=0; i<SU1; i++,U+=du1) { 
-         for(V=resv0,j=0; j<SV1; V+=dv1,j++) {       
-           //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
-           Standard_Real t = aIPD.xP1(i, j).SquareDistance(P);
-           //-- On remplace la plus grande valeur ds Dist[.] par la val courante
-           if(Dist3[0]<Dist3[1]) { 
-             Standard_Real z;
-             z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
-             z=u3[0]; u3[0]=u3[1]; u3[1]=z;
-             z=v3[0]; v3[0]=v3[1]; v3[1]=z;
-           }
-           if(Dist3[1]<Dist3[2]) { 
-             Standard_Real z;
-             z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
-             z=u3[1]; u3[1]=u3[2]; u3[2]=z;
-             z=v3[1]; v3[1]=v3[2]; v3[2]=z;
-           }
-           if(Dist3[0]<Dist3[1]) { 
-             Standard_Real z;
-             z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
-             z=u3[0]; u3[0]=u3[1]; u3[1]=z;
-             z=v3[0]; v3[0]=v3[1]; v3[1]=z;
-           }
-           //-- la plus grande valeur est dans Dist3[0]
-           if(t<Dist3[0]) { 
-             Dist3[0]=t; u3[0]=U; v3[0]=V;
-           }
-         }
-       }
-       //
-       Standard_Real U1_3 = (u3[0]+u3[1]+u3[2])/3.0;
-       Standard_Real V1_3 = (v3[0]+v3[1]+v3[2])/3.0;
-       
-       Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
-       for(U=U0,i=0; i<SU2; i++,U+=du2) { 
-         for(V=V0,j=0; j<SV2; V+=dv2,j++) {       
-           //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
-           Standard_Real t = aIPD.xP2(i, j).SquareDistance(P);
-           //-- On remplace la plus grande valeur ds Dist3[.] par la val courante
-           if(Dist3[0]<Dist3[1]) { 
-             Standard_Real z;
-             z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
-             z=u3[0]; u3[0]=u3[1]; u3[1]=z;
-             z=v3[0]; v3[0]=v3[1]; v3[1]=z;
-           }
-           if(Dist3[1]<Dist3[2]) { 
-             Standard_Real z;
-             z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
-             z=u3[1]; u3[1]=u3[2]; u3[2]=z;
-             z=v3[1]; v3[1]=v3[2]; v3[2]=z;
-           }
-           if(Dist3[0]<Dist3[1]) { 
-             Standard_Real z;
-             z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
-             z=u3[0]; u3[0]=u3[1]; u3[1]=z;
-             z=v3[0]; v3[0]=v3[1]; v3[1]=z;
-           }
-           //-- la plus grande valeur est dans Dist3[0]
-           if(t<Dist3[0]) { 
-             Dist3[0]=t; u3[0]=U; v3[0]=V;
-           }
-         }
-       }
-       //
-       Standard_Real U2_3 = (u3[0]+u3[1]+u3[2])/3.0;
-       Standard_Real V2_3 = (v3[0]+v3[1]+v3[2])/3.0;
-       //
-       IntSurf_PntOn2S POn2S;
-       POn2S.SetValue(P,U1_3,V1_3,U2_3,V2_3);
-       LineOn2S->Add(POn2S);
-       Compt++;        
+        //-- aucun point du triangle n a ete trouve assez proche
+        //-- on recherche les 3 points les plus proches de P 
+        //-- dans chacun des tableaux 
+        Standard_Real Dist3[3],u3[3] = { 0.0, 0.0, 0.0 },v3[3] = { 0.0, 0.0, 0.0 };
+        Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
+        for(U=resu0,i=0; i<SU1; i++,U+=du1) { 
+          for(V=resv0,j=0; j<SV1; V+=dv1,j++) {       
+            //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
+            Standard_Real t = aIPD.xP1(i, j).SquareDistance(P);
+            //-- On remplace la plus grande valeur ds Dist[.] par la val courante
+            if(Dist3[0]<Dist3[1]) { 
+              Standard_Real z;
+              z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
+              z=u3[0]; u3[0]=u3[1]; u3[1]=z;
+              z=v3[0]; v3[0]=v3[1]; v3[1]=z;
+            }
+            if(Dist3[1]<Dist3[2]) { 
+              Standard_Real z;
+              z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
+              z=u3[1]; u3[1]=u3[2]; u3[2]=z;
+              z=v3[1]; v3[1]=v3[2]; v3[2]=z;
+            }
+            if(Dist3[0]<Dist3[1]) { 
+              Standard_Real z;
+              z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
+              z=u3[0]; u3[0]=u3[1]; u3[1]=z;
+              z=v3[0]; v3[0]=v3[1]; v3[1]=z;
+            }
+            //-- la plus grande valeur est dans Dist3[0]
+            if(t<Dist3[0]) { 
+              Dist3[0]=t; u3[0]=U; v3[0]=V;
+            }
+          }
+        }
+        //
+        Standard_Real U1_3 = (u3[0]+u3[1]+u3[2])/3.0;
+        Standard_Real V1_3 = (v3[0]+v3[1]+v3[2])/3.0;
+
+        Dist3[0]=Dist3[1]=Dist3[2]=RealLast();
+        for(U=U0,i=0; i<SU2; i++,U+=du2) { 
+          for(V=V0,j=0; j<SV2; V+=dv2,j++) {       
+            //-- On place les 3 meilleures valeurs dans Dist1,Dist2,Dist3
+            Standard_Real t = aIPD.xP2(i, j).SquareDistance(P);
+            //-- On remplace la plus grande valeur ds Dist3[.] par la val courante
+            if(Dist3[0]<Dist3[1]) { 
+              Standard_Real z;
+              z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
+              z=u3[0]; u3[0]=u3[1]; u3[1]=z;
+              z=v3[0]; v3[0]=v3[1]; v3[1]=z;
+            }
+            if(Dist3[1]<Dist3[2]) { 
+              Standard_Real z;
+              z=Dist3[1]; Dist3[1]=Dist3[2]; Dist3[2]=z;
+              z=u3[1]; u3[1]=u3[2]; u3[2]=z;
+              z=v3[1]; v3[1]=v3[2]; v3[2]=z;
+            }
+            if(Dist3[0]<Dist3[1]) { 
+              Standard_Real z;
+              z=Dist3[0]; Dist3[0]=Dist3[1]; Dist3[1]=z;
+              z=u3[0]; u3[0]=u3[1]; u3[1]=z;
+              z=v3[0]; v3[0]=v3[1]; v3[1]=z;
+            }
+            //-- la plus grande valeur est dans Dist3[0]
+            if(t<Dist3[0]) { 
+              Dist3[0]=t; u3[0]=U; v3[0]=V;
+            }
+          }
+        }
+        //
+        Standard_Real U2_3 = (u3[0]+u3[1]+u3[2])/3.0;
+        Standard_Real V2_3 = (v3[0]+v3[1]+v3[2])/3.0;
+        //
+        IntSurf_PntOn2S POn2S;
+        POn2S.SetValue(P,U1_3,V1_3,U2_3,V2_3);
+        LineOn2S->Add(POn2S);
+        Compt++;       
       }
     }
   }
@@ -3212,62 +3326,62 @@ Standard_Boolean IsPointOnLine(const IntSurf_PntOn2S        &thePOn2S,
   thePOn2S.Parameters(pu1, pv1, pu2, pv2);
 
   if ((theWLine->IsOutSurf1Box(gp_Pnt2d(pu1, pv1)) == Standard_False) &&
-      (theWLine->IsOutSurf2Box(gp_Pnt2d(pu2, pv2)) == Standard_False) &&
-      (theWLine->IsOutBox(thePOn2S.Value())        == Standard_False)) {
-    const Standard_Integer NbPntOn2SOnLine = theWLine->NbPnts();
-    Standard_Integer ll;
-
-    for (ll=1; ll < NbPntOn2SOnLine && !isOnLine; ll++) {
-      const gp_Pnt &Pa     = theWLine->Point(ll).Value();
-      const gp_Pnt &Pb     = theWLine->Point(ll+1).Value();
-      const gp_Pnt &PStart = thePOn2S.Value();
-      const gp_Vec  AM(Pa, PStart);
-      const gp_Vec  MB(PStart,Pb);
-      const Standard_Real AMMB = AM.Dot(MB);
-
-      if(AMMB > 0.0) {
-        gp_Dir ABN(Pb.X() - Pa.X(), Pb.Y() - Pa.Y(), Pb.Z() - Pa.Z());
-        Standard_Real lan =  ABN.X()*AM.X() + ABN.Y()*AM.Y() + ABN.Z()*AM.Z();
-        gp_Vec AH(lan*ABN.X(), lan*ABN.Y(), lan*ABN.Z());
-        gp_Vec HM(AM.X() - AH.X(), AM.Y() - AH.Y(), AM.Z() - AH.Z());
-        Standard_Real d = 0.0;
-  
-        if(HM.X() < Deflection) {
-          d += HM.X()*HM.X();
-
-          if(HM.Y() < Deflection) {
-            d += HM.Y()*HM.Y();
-
-            if(HM.Z() < Deflection) {
-              d += HM.Z()*HM.Z();
+    (theWLine->IsOutSurf2Box(gp_Pnt2d(pu2, pv2)) == Standard_False) &&
+    (theWLine->IsOutBox(thePOn2S.Value())        == Standard_False)) {
+      const Standard_Integer NbPntOn2SOnLine = theWLine->NbPnts();
+      Standard_Integer ll;
+
+      for (ll=1; ll < NbPntOn2SOnLine && !isOnLine; ll++) {
+        const gp_Pnt &Pa     = theWLine->Point(ll).Value();
+        const gp_Pnt &Pb     = theWLine->Point(ll+1).Value();
+        const gp_Pnt &PStart = thePOn2S.Value();
+        const gp_Vec  AM(Pa, PStart);
+        const gp_Vec  MB(PStart,Pb);
+        const Standard_Real AMMB = AM.Dot(MB);
+
+        if(AMMB > 0.0) {
+          gp_Dir ABN(Pb.X() - Pa.X(), Pb.Y() - Pa.Y(), Pb.Z() - Pa.Z());
+          Standard_Real lan =  ABN.X()*AM.X() + ABN.Y()*AM.Y() + ABN.Z()*AM.Z();
+          gp_Vec AH(lan*ABN.X(), lan*ABN.Y(), lan*ABN.Z());
+          gp_Vec HM(AM.X() - AH.X(), AM.Y() - AH.Y(), AM.Z() - AH.Z());
+          Standard_Real d = 0.0;
+
+          if(HM.X() < Deflection) {
+            d += HM.X()*HM.X();
+
+            if(HM.Y() < Deflection) {
+              d += HM.Y()*HM.Y();
+
+              if(HM.Z() < Deflection) {
+                d += HM.Z()*HM.Z();
+              } else {
+                d = Deflection2;
+              }
             } else {
               d = Deflection2;
             }
           } else {
             d = Deflection2;
           }
-        } else {
-          d = Deflection2;
-        }
 
-        if(d < Deflection2) {
-          isOnLine = Standard_True;
-        }
-      } else {
-        Standard_Real dab = Pa.SquareDistance(Pb);
-        Standard_Real dap = Pa.SquareDistance(PStart);
-
-        if(dap < dab) {
-          isOnLine = Standard_True;
+          if(d < Deflection2) {
+            isOnLine = Standard_True;
+          }
         } else {
-          Standard_Real dbp = Pb.SquareDistance(PStart);
+          Standard_Real dab = Pa.SquareDistance(Pb);
+          Standard_Real dap = Pa.SquareDistance(PStart);
 
-          if(dbp < dab) {
+          if(dap < dab) {
             isOnLine = Standard_True;
+          } else {
+            Standard_Real dbp = Pb.SquareDistance(PStart);
+
+            if(dbp < dab) {
+              isOnLine = Standard_True;
+            }
           }
         }
       }
-    }
   }
 
   return isOnLine;
@@ -3290,7 +3404,7 @@ void AddWLine(IntPatch_SequenceOfLine      &theLines,
   while (i <= aNbLines) {
     Handle(IntPatch_WLine) aWLine =
       Handle(IntPatch_WLine)::DownCast(theLines.Value(i));
-    
+
     isToRemove = Standard_False;
 
     if (aWLine.IsNull() == Standard_False) {
index 1d0ef2f..5c49296 100644 (file)
@@ -32,7 +32,8 @@ uses XY                  from gp,
      PntOn2S             from IntSurf,
      LineOn2S            from IntSurf,
      Dir                 from gp,
-     Dir2d               from gp
+     Dir2d               from gp,
+     Pnt                 from gp
      
      
 raises OutOfRange from Standard,
@@ -248,14 +249,36 @@ is
        is static;
 
     AddAPoint ( me    : in out  ; 
-               line  : in  out  LineOn2S  from  IntSurf  ;     
-               POn2S :          PntOn2S   from  IntSurf  ) ;
-       ---C++: inline
-               
+    line  : in  out  LineOn2S  from  IntSurf  ;     
+    POn2S :          PntOn2S   from  IntSurf  ) ;
+    ---C++: inline
+    
     ExtendLineInCommonZone(me: in out; theChoixIso: ConstIsoparametric  from IntImp;
-                                      theDirectionFlag: Boolean from Standard)
-       returns Boolean from Standard
-       is private;
+theDirectionFlag: Boolean from Standard)
+    returns Boolean from Standard
+    is private;
+  
+  DistanceMinimizeByGradient( me    : in out;
+                              theASurf1 , theASurf2  : ThePSurface ;
+                              theU1, theV1, theU2, theV2: out Real from Standard;
+                              theStep0U1V1: Real from Standard = 1.0e-6;
+                              theStep0U2V2: Real from Standard = 1.0e-6)
+    returns Boolean from Standard
+    is private;
+  
+  DistanceMinimizeByExtrema(me          : in out;
+                            theASurf1   : ThePSurface ;
+                            theP0       : Pnt from gp;
+                            theU0, theV0: out Real from Standard;
+                            theStep0U: Real from Standard = 1.0;
+                            theStep0V: Real from Standard = 1.0)
+    returns Boolean from Standard
+    is private;
+  
+  SeekAdditionalPoints( me    : in out;
+                        theASurf1 , theASurf2  : ThePSurface;
+                        theMinNbPoints : Integer from Standard)
+    returns Boolean from Standard;
 
 fields
 
index ff237eb..0955a25 100644 (file)
@@ -19,6 +19,8 @@
 #include <Precision.hxx>
 #include <math_FunctionSetRoot.hxx>
 
+#include <Geom_Surface.hxx>
+
 //#define KELARG 20.0
 
 //==================================================================================
 // during change of isos 
 //==================================================================================
 void ComputePasInit(Standard_Real *pasuv,
-                   Standard_Real Um1,Standard_Real UM1,
-                   Standard_Real Vm1,Standard_Real VM1,
-                   Standard_Real Um2,Standard_Real UM2,
-                   Standard_Real Vm2,Standard_Real VM2,
-                   Standard_Real _Um1,Standard_Real _UM1,
-                   Standard_Real _Vm1,Standard_Real _VM1,
-                   Standard_Real _Um2,Standard_Real _UM2,
-                   Standard_Real _Vm2,Standard_Real _VM2,
-                   const ThePSurface& ,
-                   const ThePSurface& ,
-                   const Standard_Real Increment) 
+                    Standard_Real Um1,Standard_Real UM1,
+                    Standard_Real Vm1,Standard_Real VM1,
+                    Standard_Real Um2,Standard_Real UM2,
+                    Standard_Real Vm2,Standard_Real VM2,
+                    Standard_Real _Um1,Standard_Real _UM1,
+                    Standard_Real _Vm1,Standard_Real _VM1,
+                    Standard_Real _Um2,Standard_Real _UM2,
+                    Standard_Real _Vm2,Standard_Real _VM2,
+                    const ThePSurface& ,
+                    const ThePSurface& ,
+                    const Standard_Real Increment) 
 { 
   Standard_Real du1=Abs(UM1-Um1);
   Standard_Real dv1=Abs(VM1-Vm1);
   Standard_Real du2=Abs(UM2-Um2);
   Standard_Real dv2=Abs(VM2-Vm2);
+
   Standard_Real _du1=Abs(_UM1-_Um1);
   Standard_Real _dv1=Abs(_VM1-_Vm1);
   Standard_Real _du2=Abs(_UM2-_Um2);
   Standard_Real _dv2=Abs(_VM2-_Vm2);
+
   //-- limit the reduction of uv box estimate to 0.01 natural box
   //--  du1 : On box of Inter
   //-- _du1 : On parametric space
@@ -57,7 +59,7 @@ void ComputePasInit(Standard_Real *pasuv,
   if(_dv1<1e50 && dv1<0.01*_dv1) dv1=0.01*_dv1;
   if(_du2<1e50 && du2<0.01*_du2) du2=0.01*_du2;
   if(_dv2<1e50 && dv2<0.01*_dv2) dv2=0.01*_dv2;
-  
+
   pasuv[0]=Increment*du1;
   pasuv[1]=Increment*dv1;
   pasuv[2]=Increment*du2;
@@ -68,21 +70,21 @@ void ComputePasInit(Standard_Real *pasuv,
 // purpose  : 
 //==================================================================================
 IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
-                                  const ThePSurface& Caro2,
-                                  const Standard_Real TolTangency,
-                                  const Standard_Real Epsilon,
-                                  const Standard_Real Deflection,
-                                  const Standard_Real Increment ) 
-     :
-       
-       done(Standard_True),
-       close(Standard_False),
-       fleche(Deflection),
-       tolconf(Epsilon),
-       sensCheminement(1),
-       myIntersectionOn2S(Caro1,Caro2,TolTangency),
-       STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
-       STATIC_PRECEDENT_INFLEXION(0)
+                                   const ThePSurface& Caro2,
+                                   const Standard_Real TolTangency,
+                                   const Standard_Real Epsilon,
+                                   const Standard_Real Deflection,
+                                   const Standard_Real Increment ) 
+                                   :
+
+done(Standard_True),
+close(Standard_False),
+fleche(Deflection),
+tolconf(Epsilon),
+sensCheminement(1),
+myIntersectionOn2S(Caro1,Caro2,TolTangency),
+STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
+STATIC_PRECEDENT_INFLEXION(0)
 {
   Standard_Real KELARG=20.;
   //
@@ -152,7 +154,7 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
       UM1+=t;  Um1-=t;
     }
   }
-      
+
   if(ThePSurfaceTool::IsVPeriodic(Caro1)==Standard_False) { 
     //VM1+=KELARG*pasuv[1];  Vm1-=KELARG*pasuv[1];
   }
@@ -164,7 +166,7 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
       VM1+=t;  Vm1-=t;
     }
   }
-   
+
   if(ThePSurfaceTool::IsUPeriodic(Caro2)==Standard_False) { 
     //UM2+=KELARG*pasuv[2];  Um2-=KELARG*pasuv[2];
   }
@@ -176,7 +178,7 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
       UM2+=t;  Um2-=t;
     }
   }
-   
+
   if(ThePSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {   
     //VM2+=KELARG*pasuv[3];  Vm2-=KELARG*pasuv[3];
   }
@@ -204,25 +206,25 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
 // purpose  : 
 //==================================================================================
 IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
-                                  const ThePSurface& Caro2,
-                                  const Standard_Real TolTangency,
-                                  const Standard_Real Epsilon,
-                                  const Standard_Real Deflection,
-                                  const Standard_Real Increment, 
-                                  const Standard_Real U1,
-                                  const Standard_Real V1,
-                                  const Standard_Real U2, 
-                                  const Standard_Real V2)
-     :
-       
-       done(Standard_True),
-       close(Standard_False),
-       fleche(Deflection),
-       tolconf(Epsilon),
-       sensCheminement(1),       
-       myIntersectionOn2S(Caro1,Caro2,TolTangency),
-       STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
-       STATIC_PRECEDENT_INFLEXION(0)
+                                   const ThePSurface& Caro2,
+                                   const Standard_Real TolTangency,
+                                   const Standard_Real Epsilon,
+                                   const Standard_Real Deflection,
+                                   const Standard_Real Increment, 
+                                   const Standard_Real U1,
+                                   const Standard_Real V1,
+                                   const Standard_Real U2, 
+                                   const Standard_Real V2)
+                                   :
+
+done(Standard_True),
+close(Standard_False),
+fleche(Deflection),
+tolconf(Epsilon),
+sensCheminement(1),       
+myIntersectionOn2S(Caro1,Caro2,TolTangency),
+STATIC_BLOCAGE_SUR_PAS_TROP_GRAND(0),
+STATIC_PRECEDENT_INFLEXION(0)
 {
   Standard_Real KELARG=20.;
   //
@@ -331,7 +333,7 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
       Um2-=t;
     }
   }
-   
+
   if(ThePSurfaceTool::IsVPeriodic(Caro2)==Standard_False) {   
     VM2+=KELARG*pasuv[3];  
     Vm2-=KELARG*pasuv[3];
@@ -369,7 +371,7 @@ IntWalk_PWalking::IntWalk_PWalking(const ThePSurface& Caro1,
 // purpose  : 
 //==================================================================================
 Standard_Boolean IntWalk_PWalking::PerformFirstPoint  (const TColStd_Array1OfReal& ParDep,
-                                                      IntSurf_PntOn2S& FirstPoint)   
+                                                       IntSurf_PntOn2S& FirstPoint)   
 {
   sensCheminement = 1;
   close = Standard_False;
@@ -408,90 +410,102 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep)
 // purpose  : 
 //==================================================================================
 void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
-                              const Standard_Real u1min,
-                              const Standard_Real v1min,
-                              const Standard_Real u2min,
-                              const Standard_Real v2min,
-                              const Standard_Real u1max,
-                              const Standard_Real v1max,
-                              const Standard_Real u2max,
-                              const Standard_Real v2max)
+                               const Standard_Real u1min,
+                               const Standard_Real v1min,
+                               const Standard_Real u2min,
+                               const Standard_Real v2min,
+                               const Standard_Real u1max,
+                               const Standard_Real v1max,
+                               const Standard_Real u2max,
+                               const Standard_Real v2max)
 {
+  const Standard_Real aSQDistMax = 1.0e-14;
   //xf
-  Standard_Integer i, NbPasOKConseq;
-  Standard_Real UFirst1, VFirst1, ULast1, VLast1, UFirst2, VFirst2, ULast2, VLast2;
+
+  Standard_Integer NbPasOKConseq=0;
+  Standard_Real pasMaxSV[4], aTmp;
   TColStd_Array1OfReal Param(1,4);
   IntImp_ConstIsoparametric ChoixIso;
   //xt
   //
   done = Standard_False;
-  NbPasOKConseq=0;
   //
   // Caro1 and Caro2
   const ThePSurface& Caro1 =myIntersectionOn2S.Function().AuxillarSurface1();
   const ThePSurface& Caro2 =myIntersectionOn2S.Function().AuxillarSurface2();
   //
-  UFirst1 = ThePSurfaceTool::FirstUParameter(Caro1);
-  VFirst1 = ThePSurfaceTool::FirstVParameter(Caro1);
-  ULast1  = ThePSurfaceTool::LastUParameter (Caro1);
-  VLast1  = ThePSurfaceTool::LastVParameter (Caro1);
-  //
-  UFirst2 = ThePSurfaceTool::FirstUParameter(Caro2);
-  VFirst2 = ThePSurfaceTool::FirstVParameter(Caro2);
-  ULast2  = ThePSurfaceTool::LastUParameter (Caro2);
-  VLast2  = ThePSurfaceTool::LastVParameter (Caro2);
+  const Standard_Real UFirst1 = ThePSurfaceTool::FirstUParameter(Caro1);
+  const Standard_Real VFirst1 = ThePSurfaceTool::FirstVParameter(Caro1);
+  const Standard_Real ULast1  = ThePSurfaceTool::LastUParameter (Caro1);
+  const Standard_Real VLast1  = ThePSurfaceTool::LastVParameter (Caro1);
+
+  const Standard_Real UFirst2 = ThePSurfaceTool::FirstUParameter(Caro2);
+  const Standard_Real VFirst2 = ThePSurfaceTool::FirstVParameter(Caro2);
+  const Standard_Real ULast2  = ThePSurfaceTool::LastUParameter (Caro2);
+  const Standard_Real VLast2  = ThePSurfaceTool::LastVParameter (Caro2);
   //
   ComputePasInit(pasuv,u1min,u1max,v1min,v1max,u2min,u2max,v2min,v2max,
-                Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2,pasMax+pasMax);
+    Um1,UM1,Vm1,VM1,Um2,UM2,Vm2,VM2,Caro1,Caro2,pasMax+pasMax);
   //
-  if(pasuv[0]<100*ResoU1) {
-    pasuv[0]=100*ResoU1; 
+  if(pasuv[0]<100.0*ResoU1) {
+    pasuv[0]=100.0*ResoU1; 
   }
-  if(pasuv[1]<100*ResoV1) {
-    pasuv[1]=100*ResoV1; 
+  if(pasuv[1]<100.0*ResoV1) {
+    pasuv[1]=100.0*ResoV1; 
   }
-  if(pasuv[2]<100*ResoU2) {
-    pasuv[2]=100*ResoU2;
+  if(pasuv[2]<100.0*ResoU2) {
+    pasuv[2]=100.0*ResoU2;
   }
-  if(pasuv[3]<100*ResoV2) {
-    pasuv[3]=100*ResoV2;
+  if(pasuv[3]<100.0*ResoV2) {
+    pasuv[3]=100.0*ResoV2;
   }
   //
-  for (i=0; i<4; ++i) {
-    if(pasuv[i]>10) {
+  for (Standard_Integer i=0; i<4; ++i)
+  {
+    if(pasuv[i]>10)
+    {
       pasuv[i] = 10;
     }
+
     pasInit[i] = pasSav[i] = pasuv[i]; 
   }
   //
   line = new IntSurf_LineOn2S ();
   //
-  for (i=1; i<=4; ++i) {
+  for (Standard_Integer i=1; i<=4; ++i)
+  {
+    aTmp=ParDep(i);
     Param(i)=ParDep(i);
   }
   //-- reproduce steps uv connected to surfaces Caro1 and Caro2
   //-- pasuv[] and pasSav[] are modified during the marching
-  for(i = 0; i < 4; ++i) { 
-    pasSav[i] = pasuv[i] = pasInit[i];
+  for(Standard_Integer i = 0; i < 4; ++i)
+  {
+    pasMaxSV[i] = pasSav[i] = pasuv[i] = pasInit[i]; 
   }
 
   //-- calculate the first solution point
   math_FunctionSetRoot  Rsnld(myIntersectionOn2S.Function());
   //
   ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld);
-  if (!myIntersectionOn2S.IsDone())   {
+  if (!myIntersectionOn2S.IsDone())
+  {
     return;
   }
+
   //
-  if (myIntersectionOn2S.IsEmpty()) {
+  if (myIntersectionOn2S.IsEmpty())
+  {
     return;
   }
   //
-  if(myIntersectionOn2S.IsTangent()) {
+  if(myIntersectionOn2S.IsTangent())
+  {
     return;
   }
   //
   Standard_Boolean Arrive, DejaReparti;
+  const Standard_Integer RejectIndexMAX = 250000;
   Standard_Integer IncKey, RejectIndex;
   gp_Pnt pf,pl;
   //
@@ -517,8 +531,8 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
   //-- 
   pf = previousPoint.Value();
   Standard_Boolean bTestFirstPoint = Standard_True;
-  
-  previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));  
+
+  previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
   AddAPoint(line,previousPoint);
   //
   IntWalk_StatusDeflection Status = IntWalk_OK;
@@ -529,12 +543,14 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
   Standard_Integer LevelOfIterWithoutAppend = -1;
   //
   Arrive = Standard_False;
-  while(!Arrive) {//010
+  while(!Arrive) //010
+  {
     LevelOfIterWithoutAppend++;
-    if(LevelOfIterWithoutAppend>20) { 
+    if(LevelOfIterWithoutAppend>20)
+    {
       Arrive = Standard_True; 
       if(DejaReparti) {
-       break;
+        break;
       }
       RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
       LevelOfIterWithoutAppend = 0;
@@ -566,16 +582,23 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
     //
     aIncKey=5.*(Standard_Real)IncKey;
     aEps=1.e-7;
-    if(ChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < aEps) {
+    if(ChoixIso == IntImp_UIsoparametricOnCaro1 && Abs(dP1) < aEps)
+    {
       dP1 *= aIncKey;
     }
-    if(ChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < aEps) {
+
+    if(ChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < aEps)
+    {
       dP2 *= aIncKey;
     }
-    if(ChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < aEps) {
+
+    if(ChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < aEps)
+    {
       dP3 *= aIncKey;
     }
-    if(ChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < aEps) {
+
+    if(ChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < aEps)
+    {
       dP4 *= aIncKey;
     }
     //--ofv.end
@@ -592,7 +615,8 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
     //
     ChoixIso= myIntersectionOn2S.Perform(Param, Rsnld, ChoixIso);                  
     //
-    if (!myIntersectionOn2S.IsDone())   {
+    if (!myIntersectionOn2S.IsDone())
+    {
       //end of line, division
       Arrive = Standard_False;
       Param(1)=SvParam[0]; 
@@ -601,403 +625,532 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
       Param(4)=SvParam[3];
       RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
     }
-    else  {//009 
+    else  //009 
+    {
       //== Calculation of exact point from Param(.) is possible
-      if (myIntersectionOn2S.IsEmpty())        {
-       Standard_Real u1,v1,u2,v2;
-       previousPoint.Parameters(u1,v1,u2,v2);
-       //
-       Arrive = Standard_False;
-       if(u1<UFirst1 || u1>ULast1) {
-         Arrive=Standard_True;
-       }       
-       if(u2<UFirst2 || u2>ULast2) {
-         Arrive=Standard_True;
-       }
-       if(v1<VFirst1 || v1>VLast1) {
-         Arrive=Standard_True;
-       }
-       if(v2<VFirst2 || v2>VLast2) {
-         Arrive=Standard_True;
-       }       
-       RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-       LevelOfEmptyInmyIntersectionOn2S++;
-       //
-       if(LevelOfEmptyInmyIntersectionOn2S>10)    {
-         pasuv[0]=pasSav[0]; 
-         pasuv[1]=pasSav[1]; 
-         pasuv[2]=pasSav[2]; 
-         pasuv[3]=pasSav[3];
-       }           
+      if (myIntersectionOn2S.IsEmpty())
+      {
+        Standard_Real u1,v1,u2,v2;
+        previousPoint.Parameters(u1,v1,u2,v2);
+        //
+        Arrive = Standard_False;
+        if(u1<UFirst1 || u1>ULast1)
+        {
+          Arrive=Standard_True;
+        }      
+
+        if(u2<UFirst2 || u2>ULast2)
+        {
+          Arrive=Standard_True;
+        }
+
+        if(v1<VFirst1 || v1>VLast1)
+        {
+          Arrive=Standard_True;
+        }
+
+        if(v2<VFirst2 || v2>VLast2)
+        {
+          Arrive=Standard_True;
+        }
+
+        RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+        LevelOfEmptyInmyIntersectionOn2S++;
+        //
+        if(LevelOfEmptyInmyIntersectionOn2S>10)
+        {
+          pasuv[0]=pasSav[0]; 
+          pasuv[1]=pasSav[1]; 
+          pasuv[2]=pasSav[2]; 
+          pasuv[3]=pasSav[3];
+        }
       }
-      else {//008
-       //============================================================
-       //== A point has been found :  T E S T   D E F L E C T I O N 
-       //============================================================
-       if(NoTestDeflection) {
-         NoTestDeflection = Standard_False;
-       }                 
-       else { 
-         if(--LevelOfEmptyInmyIntersectionOn2S<=0)     { 
-           LevelOfEmptyInmyIntersectionOn2S=0;
-           if(LevelOfIterWithoutAppend < 10) {
-             Status = TestDeflection();
-           }                   
-           else   { 
-             pasuv[0]*=0.5; 
-             pasuv[1]*=0.5; 
-             pasuv[2]*=0.5; 
-             pasuv[3]*=0.5;
-           }
-         }
-       }
-       //============================================================
-       //==       T r a i t e m e n t   s u r   S t a t u s        ==
-       //============================================================
-       if(LevelOfPointConfondu > 5) { 
-         Status = IntWalk_ArretSurPoint; 
-         LevelOfPointConfondu = 0;  
-       }
-       //
-       if(Status==IntWalk_OK) { 
-         NbPasOKConseq++;
-         if(NbPasOKConseq >= 5) { 
-           NbPasOKConseq=0;
-           Standard_Boolean pastroppetit;
-           Standard_Real t;
-           //
-           do { 
-             pastroppetit=Standard_True;
-             //
-             if(pasuv[0]<pasInit[0])     { 
-               t = (pasInit[0]-pasuv[0])*0.25;
-               if(t>0.1*pasInit[0]) {
-                 t=0.1*pasuv[0];
-               }
-               pasuv[0]+=t; 
-               pastroppetit=Standard_False;
-             } 
-             if(pasuv[1]<pasInit[1])   { 
-               t = (pasInit[1]-pasuv[1])*0.25;
-               if(t>0.1*pasInit[1]) {
-                 t=0.1*pasuv[1];
-               }               
-               pasuv[1]+=t; 
-               pastroppetit=Standard_False;
-             } 
-             if(pasuv[2]<pasInit[2]){
-               t = (pasInit[2]-pasuv[2])*0.25;
-               if(t>0.1*pasInit[2]) {
-                 t=0.1*pasuv[2];
-               }
-               pasuv[2]+=t; 
-               pastroppetit=Standard_False;
-             } 
-             if(pasuv[3]<pasInit[3])   { 
-               t = (pasInit[3]-pasuv[3])*0.25;
-               if(t>0.1*pasInit[3]) {
-                 t=0.1*pasuv[3];
-               }
-               pasuv[3]+=t; 
-               pastroppetit=Standard_False;
-             }
-             if(pastroppetit) { 
-               if(pasMax<0.1){ 
-                 pasMax*=1.1; 
-                 pasInit[0]*=1.1; 
-                 pasInit[1]*=1.1; 
-                 pasInit[2]*=1.1; 
-                 pasInit[3]*=1.1; 
-               }
-               else {
-                 pastroppetit=Standard_False;
-               }
-             }
-           } while(pastroppetit);
-         }
-       }//Status==IntWalk_OK
-       else NbPasOKConseq=0;
-       //
-       switch(Status) {//007 
-         case IntWalk_ArretSurPointPrecedent:  {                     
-           Arrive = Standard_False;                        
-           RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
-           break;
-         }
-         case IntWalk_PasTropGrand:  {
-           Param(1)=SvParam[0]; 
-           Param(2)=SvParam[1]; 
-           Param(3)=SvParam[2]; 
-           Param(4)=SvParam[3];
-           if(LevelOfIterWithoutAppend > 5) { 
-             if(pasSav[0]<pasInit[0]) { 
-               pasInit[0]-=(pasInit[0]-pasSav[0])*0.25; 
-               LevelOfIterWithoutAppend=0;
-             }
-             if(pasSav[1]<pasInit[1]) { 
-               pasInit[1]-=(pasInit[1]-pasSav[1])*0.25;  
-               LevelOfIterWithoutAppend=0; 
-             }
-             if(pasSav[2]<pasInit[2]) { 
-               pasInit[2]-=(pasInit[2]-pasSav[2])*0.25;  
-               LevelOfIterWithoutAppend=0; 
-             }
-             if(pasSav[3]<pasInit[3]) {
-               pasInit[3]-=(pasInit[3]-pasSav[3])*0.25; 
-               LevelOfIterWithoutAppend=0; 
-             }
-           }
-           break;
-         }
-         case IntWalk_PointConfondu:   {
-           LevelOfPointConfondu++;
-           if(LevelOfPointConfondu>5)   { 
-             Standard_Boolean pastroppetit;
-             //
-             do { 
-               pastroppetit=Standard_True;
-               if(pasuv[0]<pasInit[0]) { 
-                 pasuv[0]+=(pasInit[0]-pasuv[0])*0.25;
-                 pastroppetit=Standard_False; 
-               } 
-               if(pasuv[1]<pasInit[1]) { 
-                 pasuv[1]+=(pasInit[1]-pasuv[1])*0.25;
-                 pastroppetit=Standard_False; 
-               } 
-               if(pasuv[2]<pasInit[2]) { 
-                 pasuv[2]+=(pasInit[2]-pasuv[2])*0.25;
-                 pastroppetit=Standard_False; 
-               } 
-               if(pasuv[3]<pasInit[3]) { 
-                 pasuv[3]+=(pasInit[3]-pasuv[3])*0.25; 
-                 pastroppetit=Standard_False; 
-               }
-               if(pastroppetit)  { 
-                 if(pasMax<0.1){ 
-                   pasMax*=1.1; 
-                   pasInit[0]*=1.1; 
-                   pasInit[1]*=1.1; 
-                   pasInit[2]*=1.1; 
-                   pasInit[3]*=1.1; 
-                 }
-                 else{
-                   pastroppetit=Standard_False; 
-                 }             
-               }
-             } while(pastroppetit);
-           }
-           break;
-         }
-         case IntWalk_OK:
-         case IntWalk_ArretSurPoint:  {//006
-           //=======================================================
-           //== Stop Test t   :  Frame on Param(.)     ==
-           //=======================================================
-           //xft arrive here
-           Arrive = TestArret(DejaReparti,Param,ChoixIso); 
-           // JMB 30th December 1999. 
-           // Some statement below should not be put in comment because they are useful.
-           // See grid CTO 909 A1 which infinitely loops 
-           if(Arrive==Standard_False && Status==IntWalk_ArretSurPoint) { 
-             Arrive=Standard_True;
+      else //008
+      {
+        //============================================================
+        //== A point has been found :  T E S T   D E F L E C T I O N 
+        //============================================================
+        if(NoTestDeflection)
+        {
+          NoTestDeflection = Standard_False;
+        }                
+        else
+        {
+          if(--LevelOfEmptyInmyIntersectionOn2S<=0)
+          {
+            LevelOfEmptyInmyIntersectionOn2S=0;
+            if(LevelOfIterWithoutAppend < 10)
+            {
+              Status = TestDeflection();
+            }                  
+            else
+            {
+              pasuv[0]*=0.5; 
+              pasuv[1]*=0.5; 
+              pasuv[2]*=0.5; 
+              pasuv[3]*=0.5;
+            }
+          }
+        }
+
+        //============================================================
+        //==       T r a i t e m e n t   s u r   S t a t u s        ==
+        //============================================================
+        if(LevelOfPointConfondu > 5)
+        { 
+          Status = IntWalk_ArretSurPoint; 
+          LevelOfPointConfondu = 0;  
+        }
+        //
+        if(Status==IntWalk_OK)
+        { 
+          NbPasOKConseq++;
+          if(NbPasOKConseq >= 5)
+          {
+            NbPasOKConseq=0;
+            Standard_Boolean pastroppetit;
+            Standard_Real t;
+            //
+            do
+            {
+              pastroppetit=Standard_True;
+              //
+              if(pasuv[0]<pasInit[0])
+              {
+                t = (pasInit[0]-pasuv[0])*0.25;
+                if(t>0.1*pasInit[0])
+                {
+                  t=0.1*pasuv[0];
+                }
+
+                pasuv[0]+=t; 
+                pastroppetit=Standard_False;
+              }
+
+              if(pasuv[1]<pasInit[1])
+              {
+                t = (pasInit[1]-pasuv[1])*0.25;
+                if(t>0.1*pasInit[1]) {
+                  t=0.1*pasuv[1];
+                }              
+
+                pasuv[1]+=t; 
+                pastroppetit=Standard_False;
+              }
+
+              if(pasuv[2]<pasInit[2])
+              {
+                t = (pasInit[2]-pasuv[2])*0.25;
+                if(t>0.1*pasInit[2])
+                {
+                  t=0.1*pasuv[2];
+                }
+
+                pasuv[2]+=t; 
+                pastroppetit=Standard_False;
+              }
+
+              if(pasuv[3]<pasInit[3])
+              {
+                t = (pasInit[3]-pasuv[3])*0.25;
+                if(t>0.1*pasInit[3]) {
+                  t=0.1*pasuv[3];
+                }
+                pasuv[3]+=t; 
+                pastroppetit=Standard_False;
+              }
+              if(pastroppetit)
+              {
+                if(pasMax<0.1)
+                {
+                  pasMax*=1.1;
+                  pasInit[0]*=1.1; 
+                  pasInit[1]*=1.1; 
+                  pasInit[2]*=1.1; 
+                  pasInit[3]*=1.1; 
+                }
+                else
+                {
+                  pastroppetit=Standard_False;
+                }
+              }
+            }
+            while(pastroppetit);
+          }
+        }//Status==IntWalk_OK
+        else
+          NbPasOKConseq=0;
+
+        //
+        switch(Status)//007 
+        {
+        case IntWalk_ArretSurPointPrecedent:
+          {
+            Arrive = Standard_False;
+            RepartirOuDiviser(DejaReparti, ChoixIso, Arrive);
+            break;
+          }
+        case IntWalk_PasTropGrand:
+          {
+            Param(1)=SvParam[0];
+            Param(2)=SvParam[1]; 
+            Param(3)=SvParam[2]; 
+            Param(4)=SvParam[3];
+
+            if(LevelOfIterWithoutAppend > 5)
+            {
+              if(pasSav[0]<pasInit[0])
+              {
+                pasInit[0]-=(pasInit[0]-pasSav[0])*0.25;
+                LevelOfIterWithoutAppend=0;
+              }
+
+              if(pasSav[1]<pasInit[1])
+              {
+                pasInit[1]-=(pasInit[1]-pasSav[1])*0.25;
+                LevelOfIterWithoutAppend=0;
+              }
+
+              if(pasSav[2]<pasInit[2])
+              {
+                pasInit[2]-=(pasInit[2]-pasSav[2])*0.25;
+                LevelOfIterWithoutAppend=0;
+              }
+
+              if(pasSav[3]<pasInit[3])
+              {
+                pasInit[3]-=(pasInit[3]-pasSav[3])*0.25;
+                LevelOfIterWithoutAppend=0;
+              }
+            }
+
+            break;
+          }
+        case IntWalk_PointConfondu:
+          {
+            LevelOfPointConfondu++;
+
+            if(LevelOfPointConfondu>5)
+            {
+              Standard_Boolean pastroppetit;
+              //
+              do
+              {
+                pastroppetit=Standard_True;
+
+                if(pasuv[0]<pasInit[0])
+                {
+                  pasuv[0]+=(pasInit[0]-pasuv[0])*0.25;
+                  pastroppetit=Standard_False;
+                }
+
+                if(pasuv[1]<pasInit[1])
+                {
+                  pasuv[1]+=(pasInit[1]-pasuv[1])*0.25;
+                  pastroppetit=Standard_False;
+                }
+
+                if(pasuv[2]<pasInit[2])
+                {
+                  pasuv[2]+=(pasInit[2]-pasuv[2])*0.25;
+                  pastroppetit=Standard_False; 
+                }
+
+                if(pasuv[3]<pasInit[3])
+                {
+                  pasuv[3]+=(pasInit[3]-pasuv[3])*0.25;
+                  pastroppetit=Standard_False;
+                }
+
+                if(pastroppetit)
+                {
+                  if(pasMax<0.1)
+                  {
+                    pasMax*=1.1;
+                    pasInit[0]*=1.1;
+                    pasInit[1]*=1.1;
+                    pasInit[2]*=1.1;
+                    pasInit[3]*=1.1; 
+                  }
+                  else
+                  {
+                    pastroppetit=Standard_False;
+                  }
+                }
+              }
+              while(pastroppetit);
+            }
+
+            break;
+          }
+        case IntWalk_OK:
+        case IntWalk_ArretSurPoint://006
+          {
+            //=======================================================
+            //== Stop Test t   :  Frame on Param(.)     ==
+            //=======================================================
+            //xft arrive here
+            Arrive = TestArret(DejaReparti,Param,ChoixIso); 
+            // JMB 30th December 1999. 
+            // Some statement below should not be put in comment because they are useful.
+            // See grid CTO 909 A1 which infinitely loops 
+            if(Arrive==Standard_False && Status==IntWalk_ArretSurPoint)
+            {
+              Arrive=Standard_True;
 #ifdef DEB
-             cout << "Compile with option DEB : if problems with intersection : ";
-             cout << "IntWalk_PWalking_1.gxx (lbr le 1erdec98)"<<endl;
+              cout << "Compile with option DEB : if problems with intersection : ";
+              cout << "IntWalk_PWalking_1.gxx (lbr le 1erdec98)"<<endl;
 #endif
-           }
-           if(Arrive) {
-             NbPasOKConseq = -10;
-           }
-           if(!Arrive)  {//005
-             //=====================================================
-             //== Param(.) is in the limits                       ==
-             //==  and does not end a closed  line                ==
-             //=====================================================
-             //== Check on the current point of myInters
-             Standard_Boolean pointisvalid = Standard_False;
-             {
-               Standard_Real u1,v1,u2,v2; 
-               myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2); 
-               //
-               if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
-                  v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
-                  v1 >= Vm1  && v2 >= Vm2) {
-                 pointisvalid=Standard_True;
-               }
-             }
-             //
-             if(pointisvalid) { 
-               previousPoint = myIntersectionOn2S.Point();
-               previoustg = myIntersectionOn2S.IsTangent();
-               if(!previoustg) {
-                 previousd  = myIntersectionOn2S.Direction();
-                 previousd1 = myIntersectionOn2S.DirectionOnS1();
-                 previousd2 = myIntersectionOn2S.DirectionOnS2();
-               }
-               //=====================================================
-               //== Check on the previous Point
-               {
-                 Standard_Real u1,v1,u2,v2; 
-                 previousPoint.Parameters(u1,v1,u2,v2); 
-                 if( u1 <= UM1  && u2 <= UM2 && v1 <= VM1 &&
-                     v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
-                     v1 >= Vm1  && v2 >= Vm2) { 
-                   pl = previousPoint.Value();
-                   if(bTestFirstPoint) {
-                     if(pf.Distance(pl) < 1.e-7){ 
-                       IncKey++; 
-                       if(IncKey == 5000) 
-                         return; 
-                       else 
-                         continue; 
-                     }
-                     else {
-                       bTestFirstPoint = Standard_False;
-                     }
-                   }
-                   //
-                   AddAPoint(line,previousPoint);
-                   RejectIndex++; 
-                   if(RejectIndex >= 250000) {
-                     break; 
-                   };
-                   //
-                   LevelOfIterWithoutAppend = 0;
-                 } 
-               }
-             }//pointisvalid
-             //====================================================
-             if(Status == IntWalk_ArretSurPoint)  {
-               RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-             }
-             else{ 
-               if (line->NbPoints() == 2) {
-                 pasSav[0] = pasuv[0]; 
-                 pasSav[1] = pasuv[1]; 
-                 pasSav[2] = pasuv[2]; 
-                 pasSav[3] = pasuv[3];
-               }
-             }
-           }//005 if(!Arrive)
-           //
-           else {//004
-             if(close) { 
-               //================= la ligne est fermee ===============
-               AddAPoint(line,line->Value(1)); //ligne fermee
-               LevelOfIterWithoutAppend=0;
-             }
-             else {//$$$
-               //====================================================
-               //== Param was not in the limits (was reframed)
-               //====================================================
-               Standard_Boolean bPrevNotTangent = !previoustg || !myIntersectionOn2S.IsTangent();
-               
-               IntImp_ConstIsoparametric SauvChoixIso = ChoixIso;
-               ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);    
-               //
-               if(!myIntersectionOn2S.IsEmpty()) { //002
-                 // mutially outpasses in the square or intersection in corner
-                 if(TestArret(Standard_True,Param,ChoixIso))  {
-                   NbPasOKConseq = -10;
-                   ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso); 
-                   if(!myIntersectionOn2S.IsEmpty())     {
-                     previousPoint = myIntersectionOn2S.Point();         
-                     previoustg = myIntersectionOn2S.IsTangent();
-                     if (!previoustg)     {
-                       previousd  = myIntersectionOn2S.Direction();
-                       previousd1 = myIntersectionOn2S.DirectionOnS1();
-                       previousd2 = myIntersectionOn2S.DirectionOnS2();
-                     }
-                     pl = previousPoint.Value();
-                     if(bTestFirstPoint) {
-                       if(pf.Distance(pl) < 1.e-7){ 
-                         IncKey++; 
-                         if(IncKey == 5000) 
-                           return; 
-                         else 
-                           continue; 
-                       }
-                       else {
-                         bTestFirstPoint = Standard_False;
-                       }
-                     }
-                     //
-                     AddAPoint(line,previousPoint);
-                     RejectIndex++;
-                     if(RejectIndex >= 250000) {
-                       break;
-                     };
-                     //
-                     LevelOfIterWithoutAppend=0;
-                     RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-                   }
-                   else  {
-                     //fail framing divides the step
-                     Arrive = Standard_False;
-                     RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-                     NoTestDeflection = Standard_True;
-                     ChoixIso = SauvChoixIso;
-                   }
-                 }//if(TestArret())
-                 else {
-                   // save the last point
-                   // to revert to it if the current point is out of bounds
-                   IntSurf_PntOn2S previousPointSave = previousPoint;
-                   Standard_Boolean previoustgSave   = previoustg;
-                   gp_Dir previousdSave              = previousd;
-                   gp_Dir2d previousd1Save           = previousd1;
-                   gp_Dir2d previousd2Save           = previousd2;
-                   
-                   previousPoint = myIntersectionOn2S.Point();         
-                   previoustg = myIntersectionOn2S.IsTangent();
-                   Arrive = Standard_False; 
-                   if(!previoustg)  {
-                     previousd  = myIntersectionOn2S.Direction();
-                     previousd1 = myIntersectionOn2S.DirectionOnS1();
-                     previousd2 = myIntersectionOn2S.DirectionOnS2();
-                   }
-                   //========================================
-                   //== Check on PreviousPoint @@
-                   {
-                     Standard_Real u1,v1,u2,v2; 
-                     previousPoint.Parameters(u1,v1,u2,v2);
+            }
+
+            if(Arrive)
+            {
+              NbPasOKConseq = -10;
+            }
+
+            if(!Arrive)//005
+            {
+              //=====================================================
+              //== Param(.) is in the limits                       ==
+              //==  and does not end a closed  line                ==
+              //=====================================================
+              //== Check on the current point of myInters
+              Standard_Boolean pointisvalid = Standard_False;
+              {
+                Standard_Real u1,v1,u2,v2; 
+                myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2);
+
+                //
+                if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
+                  v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
+                  v1 >= Vm1  && v2 >= Vm2)
+                {
+                  pointisvalid=Standard_True;
+                }
+              }
+
+              //
+              if(pointisvalid)
+              {
+                previousPoint = myIntersectionOn2S.Point();
+                previoustg = myIntersectionOn2S.IsTangent();
+
+                if(!previoustg)
+                {
+                  previousd  = myIntersectionOn2S.Direction();
+                  previousd1 = myIntersectionOn2S.DirectionOnS1();
+                  previousd2 = myIntersectionOn2S.DirectionOnS2();
+                }
+                //=====================================================
+                //== Check on the previous Point
+                {
+                  Standard_Real u1,v1,u2,v2;
+                  previousPoint.Parameters(u1,v1,u2,v2); 
+                  if( u1 <= UM1  && u2 <= UM2 && v1 <= VM1 &&
+                    v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
+                    v1 >= Vm1  && v2 >= Vm2)
+                  {
+                    pl = previousPoint.Value();
+                    if(bTestFirstPoint)
+                    {
+                      if(pf.SquareDistance(pl) < aSQDistMax)
+                      {
+                        IncKey++;
+                        if(IncKey == 5000)
+                          return;
+                        else
+                          continue;
+                      }
+                      else
+                      {
+                        bTestFirstPoint = Standard_False;
+                      }
+                    }
+                    //
+                    AddAPoint(line,previousPoint);
+                    RejectIndex++;
+
+                    if(RejectIndex >= RejectIndexMAX)
+                    {
+                      break;
+                    }
+
+                    //
+                    LevelOfIterWithoutAppend = 0;
+                  }
+                }
+              }//pointisvalid
+              //====================================================
+
+              if(Status == IntWalk_ArretSurPoint)
+              {
+                RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+              }
+              else
+              {
+                if (line->NbPoints() == 2)
+                {
+                  pasSav[0] = pasuv[0];
+                  pasSav[1] = pasuv[1];
+                  pasSav[2] = pasuv[2];
+                  pasSav[3] = pasuv[3];
+                }
+              }
+            }//005 if(!Arrive)
+            else  //004
+            {
+              if(close)
+              {
+                //================= la ligne est fermee ===============
+                AddAPoint(line,line->Value(1)); //ligne fermee
+                LevelOfIterWithoutAppend=0;
+              }
+              else    //$$$
+              {
+                //====================================================
+                //== Param was not in the limits (was reframed)
+                //====================================================
+                Standard_Boolean bPrevNotTangent = !previoustg || !myIntersectionOn2S.IsTangent();
+
+                IntImp_ConstIsoparametric SauvChoixIso = ChoixIso;
+                ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
+                //
+                if(!myIntersectionOn2S.IsEmpty()) //002
+                {
+                  // mutially outpasses in the square or intersection in corner
+
+                  if(TestArret(Standard_True,Param,ChoixIso))
+                  {
+                    NbPasOKConseq = -10;
+                    ChoixIso = myIntersectionOn2S.Perform(Param,Rsnld,ChoixIso);
+
+                    if(!myIntersectionOn2S.IsEmpty())
+                    {
+                      previousPoint = myIntersectionOn2S.Point();
+                      previoustg = myIntersectionOn2S.IsTangent();
+
+                      if (!previoustg)
+                      {
+                        previousd  = myIntersectionOn2S.Direction();
+                        previousd1 = myIntersectionOn2S.DirectionOnS1();
+                        previousd2 = myIntersectionOn2S.DirectionOnS2();
+                      }
+
+                      pl = previousPoint.Value();
+
+                      if(bTestFirstPoint)
+                      {
+                        if(pf.SquareDistance(pl) < aSQDistMax)
+                        {
+                          IncKey++;
+                          if(IncKey == 5000)
+                            return;
+                          else
+                            continue;
+                        }
+                        else
+                        {
+                          bTestFirstPoint = Standard_False;
+                        }
+                      }
+                      //
+                      AddAPoint(line,previousPoint);
+                      RejectIndex++;
+
+                      if(RejectIndex >= RejectIndexMAX)
+                      {
+                        break;
+                      }
+
+                      //
+                      LevelOfIterWithoutAppend=0;
+                      RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+                    }
+                    else
+                    {
+                      //fail framing divides the step
+                      Arrive = Standard_False;
+                      RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+                      NoTestDeflection = Standard_True;
+                      ChoixIso = SauvChoixIso;
+                    }
+                  }//if(TestArret())
+                  else
+                  {
+                    // save the last point
+                    // to revert to it if the current point is out of bounds
+
+                    IntSurf_PntOn2S previousPointSave = previousPoint;
+                    Standard_Boolean previoustgSave   = previoustg;
+                    gp_Dir previousdSave              = previousd;
+                    gp_Dir2d previousd1Save           = previousd1;
+                    gp_Dir2d previousd2Save           = previousd2;
+
+                    previousPoint = myIntersectionOn2S.Point();
+                    previoustg = myIntersectionOn2S.IsTangent();
+                    Arrive = Standard_False;
+
+                    if(!previoustg)
+                    {
+                      previousd  = myIntersectionOn2S.Direction();
+                      previousd1 = myIntersectionOn2S.DirectionOnS1();
+                      previousd2 = myIntersectionOn2S.DirectionOnS2();
+                    }
+
+                    //========================================
+                    //== Check on PreviousPoint @@
+
+                    {
+                      Standard_Real u1,v1,u2,v2;
+                      previousPoint.Parameters(u1,v1,u2,v2);
+
                       //To save initial 2d points
                       gp_Pnt2d ParamPntOnS1(Param(1), Param(2));
                       gp_Pnt2d ParamPntOnS2(Param(3), Param(4));
+
                       ///////////////////////////
-                     Param(1) = u1; 
-                     Param(2) = v1;    
-                     Param(3) = u2; 
-                     Param(4) = v2;
-                     //
-                     //xf
-                     Standard_Boolean bFlag1, bFlag2;
-                     Standard_Real aTol2D=1.e-11;
-                     //
-                     bFlag1=u1 >= Um1-aTol2D && v1 >= Vm1-aTol2D && u1 <= UM1+aTol2D && v1 <= VM1+aTol2D;
-                     bFlag2=u2 >= Um2-aTol2D && v2 >= Vm2-aTol2D && u2 <= UM2+aTol2D && v2 <= VM2+aTol2D;
-                     if (bFlag1 && bFlag2) {
-                     /*
-                     if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 &&
-                        v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
-                        v1 >= Vm1  && v2 >= Vm2)  {
-                        */                     
-                     //xt
-                       pl = previousPoint.Value();
-                       if(bTestFirstPoint) {
-                         if(pf.Distance(pl) < 1.e-7) {
-                           IncKey++;
-                           if(IncKey == 5000)
-                             return; 
-                           else 
-                             continue;
-                         }
-                         else {
-                           bTestFirstPoint = Standard_False;
-                         }
-                       }
+                      Param(1) = u1;
+                      Param(2) = v1;
+                      Param(3) = u2;
+                      Param(4) = v2;
+                      //
+
+                      //xf
+                      Standard_Boolean bFlag1, bFlag2;
+                      Standard_Real aTol2D=1.e-11;
+                      //
+                      bFlag1=u1 >= Um1-aTol2D && v1 >= Vm1-aTol2D && u1 <= UM1+aTol2D && v1 <= VM1+aTol2D;
+                      bFlag2=u2 >= Um2-aTol2D && v2 >= Vm2-aTol2D && u2 <= UM2+aTol2D && v2 <= VM2+aTol2D;
+                      if (bFlag1 && bFlag2)
+                      {
+                        /*
+                        if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 &&
+                        v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
+                        v1 >= Vm1  && v2 >= Vm2)  {
+                        */                     
+                        //xt
+                        pl = previousPoint.Value();
+
+                        if(bTestFirstPoint)
+                        {
+                          if(pf.SquareDistance(pl) < aSQDistMax)
+                          {
+                            IncKey++;
+
+                            if(IncKey == 5000)
+                              return;
+                            else
+                              continue;
+                          }
+                          else
+                          {
+                            bTestFirstPoint = Standard_False;
+                          }
+                        }
+
                         //To avoid walking around the same point
                         //in the tangent zone near a border
+
                         if (previoustg)
                         {
                           Standard_Real prevU1, prevV1, prevU2, prevV2;
@@ -1009,70 +1162,84 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
                           gp_Vec2d PrevToParamOnS2(prevPntOnS2, ParamPntOnS2);
                           gp_Vec2d PrevToCurOnS2(prevPntOnS2, curPntOnS2);
                           Standard_Real MaxAngle = 3*M_PI/4;
+
                           if (Abs(PrevToParamOnS1.Angle(PrevToCurOnS1)) > MaxAngle &&
-                              Abs(PrevToParamOnS2.Angle(PrevToCurOnS2)) > MaxAngle)
+                            Abs(PrevToParamOnS2.Angle(PrevToCurOnS2)) > MaxAngle)
                           {
                             Arrive = Standard_True;
                             break;
                           }
                         }
+
                         ////////////////////////////////////////
-                       AddAPoint(line,previousPoint);
-                       RejectIndex++;
-                       if(RejectIndex >= 250000) {
-                         break;
-                       }
-                       //
-                       LevelOfIterWithoutAppend=0;
-                       Arrive = Standard_True;
-                     }
-                     else {
-                       // revert to the last correctly calculated point
-                       previousPoint = previousPointSave;
-                       previoustg    = previoustgSave;
-                       previousd     = previousdSave;
-                       previousd1    = previousd1Save;
-                       previousd2    = previousd2Save;
-                     }
-                   }
-                   //
-                   Standard_Boolean wasExtended = Standard_False;
-                   
-                   if(Arrive && myIntersectionOn2S.IsTangent() && bPrevNotTangent) {
-                     if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti)) {
-                       wasExtended = Standard_True;
-                       Arrive = Standard_False;
-                       ChoixIso = SauvChoixIso;
-                     }
-                   }
-                   
-                   RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-                   if(Arrive && 
-                      myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty() &&
-                      myIntersectionOn2S.IsTangent() && bPrevNotTangent &&
-                      !wasExtended) {
-                     
-                     if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti)) {
-                       wasExtended = Standard_True;
-                       Arrive = Standard_False;
-                       ChoixIso = SauvChoixIso;
-                     }
-                   }
-                 }//else !TestArret() $
-               } //$$ end successful framing on border (!myIntersectionOn2S.IsEmpty())
-               else  {
-                 //echec framing on border; division of step 
-                 Arrive = Standard_False;
-                 NoTestDeflection = Standard_True;
-                 RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
-               } 
-             }//$$$ end framing on border (!close)
-           } //004 fin TestArret return Arrive = True
-         } // 006case IntWalk_ArretSurPoint:  end Processing Status = OK  or ArretSurPoint 
-       } //007  switch(Status) 
+                        AddAPoint(line,previousPoint);
+                        RejectIndex++;
+
+                        if(RejectIndex >= RejectIndexMAX)
+                        {
+                          break;
+                        }
+
+                        //
+
+                        LevelOfIterWithoutAppend=0;
+                        Arrive = Standard_True;
+                      }
+                      else
+                      {
+                        // revert to the last correctly calculated point
+                        previousPoint = previousPointSave;
+                        previoustg    = previoustgSave;
+                        previousd     = previousdSave;
+                        previousd1    = previousd1Save;
+                        previousd2    = previousd2Save;
+                      }
+                    }
+
+                    //
+                    Standard_Boolean wasExtended = Standard_False;
+
+                    if(Arrive && myIntersectionOn2S.IsTangent() && bPrevNotTangent)
+                    {
+                      if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
+                      {
+                        wasExtended = Standard_True;
+                        Arrive = Standard_False;
+                        ChoixIso = SauvChoixIso;
+                      }
+                    }
+
+                    RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+
+                    if(Arrive && 
+                      myIntersectionOn2S.IsDone() && !myIntersectionOn2S.IsEmpty() &&
+                      myIntersectionOn2S.IsTangent() && bPrevNotTangent &&
+                      !wasExtended)
+                    {
+                      if(ExtendLineInCommonZone(SauvChoixIso, DejaReparti))
+                      {
+                        wasExtended = Standard_True;
+                        Arrive = Standard_False;
+                        ChoixIso = SauvChoixIso;
+                      }
+                    }
+                  }//else !TestArret() $
+                }//$$ end successful framing on border (!myIntersectionOn2S.IsEmpty())
+                else
+                {
+                  //echec framing on border; division of step 
+                  Arrive = Standard_False;
+                  NoTestDeflection = Standard_True;
+                  RepartirOuDiviser(DejaReparti,ChoixIso,Arrive);
+                }
+              }//$$$ end framing on border (!close)
+            }//004 fin TestArret return Arrive = True
+          } // 006case IntWalk_ArretSurPoint:  end Processing Status = OK  or ArretSurPoint 
+        } //007  switch(Status) 
       } //008 end processing point  (TEST DEFLECTION)
     } //009 end processing line (else if myIntersectionOn2S.IsDone())
   }  //010 end if first departure point allows marching  while (!Arrive)
+
   done = Standard_True;
 }
 // ===========================================================================================================
@@ -1082,7 +1249,7 @@ void IntWalk_PWalking::Perform(const TColStd_Array1OfReal& ParDep,
 //           is outside the tangent zone (but it is not put into the line). Otherwise returns Standard_False.
 // ===========================================================================================================
 Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsoparametric theChoixIso,
-                                                         const Standard_Boolean          theDirectionFlag) 
+                                                          const Standard_Boolean          theDirectionFlag) 
 {
   Standard_Boolean bOutOfTangentZone = Standard_False;
   Standard_Boolean bStop = !myIntersectionOn2S.IsTangent();
@@ -1109,15 +1276,15 @@ Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsop
     Standard_Real f = 0.;
 
     switch (theChoixIso)
-      { 
-      case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
-      case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
-      case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
-      case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
-      }
+    { 
+    case IntImp_UIsoparametricOnCaro1: f = Abs(previousd1.X()); break;
+    case IntImp_VIsoparametricOnCaro1: f = Abs(previousd1.Y()); break;
+    case IntImp_UIsoparametricOnCaro2: f = Abs(previousd2.X()); break;
+    case IntImp_VIsoparametricOnCaro2: f = Abs(previousd2.Y()); break;
+    }
 
     if(f<0.1) f=0.1;
-    
+
     previousPoint.Parameters(Param(1),Param(2),Param(3),Param(4));
 
     Standard_Real dP1 = sensCheminement * pasuv[0] * previousd1.X() /f;
@@ -1129,7 +1296,7 @@ Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsop
     if(theChoixIso == IntImp_VIsoparametricOnCaro1 && Abs(dP2) < 1.e-7) dP2 *= (5. * (Standard_Real)dIncKey);
     if(theChoixIso == IntImp_UIsoparametricOnCaro2 && Abs(dP3) < 1.e-7) dP3 *= (5. * (Standard_Real)dIncKey);
     if(theChoixIso == IntImp_VIsoparametricOnCaro2 && Abs(dP4) < 1.e-7) dP4 *= (5. * (Standard_Real)dIncKey);
-   
+
     Param(1) += dP1;
     Param(2) += dP2;
     Param(3) += dP3; 
@@ -1148,196 +1315,196 @@ Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsop
     }
     else {
       if (myIntersectionOn2S.IsEmpty()) {
-       return bOutOfTangentZone;
+        return bOutOfTangentZone;
       }
 
       Status = TestDeflection();
 
       if(Status == IntWalk_OK) {
 
-       for(uvit = 0; uvit < 4; uvit++) {
-         if(pasuv[uvit] < pasInit[uvit]) {
-           pasuv[uvit] = pasInit[uvit];
-         }
-       }
+        for(uvit = 0; uvit < 4; uvit++) {
+          if(pasuv[uvit] < pasInit[uvit]) {
+            pasuv[uvit] = pasInit[uvit];
+          }
+        }
       }
 
       switch(Status) {
       case  IntWalk_ArretSurPointPrecedent:
-       {
-         bStop = Standard_True;
-         bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
-         break;
-       }
+        {
+          bStop = Standard_True;
+          bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
+          break;
+        }
       case IntWalk_PasTropGrand:
-       {
-         for(parit = 0; parit < 4; parit++) {
-           Param(parit+1) = SvParam[parit];
-         }
-         Standard_Boolean bDecrease = Standard_False;
-
-         for(uvit = 0; uvit < 4; uvit++) {
-           if(pasSav[uvit] < pasInit[uvit]) { 
-             pasInit[uvit] -= (pasInit[uvit] - pasSav[uvit]) * 0.1;
-             bDecrease = Standard_True;
-           }
-         }
-
-         if(bDecrease) nbIterWithoutAppend--;
-         break;
-       }
+        {
+          for(parit = 0; parit < 4; parit++) {
+            Param(parit+1) = SvParam[parit];
+          }
+          Standard_Boolean bDecrease = Standard_False;
+
+          for(uvit = 0; uvit < 4; uvit++) {
+            if(pasSav[uvit] < pasInit[uvit]) { 
+              pasInit[uvit] -= (pasInit[uvit] - pasSav[uvit]) * 0.1;
+              bDecrease = Standard_True;
+            }
+          }
+
+          if(bDecrease) nbIterWithoutAppend--;
+          break;
+        }
       case IntWalk_PointConfondu:
-       {
-         for(uvit = 0; uvit < 4; uvit++) {
-           if(pasuv[uvit] < pasInit[uvit]) {
-             pasuv[uvit] += (pasInit[uvit] - pasuv[uvit]) * 0.1;
-           }
-         }
-         break;
-       }
+        {
+          for(uvit = 0; uvit < 4; uvit++) {
+            if(pasuv[uvit] < pasInit[uvit]) {
+              pasuv[uvit] += (pasInit[uvit] - pasuv[uvit]) * 0.1;
+            }
+          }
+          break;
+        }
       case IntWalk_OK:
       case IntWalk_ArretSurPoint:
-       {
-         //
-         bStop = TestArret(theDirectionFlag, Param, ChoixIso);
-         //
-
-         //
-         if(!bStop) {
-           Standard_Real u11,v11,u12,v12; 
-           myIntersectionOn2S.Point().Parameters(u11,v11,u12,v12); 
-           Standard_Real u21,v21,u22,v22;
-           previousPoint.Parameters(u21,v21,u22,v22); 
-
-           if(((fabs(u11-u21) < ResoU1) && (fabs(v11-v21) < ResoV1)) ||
-              ((fabs(u12-u22) < ResoU2) && (fabs(v12-v22) < ResoV2))) {
-             nbEqualPoints++;
-           }
-           else {
-             nbEqualPoints = 0;
-           }
-         }
-         //
-
-         bStop = bStop || !myIntersectionOn2S.IsTangent();
-         bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
-
-         if(!bStop) {
-           Standard_Boolean pointisvalid = Standard_False;
-           Standard_Real u1,v1,u2,v2; 
-           myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2); 
-
-           if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
-              v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
-              v1 >= Vm1  && v2 >= Vm2) 
-             pointisvalid = Standard_True;
-
-           if(pointisvalid) {
-             previousPoint = myIntersectionOn2S.Point();
-             previoustg = myIntersectionOn2S.IsTangent();
-
-             if(!previoustg) {
-               previousd  = myIntersectionOn2S.Direction();
-               previousd1 = myIntersectionOn2S.DirectionOnS1();
-               previousd2 = myIntersectionOn2S.DirectionOnS2();
-             }
-             Standard_Boolean bAddPoint = Standard_True;
-
-             if(line->NbPoints() >= 1) {
-               gp_Pnt pf = line->Value(1).Value();
-               gp_Pnt pl = previousPoint.Value(); 
-
-               if(pf.Distance(pl) < Precision::Confusion()) { 
-                 dIncKey++; 
-                 if(dIncKey == 5000) return bOutOfTangentZone; 
-                 else bAddPoint = Standard_False;
-               }
-             }
-
-             if(bAddPoint) {
-               aSeqOfNewPoint.Append(previousPoint);
-               nbIterWithoutAppend = 0;
-             }
-           }
-
-           if (line->NbPoints() == 2) {
-             for(uvit = 0; uvit < 4; uvit++) {
-               pasSav[uvit] = pasuv[uvit]; 
-             }
-           }
-
-           if ( !pointisvalid ) {
-             // decrease step if out of bounds
-             // otherwise the same calculations will be 
-             // repeated several times
-             if ( ( u1 > UM1 ) || ( u1 < Um1 ) )
-               pasuv[0] *= 0.5;
-
-             if ( ( v1 > VM1 ) || ( v1 < Vm1 ) ) 
-               pasuv[1] *= 0.5;
-
-             if ( ( u2 > UM2 ) || ( u2 < Um2 ) )
-               pasuv[2] *= 0.5;
-
-             if ( ( v2 > VM2 ) || ( v2 < Vm2 ) )
-               pasuv[3] *= 0.5;
-           }
-         } // end if(!bStop)
-         else { //if(bStop)
-           if(close && (line->NbPoints() >= 1)) { 
-
-             if(!bOutOfTangentZone) {
-               aSeqOfNewPoint.Append(line->Value(1)); // line end
-             }
-             nbIterWithoutAppend = 0;
-           }
-           else {
-             ChoixIso = myIntersectionOn2S.Perform(Param, Rsnld, theChoixIso);
-
-             if(myIntersectionOn2S.IsEmpty()) { 
-               bStop = !myIntersectionOn2S.IsTangent();
-               bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
-             }
-             else {
-               Standard_Boolean bAddPoint = Standard_True;
-               Standard_Boolean pointisvalid = Standard_False;
-
-               previousPoint = myIntersectionOn2S.Point();
-               Standard_Real u1,v1,u2,v2; 
-               previousPoint.Parameters(u1,v1,u2,v2); 
-
-               if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
-                  v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
-                  v1 >= Vm1  && v2 >= Vm2) 
-                 pointisvalid = Standard_True;
-
-               if(pointisvalid) {
-
-                 if(line->NbPoints() >= 1) {
-                   gp_Pnt pf = line->Value(1).Value();
-                   gp_Pnt pl = previousPoint.Value(); 
-
-                   if(pf.Distance(pl) < Precision::Confusion()) { 
-                     dIncKey++; 
-                     if(dIncKey == 5000) return bOutOfTangentZone; 
-                     else bAddPoint = Standard_False;
-                   }
-                 }
-
-                 if(bAddPoint && !bOutOfTangentZone) {
-                   aSeqOfNewPoint.Append(previousPoint);
-                   nbIterWithoutAppend = 0;
-                 }
-               }
-             }
-           }
-         }
-         break;
-       }
+        {
+          //
+          bStop = TestArret(theDirectionFlag, Param, ChoixIso);
+          //
+
+          //
+          if(!bStop) {
+            Standard_Real u11,v11,u12,v12; 
+            myIntersectionOn2S.Point().Parameters(u11,v11,u12,v12); 
+            Standard_Real u21,v21,u22,v22;
+            previousPoint.Parameters(u21,v21,u22,v22); 
+
+            if(((fabs(u11-u21) < ResoU1) && (fabs(v11-v21) < ResoV1)) ||
+              ((fabs(u12-u22) < ResoU2) && (fabs(v12-v22) < ResoV2))) {
+                nbEqualPoints++;
+            }
+            else {
+              nbEqualPoints = 0;
+            }
+          }
+          //
+
+          bStop = bStop || !myIntersectionOn2S.IsTangent();
+          bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
+
+          if(!bStop) {
+            Standard_Boolean pointisvalid = Standard_False;
+            Standard_Real u1,v1,u2,v2; 
+            myIntersectionOn2S.Point().Parameters(u1,v1,u2,v2); 
+
+            if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
+              v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
+              v1 >= Vm1  && v2 >= Vm2) 
+              pointisvalid = Standard_True;
+
+            if(pointisvalid) {
+              previousPoint = myIntersectionOn2S.Point();
+              previoustg = myIntersectionOn2S.IsTangent();
+
+              if(!previoustg) {
+                previousd  = myIntersectionOn2S.Direction();
+                previousd1 = myIntersectionOn2S.DirectionOnS1();
+                previousd2 = myIntersectionOn2S.DirectionOnS2();
+              }
+              Standard_Boolean bAddPoint = Standard_True;
+
+              if(line->NbPoints() >= 1) {
+                gp_Pnt pf = line->Value(1).Value();
+                gp_Pnt pl = previousPoint.Value(); 
+
+                if(pf.Distance(pl) < Precision::Confusion()) { 
+                  dIncKey++; 
+                  if(dIncKey == 5000) return bOutOfTangentZone; 
+                  else bAddPoint = Standard_False;
+                }
+              }
+
+              if(bAddPoint) {
+                aSeqOfNewPoint.Append(previousPoint);
+                nbIterWithoutAppend = 0;
+              }
+            }
+
+            if (line->NbPoints() == 2) {
+              for(uvit = 0; uvit < 4; uvit++) {
+                pasSav[uvit] = pasuv[uvit]; 
+              }
+            }
+
+            if ( !pointisvalid ) {
+              // decrease step if out of bounds
+              // otherwise the same calculations will be 
+              // repeated several times
+              if ( ( u1 > UM1 ) || ( u1 < Um1 ) )
+                pasuv[0] *= 0.5;
+
+              if ( ( v1 > VM1 ) || ( v1 < Vm1 ) ) 
+                pasuv[1] *= 0.5;
+
+              if ( ( u2 > UM2 ) || ( u2 < Um2 ) )
+                pasuv[2] *= 0.5;
+
+              if ( ( v2 > VM2 ) || ( v2 < Vm2 ) )
+                pasuv[3] *= 0.5;
+            }
+          } // end if(!bStop)
+          else { //if(bStop)
+            if(close && (line->NbPoints() >= 1)) { 
+
+              if(!bOutOfTangentZone) {
+                aSeqOfNewPoint.Append(line->Value(1)); // line end
+              }
+              nbIterWithoutAppend = 0;
+            }
+            else {
+              ChoixIso = myIntersectionOn2S.Perform(Param, Rsnld, theChoixIso);
+
+              if(myIntersectionOn2S.IsEmpty()) { 
+                bStop = !myIntersectionOn2S.IsTangent();
+                bOutOfTangentZone = !myIntersectionOn2S.IsTangent();
+              }
+              else {
+                Standard_Boolean bAddPoint = Standard_True;
+                Standard_Boolean pointisvalid = Standard_False;
+
+                previousPoint = myIntersectionOn2S.Point();
+                Standard_Real u1,v1,u2,v2; 
+                previousPoint.Parameters(u1,v1,u2,v2); 
+
+                if(u1 <= UM1  && u2 <= UM2 && v1 <= VM1 && 
+                  v2 <= VM2  && u1 >= Um1 && u2 >= Um2 &&
+                  v1 >= Vm1  && v2 >= Vm2) 
+                  pointisvalid = Standard_True;
+
+                if(pointisvalid) {
+
+                  if(line->NbPoints() >= 1) {
+                    gp_Pnt pf = line->Value(1).Value();
+                    gp_Pnt pl = previousPoint.Value(); 
+
+                    if(pf.Distance(pl) < Precision::Confusion()) { 
+                      dIncKey++; 
+                      if(dIncKey == 5000) return bOutOfTangentZone; 
+                      else bAddPoint = Standard_False;
+                    }
+                  }
+
+                  if(bAddPoint && !bOutOfTangentZone) {
+                    aSeqOfNewPoint.Append(previousPoint);
+                    nbIterWithoutAppend = 0;
+                  }
+                }
+              }
+            }
+          }
+          break;
+        }
       default:
-       {
-         break;
-       }
+        {
+          break;
+        }
       }
     }
   }
@@ -1351,19 +1518,19 @@ Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsop
       previousPoint.Parameters(u1,v1,u2,v2); 
     else {
       if(aSeqOfNewPoint.Length() > 0)
-       aSeqOfNewPoint.Value(aSeqOfNewPoint.Length()).Parameters(u1,v1,u2,v2); 
+        aSeqOfNewPoint.Value(aSeqOfNewPoint.Length()).Parameters(u1,v1,u2,v2); 
       else
-       break;
+        break;
     }
 
     if(((u1 - Um1) < ResoU1) ||
-       ((UM1 - u1) < ResoU1) ||
-       ((u2 - Um2) < ResoU2) ||
-       ((UM2 - u2) < ResoU2) ||
-       ((v1 - Vm1) < ResoV1) ||
-       ((VM1 - v1) < ResoV1) ||
-       ((v2 - Vm2) < ResoV2) ||
-       ((VM2 - v2) < ResoV2))
+      ((UM1 - u1) < ResoU1) ||
+      ((u2 - Um2) < ResoU2) ||
+      ((UM2 - u2) < ResoU2) ||
+      ((v1 - Vm1) < ResoV1) ||
+      ((VM1 - v1) < ResoV1) ||
+      ((v2 - Vm2) < ResoV2) ||
+      ((VM2 - v2) < ResoV2))
       bExtendLine = Standard_True;
   }
 
@@ -1373,86 +1540,86 @@ Standard_Boolean IntWalk_PWalking::ExtendLineInCommonZone(const IntImp_ConstIsop
       bExtendLine = Standard_True;
 
       if(aSeqOfNewPoint.Length() > 1) {
-       TColStd_Array1OfReal FirstParams(0, 3), LastParams(0, 3), Resolutions(0, 3);
-       Resolutions(0) = ResoU1; Resolutions(1) = ResoV1; Resolutions(2) = ResoU2; Resolutions(3) = ResoV2;
-
-       aSeqOfNewPoint(1).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
-                                    FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
-       aSeqOfNewPoint(aSeqOfNewPoint.Length()).Parameters(LastParams.ChangeValue(0), 
-                                                          LastParams.ChangeValue(1),
-                                                          LastParams.ChangeValue(2), 
-                                                          LastParams.ChangeValue(3)); 
-       Standard_Integer indexofiso = 0;
-
-       if(theChoixIso == IntImp_UIsoparametricOnCaro1) indexofiso = 0;
-       if(theChoixIso == IntImp_VIsoparametricOnCaro1) indexofiso = 1;
-       if(theChoixIso == IntImp_UIsoparametricOnCaro2) indexofiso = 2;
-       if(theChoixIso == IntImp_VIsoparametricOnCaro2) indexofiso = 3;
-
-       Standard_Integer afirstindex = (indexofiso < 2) ? 0 : 2;
-       gp_Vec2d aTangentZoneDir(gp_Pnt2d(FirstParams.Value(afirstindex), FirstParams.Value(afirstindex + 1)),
-                                gp_Pnt2d(LastParams.Value(afirstindex), LastParams.Value(afirstindex + 1)));
-
-       gp_Dir2d anIsoDir(0, 1);
-
-       if((indexofiso == 1) || (indexofiso == 3))
-         anIsoDir = gp_Dir2d(1, 0);
-
-       if(aTangentZoneDir.SquareMagnitude() > gp::Resolution()) {
-         Standard_Real piquota = M_PI*0.25;
-
-         if(fabs(aTangentZoneDir.Angle(anIsoDir)) > piquota) {
-           Standard_Integer ii = 1, nextii = 2;
-           gp_Vec2d d1(0, 0);
-           Standard_Real asqresol = gp::Resolution();
-           asqresol *= asqresol;
-
-           do {
-             aSeqOfNewPoint(ii).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
-                                           FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
-             aSeqOfNewPoint(ii + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
-                                                 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
-             d1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
-                                    FirstParams.Value(afirstindex + 1)),
-                           gp_Pnt2d(LastParams.Value(afirstindex),
-                                    LastParams.Value(afirstindex + 1)));
-             ii++;
-           }
-           while((d1.SquareMagnitude() < asqresol) &&
-                 (ii < aSeqOfNewPoint.Length()));
-
-           nextii = ii;
-
-           while(nextii < aSeqOfNewPoint.Length()) {
-
-             gp_Vec2d nextd1(0, 0);
-             Standard_Integer jj = nextii;
-
-             do {
-               aSeqOfNewPoint(jj).Parameters(FirstParams.ChangeValue(0), FirstParams.ChangeValue(1),
-                                             FirstParams.ChangeValue(2), FirstParams.ChangeValue(3));
-               aSeqOfNewPoint(jj + 1).Parameters(LastParams.ChangeValue(0), LastParams.ChangeValue(1),
-                                                 LastParams.ChangeValue(2), LastParams.ChangeValue(3));
-               nextd1 = gp_Vec2d(gp_Pnt2d(FirstParams.Value(afirstindex),
-                                          FirstParams.Value(afirstindex + 1)),
-                                 gp_Pnt2d(LastParams.Value(afirstindex),
-