0025449: Excess vertex in result of General Fuse operation.
[occt.git] / src / IntTools / IntTools_EdgeFace.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 1402429..85bc50a
@@ -1,22 +1,17 @@
 // Created on: 2001-02-26
 // Created by: Peter KURNEV
-// Copyright (c) 2001-2012 OPEN CASCADE SAS
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <IntTools_EdgeFace.ixx>
 
@@ -33,7 +28,7 @@
 #include <IntTools_CommonPrt.hxx>
 #include <IntTools_Root.hxx>
 #include <IntTools_BeanFaceIntersector.hxx>
-#include <BOPInt_Context.hxx>
+#include <IntTools_Context.hxx>
 
 #include <BRep_Tool.hxx>
 
@@ -63,7 +58,7 @@
 #include <Extrema_POnCurv.hxx>
 #include <Extrema_POnSurf.hxx>
 
-// modified by NIZHNY-MKK  Thu Jul 21 11:35:59 2005
+
 #include <IntCurveSurface_HInter.hxx>
 #include <GeomAdaptor_HCurve.hxx>
 #include <GeomAdaptor_HSurface.hxx>
 
 static
   Standard_Boolean IsCoplanar (const BRepAdaptor_Curve&  ,
-                              const BRepAdaptor_Surface& );
+          const BRepAdaptor_Surface& );
 static
   Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
-                            const BRepAdaptor_Surface& aSurface);
+        const BRepAdaptor_Surface& aSurface);
 static
   Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
-                                   const BRepAdaptor_Curve& aCurve ,
-                                   const BRepAdaptor_Surface& aSurface);
+        const BRepAdaptor_Curve& aCurve ,
+        const BRepAdaptor_Surface& aSurface);
 
 //=======================================================================
 //function : IntTools_EdgeFace::IntTools_EdgeFace
@@ -105,7 +100,7 @@ static
 //function : SetContext
 //purpose  : 
 //=======================================================================
-void IntTools_EdgeFace::SetContext(const Handle(BOPInt_Context)& theContext) 
+void IntTools_EdgeFace::SetContext(const Handle(IntTools_Context)& theContext) 
 {
   myContext = theContext;
 }
@@ -114,7 +109,7 @@ void IntTools_EdgeFace::SetContext(const Handle(BOPInt_Context)& theContext)
 //function : Context
 //purpose  : 
 //=======================================================================
-const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const 
+const Handle(IntTools_Context)& IntTools_EdgeFace::Context()const 
 {
   return myContext;
 }
@@ -122,25 +117,23 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetEdge
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
+void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge)
 {
   myEdge=anEdge;
 }
-
 //=======================================================================
 //function : SetFace
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
+void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace)
 {
   myFace=aFace;
 }
-
 //=======================================================================
 //function : SetTolE
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetTolE(const Standard_Real aTol) 
+void IntTools_EdgeFace::SetTolE(const Standard_Real aTol) 
 {
   myTolE=aTol;
 } 
@@ -148,16 +141,47 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetTolF
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetTolF(const Standard_Real aTol) 
+void IntTools_EdgeFace::SetTolF(const Standard_Real aTol) 
 {
   myTolF=aTol;
 } 
-
+//=======================================================================
+//function : Edge
+//purpose  : 
+//=======================================================================
+const TopoDS_Edge& IntTools_EdgeFace::Edge()const 
+{
+  return myEdge;
+}
+//=======================================================================
+//function : Face
+//purpose  : 
+//=======================================================================
+const TopoDS_Face& IntTools_EdgeFace::Face()const 
+{
+  return myFace;
+}
+//=======================================================================
+//function : TolE
+//purpose  : 
+//=======================================================================
+Standard_Real IntTools_EdgeFace::TolE()const 
+{
+  return myTolE;
+}
+ //=======================================================================
+//function : TolF
+//purpose  : 
+//=======================================================================
+Standard_Real IntTools_EdgeFace::TolF()const 
+{
+  return myTolF;
+} 
 //=======================================================================
 //function : SetDiscretize
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
+void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret)
 {
   myDiscret=aDiscret;
 }
@@ -165,7 +189,7 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetDeflection
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl) 
+void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl) 
 {
   myDeflection=aDefl;
 } 
@@ -173,7 +197,7 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetEpsilonT
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT) 
+void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT) 
 {
   myEpsT=anEpsT;
 } 
@@ -181,7 +205,7 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetEpsilonNull
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull) 
+void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull) 
 {
   myEpsNull=anEpsNull;
 } 
