0024005: Intersecting a slightly off angle plane with a cylinder takes 7+ seconds
[occt.git] / src / IntPatch / IntPatch_GLine.cxx
index a88bbed..ef84e89 100755 (executable)
@@ -550,185 +550,289 @@ void IntPatch_GLine::ComputeVertexParameters(const Standard_Real /*Tol*/)
 
     SortAgain = Standard_False;
     SortIsOK = Standard_True; 
-    for(i=2; i<=nbvtx && SortIsOK; i++) { 
+    for(i=2; i<=nbvtx && SortIsOK; i++)
+    { 
       IntPatch_Point& VTX   = svtx.ChangeValue(i);      
-      for(j=1; j<=nbvtx && SortIsOK; j++) {
-       if(i!=j) { 
-         IntPatch_Point& VTXM1 = svtx.ChangeValue(j);
-         Standard_Boolean kill   = Standard_False;
-         Standard_Boolean killm1 = Standard_False;
-         if(Abs(VTXM1.ParameterOnLine()-VTX.ParameterOnLine())<PrecisionPConfusion) { 
-           if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) {  //-- OnS1    OnS1
-             if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) {    //-- OnS1 == OnS1
-               if(VTXM1.IsOnDomS2()) {                 //-- OnS1 == OnS1  OnS2  
-                 if(VTX.IsOnDomS2()==Standard_False) {   //-- OnS1 == OnS1  OnS2 PasOnS2
-                   kill=Standard_True;   
-                 }
-                 else {
-                   if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) { //-- OnS1 == OnS1  OnS2 == OnS2
-                     if(VTXM1.IsVertexOnS2()) {                      
-                       kill=Standard_True;
-                     }
-                     else { 
-                       killm1=Standard_True;
-                     }
-                   }
-                 }
-               }
-               else {                                  //-- OnS1 == OnS1  PasOnS2  
-                 if(VTX.IsOnDomS2()) {                 //-- OnS1 == OnS1  PasOnS2  OnS2
-                   killm1=Standard_True;
-                 }
-               }
-             }
-           }
-           else { //-- Pas OnS1  et  OnS1
-             if(VTXM1.IsOnDomS2()==Standard_False && VTX.IsOnDomS2()==Standard_False) { 
-               if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()==Standard_False) { 
-                 kill=Standard_True;
-               }
-               else  if(VTX.IsOnDomS1() && VTXM1.IsOnDomS1()==Standard_False) { 
-                 killm1=Standard_True;
-               }
-             }
-           }
-           
-           if(!(kill || killm1)) {
-             if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()) {  //-- OnS2    OnS2
-               if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) {    //-- OnS2 == OnS2
-                 if(VTXM1.IsOnDomS1()) {                 //-- OnS2 == OnS2  OnS1  
-                   if(VTX.IsOnDomS1()==Standard_False) {   //-- OnS2 == OnS2  OnS1 PasOnS1
-                     kill=Standard_True;   
-                   }
-                   else {
-                     if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) { //-- OnS2 == OnS2  OnS1 == OnS1
-                       if(VTXM1.IsVertexOnS1()) {                    
-                         kill=Standard_True;                //-- OnS2 == OnS2  OnS1 == OnS1  Vtx PasVtx
-                       }
-                       else { 
-                         killm1=Standard_True;              //-- OnS2 == OnS2  OnS1 == OnS1  PasVtx Vtx
-                       } 
-                     }
-                   }
-                 }
-                 else {                                  //-- OnS2 == OnS2  PasOnS1  
-                   if(VTX.IsOnDomS1()) {                 //-- OnS2 == OnS2  PasOnS1  OnS1
-                     killm1=Standard_True;
-                   }
-                 }
-               }
-             }
-             else { //-- Pas OnS2  et  OnS2
-               if(VTXM1.IsOnDomS1()==Standard_False && VTX.IsOnDomS1()==Standard_False) { 
-                 if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()==Standard_False) { 
-                   kill=Standard_True;
-                 }
-                 else  if(VTX.IsOnDomS2() && VTXM1.IsOnDomS2()==Standard_False) { 
-                   killm1=Standard_True;
-                 }
-               }
-             }
-           }
-           //-- On a j < i 
-           if(kill) { 
-             SortIsOK = Standard_False;
-             if(lapt) { if(indl>i) indl--; else if(indl==i) indl=j; } 
-             if(fipt) { if(indf>i) indf--; else if(indf==i) indf=j; } 
-             svtx.Remove(i);
-             nbvtx--;
-           }
-           else if(killm1) { 
-             SortIsOK = Standard_False;
-             if(lapt) { if(indl>j) indl--;  else if(indl==j) indl=i-1;} 
-             if(fipt) { if(indf>j) indf--;  else if(indf==j) indf=i-1;} 
-             svtx.Remove(j);
-             nbvtx--; 
-           }
-//         else
-           else if(ArcType()==IntPatch_Circle || ArcType()==IntPatch_Ellipse) { // eap
-             //-- deux points de meme parametre qui ne peuvent etre confondus
-             //-- On change les parametres d un des points si les points UV sont
-             //-- differents. Ceci distingue le cas des aretes de couture.
-             // ==========================================================
-             //-- 2 points with the same parameters
-             //-- Change parametres of one point if points UV are
-             //-- different. This is the case of seam edge
-             Standard_Real ponline = VTX.ParameterOnLine();
-             // eap, =>>
-             Standard_Real newParam = ponline;
-             const Standard_Real PiPi = M_PI+M_PI;
-             Standard_Boolean is2PI = ( Abs(ponline-PiPi) <= PrecisionPConfusion );
-
-             if (nbvtx > 2 && // do this check if seam edge only gives vertices 
-                 !is2PI)      // but always change 2PI -> 0
-               continue;
-             
-             if (is2PI)
-               newParam = 0;
-             else if (Abs(ponline) <= PrecisionPConfusion)
-               newParam = PiPi;
-             else 
-               newParam -= PiPi;
-//           if(  (Abs(ponline)<=PrecisionPConfusion)
-//                ||(Abs(ponline-M_PI-M_PI) <=PrecisionPConfusion)) 
-             // eap, <<=
-               Standard_Real u1a,v1a,u2a,v2a,u1b,v1b,u2b,v2b; 
-               VTXM1.Parameters(u1a,v1a,u2a,v2a);
-               VTX.Parameters(u1b,v1b,u2b,v2b);
-               Standard_Integer flag  = 0;
-               
-               if(   (Abs(u1a-u1b)<=PrecisionPConfusion) ) flag|=1;
-               if(   (Abs(v1a-v1b)<=PrecisionPConfusion) ) flag|=2;
-               if(   (Abs(u2a-u2b)<=PrecisionPConfusion) ) flag|=4;
-               if(   (Abs(v2a-v2b)<=PrecisionPConfusion) ) flag|=8;
-               Standard_Boolean TestOn1 = Standard_False;
-               Standard_Boolean TestOn2 = Standard_False;
-               switch(flag) { 
-               case 3:   //-- meme point U1 V1  
-               case 7:  //-- meme point U1 V1   meme U2            
-               case 12:  //--                    meme U2 V2
-               case 13:  //-- meme point U1      meme U2 V2
-               case 10:  //-- meme point    V1   meme    V2   Test si U1a=U1b Mod 2PI et Test si U2a=U2b Mod 2PI
-                 break;
-               case 11:   //-- meme point U1 V1   meme    V2   Test si U2a=U2b Mod 2PI   
-                 { TestOn2 = Standard_True; break; } 
-               case 14:  //-- meme point    V1   meme U2 V2   Test si U1a=U1b Mod 2PI
-                 { TestOn1 = Standard_True; break; } 
-               default: break;
-               };
-               // eap
-               //if(ArcType()==IntPatch_Circle || ArcType()==IntPatch_Ellipse) {}
-                 if(TestOn1) { 
-                   //// modified by jgv, 2.11.01 for BUC61033 ////
-                   Standard_Real U1A = (u1a < u1b)? u1a : u1b;
-                   Standard_Real U1B = (u1a < u1b)? u1b : u1a;
-                   if (u1min == RealLast())
-                     {
-                       u1min = U1A;
-                       u1max = U1B;
-                     }
-                   else
-                     {
-                       if (Abs(U1A-u1min) > PrecisionPConfusion)
-                         ToBreak = Standard_True;
-                       if (Abs(U1B-u1max) > PrecisionPConfusion)
-                         ToBreak = Standard_True;
-                     }
+      for(j=1; j<=nbvtx && SortIsOK; j++)
+      {
+        if(i!=j)
+        {
+          IntPatch_Point& VTXM1 = svtx.ChangeValue(j);
+          Standard_Boolean kill   = Standard_False;
+          Standard_Boolean killm1 = Standard_False;
+          if(Abs(VTXM1.ParameterOnLine()-VTX.ParameterOnLine())<PrecisionPConfusion)
+          {
+            if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()) //-- OnS1    OnS1
+            {
+              if(VTXM1.ArcOnS1() == VTX.ArcOnS1())//-- OnS1 == OnS1
+              {
+                if(VTXM1.IsOnDomS2())             //-- OnS1 == OnS1  OnS2  
+                {
+                  if(VTX.IsOnDomS2()==Standard_False)//-- OnS1 == OnS1  OnS2 PasOnS2
+                  {
+                    kill=Standard_True;
+                  }
+                  else
+                  {
+                    if(VTXM1.ArcOnS2() == VTX.ArcOnS2()) //-- OnS1 == OnS1  OnS2 == OnS2
+                    {
+                      if(VTXM1.IsVertexOnS2())
+                      {
+                        kill=Standard_True;
+                      }
+                      else
+                      {
+                        killm1=Standard_True;
+                      }
+                    }
+                  }
+                }
+                else                    //-- OnS1 == OnS1  PasOnS2  
+                {
+                  if(VTX.IsOnDomS2())   //-- OnS1 == OnS1  PasOnS2  OnS2
+                  {
+                    killm1=Standard_True;
+                  }
+                }
+              }
+            }
+            else                        //-- Pas OnS1  et  OnS1
+            {
+              if(VTXM1.IsOnDomS2()==Standard_False && VTX.IsOnDomS2()==Standard_False)
+              {
+                if(VTXM1.IsOnDomS1() && VTX.IsOnDomS1()==Standard_False)
+                {
+                  kill=Standard_True;
+                }
+                else if(VTX.IsOnDomS1() && VTXM1.IsOnDomS1()==Standard_False)
+                {
+                  killm1=Standard_True;
+                }
+              }
+            }
+
+            if(!(kill || killm1))
+            {
+              if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2())  //-- OnS2    OnS2
+              {
+                if(VTXM1.ArcOnS2() == VTX.ArcOnS2())    //-- OnS2 == OnS2
+                {
+                  if(VTXM1.IsOnDomS1())                 //-- OnS2 == OnS2  OnS1 
+                  {
+                    if(VTX.IsOnDomS1()==Standard_False) //-- OnS2 == OnS2  OnS1 PasOnS1
+                    {
+                      kill=Standard_True;
+                    }
+                    else
+                    {
+                      if(VTXM1.ArcOnS1() == VTX.ArcOnS1()) //-- OnS2 == OnS2  OnS1 == OnS1
+                      {
+                        if(VTXM1.IsVertexOnS1())
+                        {
+                          kill=Standard_True;              //-- OnS2 == OnS2  OnS1 == OnS1  Vtx PasVtx
+                        }
+                        else
+                        {
+                          killm1=Standard_True;            //-- OnS2 == OnS2  OnS1 == OnS1  PasVtx Vtx
+                        }
+                      }
+                    }
+                  }
+                  else
+                  {                           //-- OnS2 == OnS2  PasOnS1
+                    if(VTX.IsOnDomS1())       //-- OnS2 == OnS2  PasOnS1  OnS1
+                    {
+                      killm1=Standard_True;
+                    }
+                  }
+                }
+              }
+              else //-- Pas OnS2  et  OnS2
+              {
+                if(VTXM1.IsOnDomS1()==Standard_False && VTX.IsOnDomS1()==Standard_False)
+                {
+                  if(VTXM1.IsOnDomS2() && VTX.IsOnDomS2()==Standard_False)
+                  {
+                    kill=Standard_True;
+                  }
+                  else if(VTX.IsOnDomS2() && VTXM1.IsOnDomS2()==Standard_False)
+                  {
+                    killm1=Standard_True;
+                  }
+                }
+              }
+            }
+
+            //-- On a j < i
+            if(kill)
+            {
+              SortIsOK = Standard_False;
+              if(lapt)
+              {
+                if(indl>i)
+                  indl--;
+                else if(indl==i)
+                  indl=j;
+              }
+
+              if(fipt)
+              {
+                if(indf>i)
+                  indf--;
+                else if(indf==i)
+                  indf=j;
+              }
+
+              svtx.Remove(i);
+              nbvtx--;
+            }
+            else if(killm1)
+            {
+              SortIsOK = Standard_False;
+              if(lapt)
+              {
+                if(indl>j)
+                  indl--;
+                else if(indl==j)
+                  indl=i-1;
+              } 
+
+              if(fipt)
+              {
+                if(indf>j)
+                  indf--;
+                else if(indf==j)
+                  indf=i-1;
+              }
+
+              svtx.Remove(j);
+              nbvtx--;
+            }//            else
+            else if(ArcType()==IntPatch_Circle || ArcType()==IntPatch_Ellipse) // eap
+            {
+              //-- deux points de meme parametre qui ne peuvent etre confondus
+              //-- On change les parametres d un des points si les points UV sont
+              //-- differents. Ceci distingue le cas des aretes de couture.
+              // ==========================================================
+              //-- 2 points with the same parameters
+              //-- Change parametres of one point if points UV are
+              //-- different. This is the case of seam edge
+
+              Standard_Real ponline = VTX.ParameterOnLine();
+              // eap, =>>
+              Standard_Real newParam = ponline;
+              const Standard_Real PiPi = M_PI+M_PI;
+              Standard_Boolean is2PI = ( Abs(ponline-PiPi) <= PrecisionPConfusion );
+
+              if (nbvtx > 2 && // do this check if seam edge only gives vertices 
+                  !is2PI)      // but always change 2PI -> 0
+                        continue;
+
+              if (is2PI)
+                newParam = 0;
+              else if (Abs(ponline) <= PrecisionPConfusion)
+                newParam = PiPi;
+              else
+                newParam -= PiPi;
+
+              //             if(  (Abs(ponline)<=PrecisionPConfusion)
+              //                  ||(Abs(ponline-M_PI-M_PI) <=PrecisionPConfusion))
+              // eap, <<=
+
+              Standard_Real u1a,v1a,u2a,v2a,u1b,v1b,u2b,v2b;
+              VTXM1.Parameters(u1a,v1a,u2a,v2a);
+              VTX.Parameters(u1b,v1b,u2b,v2b);
+              Standard_Integer flag  = 0;
+
+              if(   (Abs(u1a-u1b)<=PrecisionPConfusion) )
+                flag|=1;
+
+              if(   (Abs(v1a-v1b)<=PrecisionPConfusion) )
+                flag|=2;
+              if(   (Abs(u2a-u2b)<=PrecisionPConfusion) )
+                flag|=4;
+
+              if(   (Abs(v2a-v2b)<=PrecisionPConfusion) )
+                flag|=8;
+
+              Standard_Boolean TestOn1 = Standard_False;
+              Standard_Boolean TestOn2 = Standard_False;
+
+              switch(flag)
+              { 
+              case 3:   //-- meme point U1 V1  
+              case 7:  //-- meme point U1 V1   meme U2
+              case 12:  //--                    meme U2 V2
+              case 13:  //-- meme point U1      meme U2 V2
+              case 10:  //-- meme point    V1   meme    V2   Test si U1a=U1b Mod 2PI et Test si U2a=U2b Mod 2PI
+                break;
+              case 11:   //-- meme point U1 V1   meme    V2   Test si U2a=U2b Mod 2PI
+                {
+                  TestOn2 = Standard_True;
+                  break;
+                }
+
+              case 14:  //-- meme point    V1   meme U2 V2   Test si U1a=U1b Mod 2PI
+                {
+                  TestOn1 = Standard_True;
+                  break;
+                }
+              default:
+                break;
+              };
+
+              // eap
+              //if(ArcType()==IntPatch_Circle || ArcType()==IntPatch_Ellipse) {}
+              if(TestOn1)
+              {
+                //// modified by jgv, 2.11.01 for BUC61033 ////
+                Standard_Real U1A = (u1a < u1b)? u1a : u1b;
+                Standard_Real U1B = (u1a < u1b)? u1b : u1a;
+                
+                if (u1min == RealLast())
+                {
+                  u1min = U1A;
+                  u1max = U1B;
+                }
+                else
+                {
+                  if (Abs(U1A-u1min) > PrecisionPConfusion)
+                    ToBreak = Standard_True;
+                  if (Abs(U1B-u1max) > PrecisionPConfusion)
+                    ToBreak = Standard_True;
+                }
                    ///////////////////////////////////////////////
                    // eap, =>>
 //                   if (Abs(ponline) <= PrecisionPConfusion) { 
 //                   const Standard_Real PiPi = M_PI+M_PI;
-                     if(newParam >= ParamMinOnLine && newParam <= ParamMaxOnLine
-                        /*PiPi >= ParamMinOnLine && PiPi<=ParamMaxOnLine*/) { 
-                       SortAgain = Standard_True;
-                       SortIsOK = Standard_False;
-                       if (newParam > ponline)
-                         if(u1a < u1b) { VTX.SetParameter(newParam); } 
-                         else          { VTXM1.SetParameter(newParam); }
-                       else
-                         if(u1a > u1b) { VTX.SetParameter(newParam); } 
-                         else          { VTXM1.SetParameter(newParam); } 
-                     }
+                if(newParam >= ParamMinOnLine && newParam <= ParamMaxOnLine
+                  /*PiPi >= ParamMinOnLine && PiPi<=ParamMaxOnLine*/)
+                {
+                  SortAgain = Standard_True;
+                  SortIsOK = Standard_False;
+                  if (newParam > ponline)
+                  {
+                    if(u1a < u1b)
+                    {
+                      VTX.SetParameter(newParam);
+                    } 
+                    else
+                    {
+                      VTXM1.SetParameter(newParam);
+                    }
+                  }
+                  else
+                  {
+                    if(u1a > u1b)
+                    {
+                      VTX.SetParameter(newParam);
+                    }
+                    else
+                    {
+                      VTXM1.SetParameter(newParam);
+                    } 
+                  }
+                }
 //                 }
 //                 else { 
 //                   if(0.0 >= ParamMinOnLine && 0.0<=ParamMaxOnLine) { 
@@ -739,38 +843,59 @@ void IntPatch_GLine::ComputeVertexParameters(const Standard_Real /*Tol*/)
 //                   }
 //                 }
                    // eap, <<=
-                 }
-                 if(TestOn2) { 
-                   //// modified by jgv, 2.11.01 for BUC61033 ////
-                   Standard_Real U2A = (u2a < u2b)? u2a : u2b;
-                   Standard_Real U2B = (u2a < u2b)? u2b : u2a;
-                   if (u2min == RealLast())
-                     {
-                       u2min = U2A;
-                       u2max = U2B;
-                     }
-                   else
-                     {
-                       if (Abs(U2A-u2min) > PrecisionPConfusion)
-                         ToBreak = Standard_True;
-                       if (Abs(U2B-u2max) > PrecisionPConfusion)
-                         ToBreak = Standard_True;
-                     }
+              }
+
+              if(TestOn2)
+              {
+                //// modified by jgv, 2.11.01 for BUC61033 ////
+                Standard_Real U2A = (u2a < u2b)? u2a : u2b;
+                Standard_Real U2B = (u2a < u2b)? u2b : u2a;
+                if (u2min == RealLast())
+                {
+                  u2min = U2A;
+                  u2max = U2B;
+                }
+                else
+                {
+                  if (Abs(U2A-u2min) > PrecisionPConfusion)
+                    ToBreak = Standard_True;
+                  
+                  if (Abs(U2B-u2max) > PrecisionPConfusion)
+                    ToBreak = Standard_True;
+
+                }
                    ///////////////////////////////////////////////
                    // eap, =>>
 //                 if (Abs(ponline) <= PrecisionPConfusion) { 
 //                   const Standard_Real PiPi = M_PI+M_PI;
-                     if(newParam >= ParamMinOnLine && newParam <= ParamMaxOnLine
-                        /*PiPi >= ParamMinOnLine && PiPi<=ParamMaxOnLine*/) {
-                       SortAgain = Standard_True;
-                       SortIsOK = Standard_False;
-                       if (newParam > ponline)
-                         if(u2a < u2b) { VTX.SetParameter(newParam); } 
-                         else          { VTXM1.SetParameter(newParam); }
-                       else
-                         if(u2a > u2b) { VTX.SetParameter(newParam); } 
-                         else          { VTXM1.SetParameter(newParam); } 
-                     }
+                if(newParam >= ParamMinOnLine && newParam <= ParamMaxOnLine
+                  /*PiPi >= ParamMinOnLine && PiPi<=ParamMaxOnLine*/)
+                {
+                  SortAgain = Standard_True;
+                  SortIsOK = Standard_False;
+                  if (newParam > ponline)
+                  {
+                    if(u2a < u2b)
+                    {
+                      VTX.SetParameter(newParam);
+                    }
+                    else
+                    {
+                      VTXM1.SetParameter(newParam);
+                    }
+                  }
+                  else
+                  {
+                    if(u2a > u2b)
+                    {
+                      VTX.SetParameter(newParam);
+                    }
+                    else
+                    {
+                      VTXM1.SetParameter(newParam);
+                    }
+                  }
+                }
 //                 }
 //                 else { 
 //                   if(0.0 >= ParamMinOnLine && 0.0<=ParamMaxOnLine) {
@@ -783,10 +908,10 @@ void IntPatch_GLine::ComputeVertexParameters(const Standard_Real /*Tol*/)
 //               }
 //             }
              // eap, <<=
-             }
-           }
-         }
-       }
+              }
+            }
+          }
+        }
       } //-- if(i!=j)
     }
   }
@@ -809,6 +934,7 @@ void IntPatch_GLine::ComputeVertexParameters(const Standard_Real /*Tol*/)
       }
     }
     while(!SortIsOK);
+
     indl=nbvtx;
     indf=1;
   }