@@ -190,8 +214,8 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetRange
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
-                                  const Standard_Real aLast) 
+void IntTools_EdgeFace::SetRange(const Standard_Real aFirst,
+                                 const Standard_Real aLast) 
 {
   myRange.SetFirst (aFirst);
   myRange.SetLast  (aLast);
@@ -201,7 +225,7 @@ const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const
 //function : SetRange
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange) 
+void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange) 
 {
   myRange.SetFirst (aRange.First());
   myRange.SetLast  (aRange.Last());
@@ -256,7 +280,7 @@ void IntTools_EdgeFace::CheckData()
 //function : Prepare
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::Prepare() 
+void IntTools_EdgeFace::Prepare() 
 {
   Standard_Integer pri;
   IntTools_CArray1OfReal aPars;
@@ -269,7 +293,7 @@ void IntTools_EdgeFace::CheckData()
   //
   // 2.Prepare myCriteria
   if (aCurveType==GeomAbs_BSplineCurve||
      aCurveType==GeomAbs_BezierCurve) {
+ aCurveType==GeomAbs_BezierCurve) {
     myCriteria=1.5*myTolE+myTolF;
   }
   else {
@@ -287,7 +311,8 @@ void IntTools_EdgeFace::CheckData()
   //
   //
   // 3.Prepare myPars 
-  pri = IntTools::PrepareArgs(myC, myTmax, myTmin, myDiscret, myDeflection, aPars);
+  pri = IntTools::PrepareArgs(myC, myTmax, myTmin, 
+                              myDiscret, myDeflection, aPars);
   if (pri) {
     myErrorStatus=6;
     return;
@@ -337,20 +362,20 @@ void IntTools_EdgeFace::CheckData()
 
     if (i==(aNb-1)) {
       if (ind1 && ind0) {
      aRange.SetLast(t1);
      myProjectableRanges.Append(aRange);
+ aRange.SetLast(t1);
+ myProjectableRanges.Append(aRange);
       }
       if (ind1 && !ind0) {
      FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
      aRange.SetFirst(tRoot);
      aRange.SetLast(t1);
      myProjectableRanges.Append(aRange);
+ FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
+ aRange.SetFirst(tRoot);
+ aRange.SetLast(t1);
+ myProjectableRanges.Append(aRange);
       }
       //
       if (ind0 && !ind1) {
      FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
      aRange.SetLast(tRoot);
      myProjectableRanges.Append(aRange);
+ FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
+ aRange.SetLast(tRoot);
+ myProjectableRanges.Append(aRange);
       }
       //
       break;
@@ -360,11 +385,11 @@ void IntTools_EdgeFace::CheckData()
       FindProjectableRoot(t0, t1, ind0, ind1, tRoot);
       
       if (ind0 && !ind1) {
      aRange.SetLast(tRoot);
      myProjectableRanges.Append(aRange);
+ aRange.SetLast(tRoot);
+ myProjectableRanges.Append(aRange);
       }
       else {
      aRange.SetFirst(tRoot);
+ aRange.SetFirst(tRoot);
       }
     } // if (ind0 != ind1)
     ind0=ind1;
@@ -376,92 +401,65 @@ void IntTools_EdgeFace::CheckData()
 //purpose  : 
 //=======================================================================
   void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1,
-                                              const Standard_Real tt2,
-                                              const Standard_Integer ff1,
-                                              const Standard_Integer ff2,
-                                              Standard_Real& tRoot)
+                                               const Standard_Real tt2,
+                                               const Standard_Integer ff1,
+                                               const Standard_Integer /*ff2*/,
+                                               Standard_Real& tRoot)
 {
   Standard_Real tm, t1, t2, aEpsT;
-  Standard_Integer anIsProj1, anIsProj2, anIsProjm;
-  aEpsT=0.5*myEpsT;
-  //
+  Standard_Integer anIsProj1, anIsProjm;
+  aEpsT = 0.5 * myEpsT;
+
   // Root is inside [tt1, tt2]
-  t1=tt1;  
-  t2=tt2;
-  anIsProj1=ff1;
-  anIsProj2=ff2;
-  
-  for(;;) {
-    if (fabs(t1-t2) < aEpsT) {
-      tRoot=(anIsProj1) ? t1 : t2;
+  t1 = tt1;
+  t2 = tt2;
+  anIsProj1 =  ff1;
+
+  for(;;)
+  {
+    if (fabs(t1 - t2) < aEpsT)
+    {
+      tRoot = (anIsProj1) ? t1 : t2;
       return;
     }
-    tm=.5*(t1+t2);
-    anIsProjm=IsProjectable(tm);
-    
-    if (anIsProjm != anIsProj1) {
-      t2=tm;
-      anIsProj2=anIsProjm;
+    tm = 0.5 * (t1 + t2);
+    anIsProjm = IsProjectable(tm);
+
+    if (anIsProjm != anIsProj1)
+    {
+      t2 = tm;
     }
-    else {
-      t1=tm;
-      anIsProj1=anIsProjm;
+    else
+    {
+      t1 = tm;
+      anIsProj1 = anIsProjm;
     }
-  }
+  } // for(;;)
 }
 //=======================================================================
 //function : IsProjectable
 //purpose  : 
 //=======================================================================
-  Standard_Boolean IntTools_EdgeFace::IsProjectable(const Standard_Real t) const
+Standard_Boolean IntTools_EdgeFace::IsProjectable
+  (const Standard_Real aT) const
 {
-  Standard_Boolean bFlag;
-  Standard_Real Umin, Usup, Vmin, Vsup;
-
-  Umin=myS.FirstUParameter();
-  Usup=myS.LastUParameter();
-  Vmin=myS.FirstVParameter();
-  Vsup=myS.LastVParameter ();
-  
-  gp_Pnt P;
-  myC.D0(t, P);
-  GeomAPI_ProjectPointOnSurf aProjector;
+  Standard_Boolean bFlag; 
+  gp_Pnt aPC;
   //
-  Standard_Real ULD = 0., VLD = 0.;
-
-  GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace);
-  aLocProj.Perform(P);
-  bFlag = aLocProj.IsDone();
-  
-  if(bFlag) {
-    aLocProj.LowerDistanceParameters(ULD, VLD);
-  }
+  myC.D0(aT, aPC);
+  bFlag=myContext->IsValidPointForFace(aPC, myFace, myCriteria);
   //
-
-  if (bFlag) {
-    bFlag=Standard_False;
-
-    // 
-    TopAbs_State aState;
-    gp_Pnt2d aP2d(ULD, VLD);
-
-    aState = myContext->FClass2d(myFace).Perform(aP2d);
-    //
-    
-    if (aState==TopAbs_IN || aState==TopAbs_ON) {
-      bFlag=Standard_True;
-    }
-  }
   return bFlag;
 }
-
 //=======================================================================
 //function : DistanceFunction
 //purpose  : 
 //=======================================================================
-  Standard_Real IntTools_EdgeFace::DistanceFunction(const Standard_Real t)
+Standard_Real IntTools_EdgeFace::DistanceFunction
+  (const Standard_Real t)
 {
-  Standard_Real Umin, Usup, Vmin, Vsup, aD;
+  Standard_Real aD;
+
   //
   gp_Pnt P;
   myC.D0(t, P);
@@ -474,11 +472,6 @@ void IntTools_EdgeFace::CheckData()
     return aD; 
   }
   
-  Umin=myS.FirstUParameter();
-  Usup=myS.LastUParameter();
-  Vmin=myS.FirstVParameter();
-  Vsup=myS.LastVParameter ();
-  
   //
   Standard_Boolean bFlag = Standard_False;
 
@@ -507,10 +500,11 @@ void IntTools_EdgeFace::CheckData()
 //function : IsEqDistance
 //purpose  : 
 //=======================================================================
-  Standard_Boolean IntTools_EdgeFace::IsEqDistance(const gp_Pnt& aP,
-                                                  const BRepAdaptor_Surface& aBAS,
-                                                  const Standard_Real aTol,
-                                                  Standard_Real& aD)
+Standard_Boolean IntTools_EdgeFace::IsEqDistance
+  (const gp_Pnt& aP,
+   const BRepAdaptor_Surface& aBAS,
+   const Standard_Real aTol,
+   Standard_Real& aD)
 {
   Standard_Boolean bRetFlag=Standard_True;
 
@@ -566,9 +560,9 @@ void IntTools_EdgeFace::CheckData()
 //function : PrepareArgsFuncArrays
 //purpose  : Obtain 
 //           myFuncArray and myArgsArray for the interval [ta, tb]
-//=======================================================================              
-  void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
-                                               const Standard_Real tb)
+//=======================================================================  
+void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta,
+                                              const Standard_Real tb)
 {
   IntTools_CArray1OfReal anArgs, aFunc;
   Standard_Integer i, aNb, pri;
@@ -609,14 +603,13 @@ void IntTools_EdgeFace::CheckData()
   AddDerivativePoints(anArgs, aFunc);
 
 }
-
-
 //=======================================================================
 //function : AddDerivativePoints
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::AddDerivativePoints(const IntTools_CArray1OfReal& t,
-                                             const IntTools_CArray1OfReal& f)  
+void IntTools_EdgeFace::AddDerivativePoints
+  (const IntTools_CArray1OfReal& t,
+   const IntTools_CArray1OfReal& f)  
 {
   Standard_Integer i, j, n, k, nn=100;
   Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull;
@@ -647,9 +640,6 @@ void IntTools_EdgeFace::CheckData()
 
   k=n-1;
   for (i=1; i<k; i++) {
-    Standard_Real ti, ti1;
-    ti=t(i);
-    ti1=t(i-1);
     fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1));
     if (fabs(fd(i)) < dEpsNull){
       fd(i)=0.;
@@ -682,16 +672,16 @@ void IntTools_EdgeFace::CheckData()
 
     if (fd1*fd2 < 0.) {
       if (fabs(fd1) < myEpsNull) {
      tr=t1;
      fr=DistanceFunction(tr);//fd1;
+ tr=t1;
+ fr=DistanceFunction(tr);//fd1;
       }
       else if (fabs(fd2) < myEpsNull) {
      tr=t2;
      fr=DistanceFunction(tr);
+ tr=t2;
+ fr=DistanceFunction(tr);
       }
       else {
      tr=FindSimpleRoot(2, t1, t2, fd1);
      fr=DistanceFunction(tr);
+ tr=FindSimpleRoot(2, t1, t2, fd1);
+ fr=DistanceFunction(tr);
       }
       
       aTSeq.Append(tr);
@@ -705,11 +695,11 @@ void IntTools_EdgeFace::CheckData()
     for (i=1; i<=aTSeq.Length(); i++) {
       tr=aTSeq(i);
       for (j=0; j<n; j++) {
      tr1=t(j);
      if (fabs (tr1-tr) < myEpsT) {
-         aTSeq.Remove(i);
-         aFSeq.Remove(i);
      }
+ tr1=t(j);
+ if (fabs (tr1-tr) < myEpsT) {
+   aTSeq.Remove(i);
+   aFSeq.Remove(i);
+ }
       }
     }
     nn=aTSeq.Length();
@@ -755,7 +745,8 @@ void IntTools_EdgeFace::CheckData()
 //function : DerivativeFunction
 //purpose  : 
 //=======================================================================
-  Standard_Real IntTools_EdgeFace::DerivativeFunction(const Standard_Real t2)
+Standard_Real IntTools_EdgeFace::DerivativeFunction
+  (const Standard_Real t2)
 {
   Standard_Real t1, t3, aD1, aD2, aD3;
   Standard_Real dt=1.e-9;
@@ -772,10 +763,11 @@ void IntTools_EdgeFace::CheckData()
 //function : FindSimpleRoot
 //purpose  : [private]
 //=======================================================================
-  Standard_Real IntTools_EdgeFace::FindSimpleRoot (const Standard_Integer IP,
-                                                  const Standard_Real tA,
-                                                  const Standard_Real tB,
-                                                  const Standard_Real fA)
+Standard_Real IntTools_EdgeFace::FindSimpleRoot 
+  (const Standard_Integer IP,
+   const Standard_Real tA,
+   const Standard_Real tB,
+   const Standard_Real fA)
 {
   Standard_Real r, a, b, y, x0, s;
   
@@ -810,9 +802,10 @@ void IntTools_EdgeFace::CheckData()
 //function : FindGoldRoot
 //purpose  : [private]
 //=======================================================================
-  Standard_Real IntTools_EdgeFace::FindGoldRoot (const Standard_Real tA,
-                                                const Standard_Real tB,
-                                                const Standard_Real coeff)
+Standard_Real IntTools_EdgeFace::FindGoldRoot
+  (const Standard_Real tA,
+   const Standard_Real tB,
+   const Standard_Real coeff)
 {
   Standard_Real gs=0.61803399;
   Standard_Real a, b, xp, xl, yp, yl;
@@ -852,10 +845,11 @@ void IntTools_EdgeFace::CheckData()
 //function : MakeType
 //purpose  : 
 //=======================================================================
-  Standard_Integer IntTools_EdgeFace::MakeType(IntTools_CommonPrt&  aCommonPrt)
+Standard_Integer IntTools_EdgeFace::MakeType
+  (IntTools_CommonPrt&  aCommonPrt)
 {
   Standard_Real  af1, al1;
-  Standard_Real dt, df1, df2, tm;
+  Standard_Real  df1, tm;
   Standard_Boolean bAllNullFlag;
   //
   bAllNullFlag=aCommonPrt.AllNullFlag();
@@ -876,72 +870,30 @@ void IntTools_EdgeFace::CheckData()
     if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) &&
        (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria)))
       isWholeRange = Standard_True;
-
+    
     
     if ((df1 > myCriteria * 2.) && isWholeRange) {
       aCommonPrt.SetType(TopAbs_EDGE);
     }
     else {
       if(isWholeRange) {
-       tm = (af1 + al1) * 0.5;
-
-       if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
-         aCommonPrt.SetType(TopAbs_EDGE);
-         return 0;
-       }
+        tm = (af1 + al1) * 0.5;
+        
+        if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) {
+          aCommonPrt.SetType(TopAbs_EDGE);
+          return 0;
+        }
       }
-
+      
       if(!CheckTouch(aCommonPrt, tm)) {
-       tm = (af1 + al1) * 0.5;
+        tm = (af1 + al1) * 0.5;
       }
       aCommonPrt.SetType(TopAbs_VERTEX);
       aCommonPrt.SetVertexParameter1(tm);
       aCommonPrt.SetRange1 (af1, al1);
-    }
-        return 0;
-  }
-  //
-  /*
-  dt=al1-af1;
-  if (dt<1.e-5) {
-    gp_Pnt aPF, aPL;
-    myC.D0(af1, aPF);
-    myC.D0(al1, aPL);
-    df1=aPF.Distance(aPL);
-    if (df1<myCriteria) {
-      //
-      tm=.5*(af1+al1);
-      aCommonPrt.SetType(TopAbs_VERTEX);
-      aCommonPrt.SetVertexParameter1(tm);
-      aCommonPrt.SetRange1 (af1, al1);
-      return 0;
-    }
-  }
-  //
-  IsIntersection (af1, al1);
-  //
-  if (!myParallel) {
-    aCommonPrt.SetType(TopAbs_VERTEX);
-    aCommonPrt.SetVertexParameter1(myPar1);
-    aCommonPrt.SetRange1 (af1, al1);
-  }
-  else {
-    dt=al1-af1;
-    if (dt<1.e-5) {
-      df1=DistanceFunction(af1);
-      df2=DistanceFunction(al1);
-      tm=(df1 < df2) ? af1 : al1;
-      aCommonPrt.SetType(TopAbs_VERTEX);
-      aCommonPrt.SetVertexParameter1(tm);
-      aCommonPrt.SetRange1 (af1, al1);
-    }
-
-    else {
-      aCommonPrt.SetType(TopAbs_EDGE);
     }
   }
-  */
-//  return 0;
+ return 0;
 }
 
 
@@ -949,17 +901,17 @@ void IntTools_EdgeFace::CheckData()
 //function : IsIntersection
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::IsIntersection (const Standard_Real ta, 
-                                         const Standard_Real tb) 
+void IntTools_EdgeFace::IsIntersection (const Standard_Real ta, 
+                                        const Standard_Real tb) 
 {
   IntTools_CArray1OfReal anArgs, aFunc;
-  Standard_Integer i, aNb, pri, aCnt=0;
+  Standard_Integer i, aNb, aCnt=0;
   //
   Standard_Integer aCntIncreasing=1, aCntDecreasing=1;
   Standard_Real t, f, f1;
   //
   // Prepare values of arguments for the interval [ta, tb]
-  pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
+  IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs);
   aNb=anArgs.Length();
   
   aFunc.Resize(aNb);
@@ -977,10 +929,10 @@ void IntTools_EdgeFace::CheckData()
     //
     if (i) {
       if (aFunc(i)>aFunc(i-1)) {
      aCntIncreasing++;
+ aCntIncreasing++;
       }
       if (aFunc(i)<aFunc(i-1)) {
      aCntDecreasing++;
+ aCntDecreasing++;
       }
     }
     //
@@ -996,15 +948,15 @@ void IntTools_EdgeFace::CheckData()
   //
   if (myParallel) {
     if (!(myC.GetType()==GeomAbs_Line 
-         && 
-         myS.GetType()==GeomAbs_Cylinder)) {
+   && 
+   myS.GetType()==GeomAbs_Cylinder)) {
       if (aCntDecreasing==aNb) {
      myPar1=anArgs(aNb-1);
      myParallel=Standard_False;
+ myPar1=anArgs(aNb-1);
+ myParallel=Standard_False;
       }
       if (aCntIncreasing==aNb) {
      myPar1=anArgs(0);
      myParallel=Standard_False;
+ myPar1=anArgs(0);
+ myParallel=Standard_False;
       }
     }
   }
@@ -1016,11 +968,12 @@ void IntTools_EdgeFace::CheckData()
 //function : FindDerivativeRoot
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::FindDerivativeRoot(const IntTools_CArray1OfReal& t,
-                                            const IntTools_CArray1OfReal& f)  
+void IntTools_EdgeFace::FindDerivativeRoot
+  (const IntTools_CArray1OfReal& t,
+   const IntTools_CArray1OfReal& f)  
 {
   Standard_Integer i, n, k;
-  Standard_Real fr, tr;
+  Standard_Real tr;
   IntTools_CArray1OfReal fd;
   TColStd_SequenceOfReal aTSeq, aFSeq;  
   
@@ -1067,7 +1020,7 @@ void IntTools_EdgeFace::CheckData()
     //
     if (fd1*fd2 < 0.) {
       tr=FindSimpleRoot(2, t1, t2, fd1);
-      fr=DistanceFunction(tr);
+      DistanceFunction(tr);
       myPar1=tr;
       myParallel=Standard_False;
       break;
@@ -1075,7 +1028,6 @@ void IntTools_EdgeFace::CheckData()
     
     if (!bF1 && bF2) {
       tr=t2;
-      fr=fd2;
       myPar1=tr;
       myParallel=Standard_False;
       break;
@@ -1083,7 +1035,6 @@ void IntTools_EdgeFace::CheckData()
     
     if (bF1 && !bF2) {
       tr=t1;
-      fr=fd1;
       myPar1=tr;
       myParallel=Standard_False;
       break;
@@ -1095,7 +1046,7 @@ void IntTools_EdgeFace::CheckData()
 //function : RemoveIdenticalRoots 
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::RemoveIdenticalRoots()
+void IntTools_EdgeFace::RemoveIdenticalRoots()
 {
   Standard_Integer aNbRoots, j, k;
 
@@ -1116,8 +1067,8 @@ void IntTools_EdgeFace::CheckData()
 
       aDistance=aPj.Distance(aPk);
       if (aDistance < myCriteria) {
      mySequenceOfRoots.Remove(k);
      aNbRoots=mySequenceOfRoots.Length();
+ mySequenceOfRoots.Remove(k);
+ aNbRoots=mySequenceOfRoots.Length();
       }
     }
   }
@@ -1127,8 +1078,9 @@ void IntTools_EdgeFace::CheckData()
 //function : CheckTouch 
 //purpose  : 
 //=======================================================================
-  Standard_Boolean IntTools_EdgeFace::CheckTouch(const IntTools_CommonPrt& aCP,
-                                                Standard_Real&            aTx) 
+Standard_Boolean IntTools_EdgeFace::CheckTouch
+  (const IntTools_CommonPrt& aCP,
+   Standard_Real&            aTx) 
 {
   Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2;
   Standard_Boolean theflag=Standard_False;
@@ -1157,7 +1109,7 @@ void IntTools_EdgeFace::CheckData()
   
   GeomAdaptor_Curve   TheCurve   (Curve,aTF, aTL);
   GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l); 
-                                
+     
   Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
 
   aDist2 = 1.e100;
@@ -1169,42 +1121,42 @@ void IntTools_EdgeFace::CheckData()
       aNbExt=anExtrema.NbExt();
       
       if(aNbExt > 0) {
      iLower=1;
      for (i=1; i<=aNbExt; i++) {
-         aDist2=anExtrema.SquareDistance(i);
-         if (aDist2 < aMinDist2) {
-           aMinDist2=aDist2;
-           iLower=i;
-         }
      }
      aDist2=anExtrema.SquareDistance(iLower);
      Extrema_POnCurv aPOnC;
      Extrema_POnSurf aPOnS;
      anExtrema.Points(iLower, aPOnC, aPOnS);
      aTx=aPOnC.Parameter();
+ iLower=1;
+ for (i=1; i<=aNbExt; i++) {
+   aDist2=anExtrema.SquareDistance(i);
+   if (aDist2 < aMinDist2) {
+     aMinDist2=aDist2;
+     iLower=i;
+   }
+ }
+ aDist2=anExtrema.SquareDistance(iLower);
+ Extrema_POnCurv aPOnC;
+ Extrema_POnSurf aPOnS;
+ anExtrema.Points(iLower, aPOnC, aPOnS);
+ aTx=aPOnC.Parameter();
       }
       else {
      // modified by NIZHNY-MKK  Thu Jul 21 11:35:32 2005.BEGIN
      IntCurveSurface_HInter anExactIntersector;
+ // modified by NIZHNY-MKK  Thu Jul 21 11:35:32 2005.BEGIN
+ IntCurveSurface_HInter anExactIntersector;
   
      Handle(GeomAdaptor_HCurve) aCurve     = new GeomAdaptor_HCurve(TheCurve);
      Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
-       
      anExactIntersector.Perform(aCurve, aSurface);
+ Handle(GeomAdaptor_HCurve) aCurve     = new GeomAdaptor_HCurve(TheCurve);
+ Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface);
+ anExactIntersector.Perform(aCurve, aSurface);
 
      if(anExactIntersector.IsDone()) {
-         Standard_Integer i = 0;
+ if(anExactIntersector.IsDone()) {
+   Standard_Integer i = 0;
 
-         for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
-           const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
+   for(i = 1; i <= anExactIntersector.NbPoints(); i++) {
+     const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i);
       
-           if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
-             aDist2=0.;
-             aTx = aPoint.W();
-           }
-         }
      }
      // modified by NIZHNY-MKK  Thu Jul 21 11:35:40 2005.END
+     if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) {
+       aDist2=0.;
+       aTx = aPoint.W();
+     }
+   }
+ }
+ // modified by NIZHNY-MKK  Thu Jul 21 11:35:40 2005.END
       }
     }
     else {
@@ -1251,13 +1203,11 @@ void IntTools_EdgeFace::CheckData()
 
   return theflag;
 }
-
-
 //=======================================================================
 //function : Perform
 //purpose  : 
 //=======================================================================
-  void IntTools_EdgeFace::Perform() 
+void IntTools_EdgeFace::Perform() 
 {
   Standard_Integer i, aNb;
   IntTools_CommonPrt aCommonPrt;
@@ -1271,7 +1221,7 @@ void IntTools_EdgeFace::CheckData()
   }
   //
   if (myContext.IsNull()) {
-    myContext=new BOPInt_Context;
+    myContext=new IntTools_Context;
   }
   //
   myIsDone = Standard_False;
@@ -1281,7 +1231,7 @@ void IntTools_EdgeFace::CheckData()
   //
   // Prepare myCriteria
   if (aCurveType==GeomAbs_BSplineCurve||
-       aCurveType==GeomAbs_BezierCurve) {
+      aCurveType==GeomAbs_BezierCurve) {
     //--- 5112
     Standard_Real diff1 = (myTolE/myTolF);
     Standard_Real diff2 = (myTolF/myTolE);
@@ -1294,27 +1244,27 @@ void IntTools_EdgeFace::CheckData()
   else {
     myCriteria=myTolE+myTolF;
   }
-
+  
   myTmin=myRange.First();
   myTmax=myRange.Last();
-
+  
   myS.Initialize (myFace,Standard_True);
-
+  
   if(myContext.IsNull()) {
     myFClass2d.Init(myFace, 1.e-6);
   }
-
+  
   IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF);
   anIntersector.SetBeanParameters(myRange.First(), myRange.Last());
   //
   anIntersector.SetContext(myContext);
   //
   anIntersector.Perform();
-
+  
   if(!anIntersector.IsDone()) {
     return;
   }
-
+  
   for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) {
     const IntTools_Range& aRange = anIntersector.Result().Value(r);
     
@@ -1346,32 +1296,32 @@ void IntTools_EdgeFace::CheckData()
     TopAbs_ShapeEnum aType;
     Standard_Boolean bIsTouch;
     Standard_Real aTx;
-
+    
     aCType=myC.GetType();
     aSType=myS.GetType();
     
     if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) {
       for (i=1; i<=aNb; i++) {
-       IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
-       aType=aCP.Type();
-       if (aType==TopAbs_EDGE) {
-         bIsTouch=CheckTouch (aCP, aTx);
-         if (bIsTouch) {
-           aCP.SetType(TopAbs_VERTEX);
-           aCP.SetVertexParameter1(aTx);
-           aCP.SetRange1 (aTx, aTx);
-         }
-       }
-       if (aType==TopAbs_VERTEX) {
-         bIsTouch=CheckTouchVertex (aCP, aTx);
-         if (bIsTouch) {
-           aCP.SetVertexParameter1(aTx);
-           aCP.SetRange1 (aTx, aTx);
-         }
-       }
+        IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
+        aType=aCP.Type();
+        if (aType==TopAbs_EDGE) {
+          bIsTouch=CheckTouch (aCP, aTx);
+          if (bIsTouch) {
+            aCP.SetType(TopAbs_VERTEX);
+            aCP.SetVertexParameter1(aTx);
+            aCP.SetRange1 (aTx, aTx);
+          }
+        }
+        if (aType==TopAbs_VERTEX) {
+          bIsTouch=CheckTouchVertex (aCP, aTx);
+          if (bIsTouch) {
+            aCP.SetVertexParameter1(aTx);
+            aCP.SetRange1 (aTx, aTx);
+          }
+        }
       }
     }
-
+    
     // Circle\Plane's Common Parts treatement
     
     if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) {
@@ -1379,18 +1329,18 @@ void IntTools_EdgeFace::CheckData()
       bIsCoplanar=IsCoplanar(myC, myS);
       bIsRadius=IsRadius(myC, myS);
       if (!bIsCoplanar && !bIsRadius) {
-       for (i=1; i<=aNb; i++) {
-         IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
-         aType=aCP.Type();
-         if (aType==TopAbs_EDGE) {
-           bIsTouch=CheckTouch (aCP, aTx);
-           if (bIsTouch) {
-             aCP.SetType(TopAbs_VERTEX);
-             aCP.SetVertexParameter1(aTx);
-             aCP.SetRange1 (aTx, aTx);
-           }
-         }
-       }
+        for (i=1; i<=aNb; i++) {
+          IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i);
+          aType=aCP.Type();
+          if (aType==TopAbs_EDGE) {
+            bIsTouch=CheckTouch (aCP, aTx);
+            if (bIsTouch) {
+              aCP.SetType(TopAbs_VERTEX);
+              aCP.SetVertexParameter1(aTx);
+              aCP.SetRange1 (aTx, aTx);
+            }
+          }
+        }
       }
     }
   }
@@ -1411,30 +1361,38 @@ void IntTools_EdgeFace::CheckData()
 //function : CheckTouch 
 //purpose  : 
 //=======================================================================
-  Standard_Boolean IntTools_EdgeFace::CheckTouchVertex (const IntTools_CommonPrt& aCP,
-                                                       Standard_Real& aTx) 
+Standard_Boolean IntTools_EdgeFace::CheckTouchVertex 
+  (const IntTools_CommonPrt& aCP,
+   Standard_Real& aTx) 
 {
-  Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l, af, al,aDist2, aMinDist2, aTm, aDist2New;
-  Standard_Real aEpsT;
+  Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l;
+  Standard_Real aEpsT, af, al,aDist2, aMinDist2, aTm, aDist2New;
   Standard_Boolean theflag=Standard_False;
   Standard_Integer aNbExt, i, iLower ;
-
+  GeomAbs_CurveType aType;
+  //
   aCP.Range1(aTF, aTL);
+  aType=myC.GetType();
+  //
   aEpsT=8.e-5;
+  if (aType==GeomAbs_Line) {
+    aEpsT=9.e-5;
+  }
+  //
   aTm=0.5*(aTF+aTL);
   aDist2=DistanceFunction(aTm);
   aDist2 *= aDist2;
 
   Tol = Precision::PConfusion();
 
-  const Handle(Geom_Curve)&  Curve   =BRep_Tool::Curve  (myC.Edge(), af, al);
+  const Handle(Geom_Curve)&  Curve =BRep_Tool::Curve  (myC.Edge(), af, al);
   const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face());
 
   Surface->Bounds(U1f,U1l,V1f,V1l);
   
   GeomAdaptor_Curve   TheCurve   (Curve,aTF, aTL);
   GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l); 
-                                
+     
   Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol);
    
   if(!anExtrema.IsDone()) {
@@ -1498,7 +1456,7 @@ void IntTools_EdgeFace::CheckData()
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
-                              const BRepAdaptor_Surface& aSurface)
+                             const BRepAdaptor_Surface& aSurface)
 {
   Standard_Boolean bFlag=Standard_False;
 
@@ -1526,7 +1484,7 @@ Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve ,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
-                          const BRepAdaptor_Surface& aSurface)
+                           const BRepAdaptor_Surface& aSurface)
 {
   Standard_Boolean bFlag=Standard_False;
 
@@ -1554,24 +1512,21 @@ Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve ,
 //purpose  : 
 //=======================================================================
 Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret,
-                                 const BRepAdaptor_Curve& aCurve ,
-                                 const BRepAdaptor_Surface& aSurface)
+                                  const BRepAdaptor_Curve& aCurve ,
+                                  const BRepAdaptor_Surface& aSurface)
 {
   Standard_Integer iDiscretNew;
 
   iDiscretNew=iDiscret;
 
-  GeomAbs_CurveType   aCType;
   GeomAbs_SurfaceType aSType;
 
-  aCType=aCurve.GetType();
   aSType=aSurface.GetType();
     
   if (aSType==GeomAbs_Cylinder) {
-   Standard_Real aELength, aRadius, dL, dLR;
+   Standard_Real aELength, aRadius, dLR;
 
    aELength=IntTools::Length(aCurve.Edge());
-   dL=aELength/iDiscret;
    
    gp_Cylinder aCylinder=aSurface.Cylinder();
    aRadius=aCylinder.Radius();