0023511: The function BRepTools::UVBounds provides icorrect result for a face
authornbv <nbv@opencascade.com>
Mon, 19 May 2014 07:57:24 +0000 (11:57 +0400)
committerapn <apn@opencascade.com>
Thu, 22 May 2014 13:55:31 +0000 (17:55 +0400)
Range of changing of some analytic curves is computed by other methods. It allows computing face's boundaries with more precise.
Tolerance was increased to provide successful work of some algorithms.
Functions BRepOffsetAPI_MiddlePath::Build() and ApproxWithPCurves(...) (file IntTools_FaceFace.cxx) were changed according to new result of algorithm's work.
It is possibly for "outboundaried faces" (see bug#23675) to compute incorrect UV-Bounds, when first parameter is more than last. To avoid it, extended control of computed bounds was added.
Function for fail sameparameter fixing was added to HLRAppli_ReflectLines to avoid creation bad shapes after algorithm's work.

In file ShapeFix_ComposeShell.cxx only text formatting was changed.

Some test cases are changed according to their new behavior.
Added test case bugs/moddata_3/bug23511

34 files changed:
src/BOPTools/BOPTools_AlgoTools.cxx
src/BRepOffsetAPI/BRepOffsetAPI_MiddlePath.cxx
src/BRepTools/BRepTools.cxx
src/BndLib/BndLib_Add2dCurve.cdl
src/BndLib/BndLib_Add2dCurve.cxx
src/HLRAppli/HLRAppli_ReflectLines.cxx
src/IntTools/IntTools_FaceFace.cxx
src/ProjLib/ProjLib_Sphere.cxx
src/ShapeFix/ShapeFix_ComposeShell.cxx
src/ShapeFix/ShapeFix_Face.cxx
tests/boolean/bcut_complex/O8
tests/boolean/bsection/R3
tests/bugs/modalg_1/buc60555_3
tests/bugs/modalg_1/bug10160_5
tests/bugs/modalg_2/bug5805_21
tests/bugs/modalg_2/bug5805_22
tests/bugs/modalg_2/bug5805_23
tests/bugs/modalg_2/bug5805_24
tests/bugs/modalg_2/bug5805_45
tests/bugs/modalg_2/bug5805_47
tests/bugs/modalg_2/bug5805_48
tests/bugs/modalg_5/bug23625_1
tests/bugs/modalg_5/bug24208_10
tests/bugs/modalg_5/bug24208_11
tests/bugs/modalg_5/bug24208_14
tests/bugs/modalg_5/bug24208_3
tests/bugs/modalg_5/bug24208_4
tests/bugs/modalg_5/bug24208_7
tests/bugs/moddata_2/bug76
tests/bugs/moddata_2/bug921
tests/bugs/moddata_3/bug23511 [new file with mode: 0644]
tests/de/iges_1/J9
tests/draft/angle/K8
tests/draft/angle/M2

index 61e9c97..ad698ff 100644 (file)
@@ -1843,11 +1843,16 @@ Standard_Boolean FindPointInFace(const TopoDS_Edge& aE,
                                  GeomAPI_ProjectPointOnSurf& aProjPL) 
 {
   Standard_Integer aNbItMax;
-  Standard_Real aDt, aDtMin, aTolE, aTolF, aDist;
+  Standard_Real aDt, aDtMin, aTolE, aTolF, aDist, aDTol, aPM;
   Standard_Boolean bRet;
   gp_Pnt aP1;
   BRepAdaptor_Surface aBAS;
   //
+  aDTol = Precision::Angular();
+  aPM = aP.XYZ().Modulus();
+  if (aPM > 1000.) {
+    aDTol = 5.e-16 * aPM;
+  }
   bRet = Standard_False;
   aTolE = BRep_Tool::Tolerance(aE);
   aTolF = BRep_Tool::Tolerance(aF);
@@ -1910,9 +1915,9 @@ Standard_Boolean FindPointInFace(const TopoDS_Edge& aE,
     //
     gp_Vec aV(aP, aPOut);
     aDB.SetXYZ(aV.XYZ());
-  } while (aDist>Precision::Angular() && --aNbItMax);
+  } while (aDist > aDTol && --aNbItMax);
   //
-  bRet = aDist < Precision::Angular();
+  bRet = aDist < aDTol;
   return bRet;
 }
 //=======================================================================
index c77a8fd..df864df 100644 (file)
@@ -533,6 +533,32 @@ void BRepOffsetAPI_MiddlePath::Build()
       if (myPaths((j<=NbPaths)? j : 1)(i).ShapeType() == TopAbs_EDGE)
         E2 = TopoDS::Edge(myPaths((j<=NbPaths)? j : 1)(i));
       TopoDS_Edge E12 = TopoDS::Edge(SectionsEdges(i)(j-1));
+      //Find the face on which (E1 or E2) and E12 lie
+      TopoDS_Shape E1orE2 = (E1.IsNull())? E2 : E1;
+      if (E1orE2.IsNull()) //both E1 and E2 are vertices =>
+      {
+        EdgeSeq(j-1) = E12; // => proper edge is the edge of previous section between them
+        continue;
+      }
+      const TopTools_ListOfShape& LF = EFmap.FindFromKey(E1orE2);
+      TopoDS_Face theFace;
+      for (itl.Initialize(LF); itl.More(); itl.Next())
+      {
+        const TopoDS_Shape& aFace = itl.Value();
+        const TopTools_ListOfShape& LF2 = EFmap.FindFromKey(E12);
+        TopTools_ListIteratorOfListOfShape itl2(LF2);
+        for (; itl2.More(); itl2.Next())
+        {
+          const TopoDS_Shape& aFace2 = itl2.Value();
+          if (aFace.IsSame(aFace2))
+          {
+            theFace = TopoDS::Face(aFace);
+            break;
+          }
+        }
+        if (!theFace.IsNull())
+          break;
+      }
       
       TopoDS_Vertex PrevVertex = (E1.IsNull())? TopoDS::Vertex(myPaths(j-1)(i))
         : TopExp::LastVertex(E1, Standard_True);
@@ -541,14 +567,19 @@ void BRepOffsetAPI_MiddlePath::Build()
       
       TopoDS_Edge ProperEdge;
       const TopTools_ListOfShape& LE = VEmap.FindFromKey(PrevVertex);
-
+      //Temporary
+      //Standard_Integer LenList = LE.Extent();
+      ///////////
+      TopTools_IndexedMapOfShape EdgesOfTheFace;
+      TopExp::MapShapes(theFace, TopAbs_EDGE, EdgesOfTheFace);
       for (itl.Initialize(LE); itl.More(); itl.Next())
       {
         anEdge = TopoDS::Edge(itl.Value());
         TopExp::Vertices(anEdge, V1, V2);
         if (((V1.IsSame(PrevVertex) && V2.IsSame(CurVertex)) ||
              (V1.IsSame(CurVertex) && V2.IsSame(PrevVertex))) &&
-            !anEdge.IsSame(E1))
+            EdgesOfTheFace.Contains(anEdge) && //this condition is for a section of two edges
+            !anEdge.IsSame(E1)) //the last condition is for torus-like shape
         {
           ProperEdge = anEdge;
           break;
@@ -570,35 +601,6 @@ void BRepOffsetAPI_MiddlePath::Build()
       {
         //Find the face on which E1, E2 and E12 lie
         //ToInsertVertex = Standard_False;
-        const TopoDS_Shape& EE1 = (E1.IsNull())?
-          myPaths(j-1)(i-1) : E1;
-        const TopoDS_Shape& EE2 = (E2.IsNull())?
-          myPaths((j<=NbPaths)? j : 1)(i-1) : E2;
-        const TopTools_ListOfShape& LF = EFmap.FindFromKey(EE1);
-        TopoDS_Face theFace;
-        for (itl.Initialize(LF); itl.More(); itl.Next())
-        {
-          const TopoDS_Shape& aFace = itl.Value();
-          TopExp_Explorer Explo(aFace, TopAbs_EDGE);
-          for (; Explo.More(); Explo.Next())
-          {
-            if (EE2.IsSame(Explo.Current()))
-            {
-              const TopTools_ListOfShape& LFsec = EFmap.FindFromKey(E12);
-              TopTools_ListIteratorOfListOfShape itlsec(LFsec);
-              for (; itlsec.More(); itlsec.Next())
-                if (aFace.IsSame(itlsec.Value()))
-                {
-                  theFace = TopoDS::Face(aFace);
-                  break;
-                }
-              if (!theFace.IsNull())
-                break;
-            }
-          }
-          if (!theFace.IsNull())
-            break;
-        }
         TopTools_ListOfShape ListOneFace;
         ListOneFace.Append(theFace);
 
index ce2b8d7..58e56b1 100644 (file)
@@ -49,6 +49,7 @@
 #include <gp_Vec2d.hxx>
 #include <Standard_ErrorHandler.hxx>
 #include <Standard_Failure.hxx>
+#include <Geom_RectangularTrimmedSurface.hxx>
 
 #include <errno.h>
 
@@ -132,7 +133,6 @@ void  BRepTools::AddUVBounds(const TopoDS_Face& FF, Bnd_Box2d& B)
 //function : AddUVBounds
 //purpose  : 
 //=======================================================================
-
 void  BRepTools::AddUVBounds(const TopoDS_Face& F, 
                              const TopoDS_Wire& W, 
                              Bnd_Box2d& B)
@@ -148,117 +148,62 @@ void  BRepTools::AddUVBounds(const TopoDS_Face& F,
 //function : AddUVBounds
 //purpose  : 
 //=======================================================================
-
-void  BRepTools::AddUVBounds(const TopoDS_Face& F, 
-                             const TopoDS_Edge& E,
-                             Bnd_Box2d& B)
+void BRepTools::AddUVBounds(const TopoDS_Face& aF, 
+                           const TopoDS_Edge& aE,
+                           Bnd_Box2d& aB)
 {
-  Standard_Real pf,pl;
-  Bnd_Box2d Baux; 
-  const Handle(Geom2d_Curve) C = BRep_Tool::CurveOnSurface(E,F,pf,pl);
-  if (C.IsNull()) return;
-  if (pl < pf) { // Petit Blindage
-    Standard_Real aux;
-    aux = pf; pf = pl; pl = aux;
+  Standard_Real aT1, aT2, aXmin, aYmin, aXmax, aYmax;
+  Standard_Real aUmin, aUmax, aVmin, aVmax;
+  Bnd_Box2d aBoxC, aBoxS; 
+  TopLoc_Location aLoc;
+  //
+  const Handle(Geom2d_Curve) aC2D = BRep_Tool::CurveOnSurface(aE, aF, aT1, aT2);
+  if (aC2D.IsNull()) {
+    return;
+  }
+  //
+  BndLib_Add2dCurve::Add(aC2D, aT1, aT2, 0., aBoxC);
+  aBoxC.Get(aXmin, aYmin, aXmax, aYmax);
+  //
+  Handle(Geom_Surface) aS = BRep_Tool::Surface(aF, aLoc);
+  aS->Bounds(aUmin, aUmax, aVmin, aVmax);
+
+  if(aS->DynamicType() == STANDARD_TYPE(Geom_RectangularTrimmedSurface))
+  {
+    const Handle(Geom_RectangularTrimmedSurface) aSt = 
+                Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
+    aS = aSt->BasisSurface();
   }
-  Geom2dAdaptor_Curve PC(C,pf,pl);
-  if (Precision::IsNegativeInfinite(pf) ||
-      Precision::IsPositiveInfinite(pf)) {
-    Geom2dAdaptor_Curve GC(PC);
-    BndLib_Add2dCurve::Add(GC,0.,B);
-    }
-  else {
 
-    // just compute points to get a close box.
-    TopLoc_Location L;
-    Standard_Real Umin,Umax,Vmin,Vmax;
-    const Handle(Geom_Surface)& Surf=BRep_Tool::Surface(F,L);
-    Surf->Bounds(Umin,Umax,Vmin,Vmax);
-    gp_Pnt2d Pa,Pb,Pc;
-
-
-    Standard_Integer i, j, k, nbp = 20;
-    if (PC.GetType() == GeomAbs_Line) nbp = 2;
-    Standard_Integer NbIntC1 = PC.NbIntervals(GeomAbs_C1);
-    if (NbIntC1 > 1)
-      nbp = 10;
-    TColStd_Array1OfReal SharpPoints(1, NbIntC1+1);
-    PC.Intervals(SharpPoints, GeomAbs_C1);
-    TColStd_Array1OfReal Parameters(1, nbp*NbIntC1+1);
-    k = 1;
-    for (i = 1; i <= NbIntC1; i++)
+  //
+  if(!aS->IsUPeriodic())
+  {
+    if((aXmin<aUmin) && (aUmin < aXmax))
     {
-      Standard_Real delta = (SharpPoints(i+1) - SharpPoints(i))/nbp;
-      for (j = 0; j < nbp; j++)
-        Parameters(k++) = SharpPoints(i) + j*delta;
+      aXmin=aUmin;
     }
-    Parameters(nbp*NbIntC1+1) = SharpPoints(NbIntC1+1);
-    
-    gp_Pnt2d P;
-    PC.D0(pf,P);
-    Baux.Add(P);
-
-    Standard_Real du=0.0;
-    Standard_Real dv=0.0;
-
-    Pc=P;
-    for (i = 2; i < Parameters.Upper(); i++) {
-      pf = Parameters(i);
-      PC.D0(pf,P);
-      Baux.Add(P);
-      if(i==2) { Pb=Pc; Pc=P; } 
-      else { 
-        //-- Calcul de la fleche 
-        Pa=Pb; Pb=Pc; Pc=P;     
-        gp_Vec2d PaPc(Pa,Pc);
-//      gp_Lin2d L2d(Pa,PaPc);
-//      Standard_Real up = ElCLib::Parameter(L2d,Pb);
-//      gp_Pnt2d PProj   = ElCLib::Value(up,L2d);
-        gp_Pnt2d PProj(Pa.Coord()+(PaPc.XY()/2.));
-        Standard_Real ddu=Abs(Pb.X()-PProj.X());
-        Standard_Real ddv=Abs(Pb.Y()-PProj.Y());
-        if(ddv>dv) dv=ddv;
-        if(ddu>du) du=ddu;
-      }
-    }
-    PC.D0(pl,P);
-    Baux.Add(P);
-
-    //-- cout<<" du="<<du<<"   dv="<<dv<<endl;
-    Standard_Real u0,u1,v0,v1;
-    Baux.Get(u0,v0,u1,v1);
-    du*=1.5;
-    dv*=1.5;
-    u0-=du; v0-=dv; u1+=du; v1+=dv;
-    if(Surf->IsUPeriodic()) { } 
-    else { 
-      if(u0<=Umin) {  u0=Umin; } 
-      if(u1>=Umax) {  u1=Umax; } 
+    if((aXmin < aUmax) && (aUmax < aXmax))
+    {
+      aXmax=aUmax;
     }
-    if(Surf->IsVPeriodic()) { } 
-    else { 
-      if(v0<=Vmin) {  v0=Vmin; } 
-      if(v1>=Vmax) {  v1=Vmax; }
+  }
+
+  if(!aS->IsVPeriodic())
+  {
+    if((aYmin<aVmin) && (aVmin < aYmax))
+    {
+      aYmin=aVmin;
     }
-    P.SetCoord(u0,v0) ; Baux.Add(P);
-    P.SetCoord(u1,v1) ; Baux.Add(P);
-
-    Bnd_Box2d FinalBox;
-    Standard_Real aXmin, aYmin, aXmax, aYmax;
-    Baux.Get(aXmin, aYmin, aXmax, aYmax);
-    Standard_Real Tol2d = Precision::PConfusion();
-    if (Abs(aXmin - Umin) <= Tol2d)
-      aXmin = Umin;
-    if (Abs(aYmin - Vmin) <= Tol2d)
-      aYmin = Vmin;
-    if (Abs(aXmax - Umax) <= Tol2d)
-      aXmax = Umax;
-    if (Abs(aYmax - Vmax) <= Tol2d)
-      aYmax = Vmax;
-    FinalBox.Update(aXmin, aYmin, aXmax, aYmax);
     
-    B.Add(FinalBox);
+    if((aYmin < aVmax) && (aVmax < aYmax))
+    {
+      aYmax=aVmax;
+    }
   }
+  
+  aBoxS.Update(aXmin, aYmin, aXmax, aYmax);
+  
+  aB.Add(aBoxS);
 }
 
 //=======================================================================
index 3abe784..2b0e3d7 100644 (file)
@@ -20,7 +20,8 @@ class Add2dCurve from BndLib
        -- The 2D curve is defined from a Geom2d curve.
         
 uses Box2d   from Bnd,
-     Curve2d from Adaptor2d
+     Curve2d from Adaptor2d,
+     Curve   from Geom2d
 
 
 is
@@ -89,5 +90,33 @@ is
        -- and P1 and P2 are either two negative infinite real
        -- numbers, or two positive infinite real numbers.      
         
-        
+       Add(myclass;  
+           C  : Curve from Geom2d;
+           Tol: Real  from Standard; 
+           Box: out Box2d from Bnd);  
+        
+       ---Purpose: Adds to the bounding box B the curve C
+        --  B is then enlarged by the tolerance value Tol.
+       -- Note: depending on the type of curve, one of the following
+       -- representations of the curve C is used to include it in the bounding box B:
+       -- -   an exact representation if C is built from a line, a circle or a conic curve,
+       -- -   the poles of the curve if C is built from a Bezier curve or a BSpline curve,
+       -- -   if not, the points of an approximation of the curve C.
+     
+       Add(myclass;  
+           C  : Curve from Geom2d; 
+           U1 : Real from Standard;
+           U2 : Real from Standard;
+           Tol: Real from Standard; 
+           B: out Box2d from Bnd); 
+           
+       ---Purpose: Adds to the bounding box B the part of curve C  
+        --  B is then enlarged by the tolerance value Tol. 
+       --  U1, U2 - the parametric range to comute the bounding box;       
+       -- Note: depending on the type of curve, one of the following
+       -- representations of the curve C is used to include it in the bounding box B:
+       -- -   an exact representation if C is built from a line, a circle or a conic curve,
+       -- -   the poles of the curve if C is built from a Bezier curve or a BSpline curve,
+       -- -   if not, the points of an approximation of the curve C. 
+               
 end Add2dCurve;
index 1d146e9..9fdc064 100644 (file)
 // commercial license or contractual agreement.
 
 #include <BndLib_Add2dCurve.ixx>
-#include <BndLib.hxx>
-#include <ElCLib.hxx>
-#include <GeomAbs_CurveType.hxx>
 
-#include <TColgp_Array1OfPnt2d.hxx>
+
+#include <Precision.hxx>
+
+#include <gp.hxx>
+
+#include <Geom2d_Curve.hxx>
+#include <Geom2d_TrimmedCurve.hxx>
+#include <Geom2d_OffsetCurve.hxx>
+#include <Geom2d_Conic.hxx>
+#include <Geom2d_Circle.hxx>
+#include <Geom2d_Ellipse.hxx>
+#include <Geom2d_Hyperbola.hxx>
+#include <Geom2d_Parabola.hxx>
+#include <Standard_Type.hxx>
+#include <Geom2d_Line.hxx>
 #include <Geom2d_BezierCurve.hxx>
 #include <Geom2d_BSplineCurve.hxx>
-#include <gp_Pnt2d.hxx>
-#include <gp_Lin2d.hxx>
-#include <gp_Circ2d.hxx>
-#include <gp_Elips2d.hxx>
-#include <gp_Parab2d.hxx>
-#include <gp_Hypr2d.hxx>
-#include <Precision.hxx>
+#include <Geom2d_Geometry.hxx>
+
+#include <Geom2dAdaptor_Curve.hxx>
+
+
 
 //=======================================================================
-//function : Add
+//function : BndLib_Box2dCurve
 //purpose  : 
 //=======================================================================
+class BndLib_Box2dCurve  {
+ public:
+  BndLib_Box2dCurve();
+
+  virtual ~BndLib_Box2dCurve();
+
+  void SetCurve(const Handle(Geom2d_Curve)& aC);
+
+  const Handle_Geom2d_Curve& Curve() const;
+
+  void SetRange(const Standard_Real aT1,
+               const Standard_Real aT2);
+
+  void Range(Standard_Real& aT1,
+            Standard_Real& aT2) const;
+
+  const Bnd_Box2d& Box() const;
 
-void BndLib_Add2dCurve::Add(const Adaptor2d_Curve2d& C,
-                           const Standard_Real   Tol,
-                                 Bnd_Box2d&      B ) 
+  void Perform();
+
+  void Clear();
+
+  Standard_Integer ErrorStatus() const;
+  //
+  //-----------------------------
+ protected:
+  void CheckData();
+  void GetInfoBase();
+  void PerformLineConic();
+  void PerformBezier();
+  void PerformBSpline();
+  void PerformOther();
+  void D0(const Standard_Real, gp_Pnt2d&);
+  //
+  void Compute(const Handle(Geom2d_Conic)&,
+              const GeomAbs_CurveType,
+              const Standard_Real,
+              const Standard_Real,
+              Bnd_Box2d& aBox2D);
+  //
+  static
+    Standard_Integer Compute(const Handle(Geom2d_Conic)&,
+                            const GeomAbs_CurveType,
+                            Standard_Real *);
+  static
+    Standard_Boolean IsTypeBase(const Handle(Geom2d_Curve)& ,
+                             GeomAbs_CurveType& );
+  static
+    Standard_Real AdjustToPeriod(const Standard_Real ,
+                                const Standard_Real );
+  //
+  void PerformOnePoint();
+  //-----------------------------
+ protected:
+  Handle_Geom2d_Curve myCurve;
+  Bnd_Box2d myBox;
+  Standard_Integer myErrorStatus;
+  Handle_Geom2d_Curve myCurveBase;
+  Standard_Real myOffsetBase;
+  Standard_Boolean myOffsetFlag;
+  Standard_Real myT1;
+  Standard_Real myT2;
+  GeomAbs_CurveType myTypeBase;
+};
+
+
+//=======================================================================
+//function : 
+//purpose  : 
+//=======================================================================
+BndLib_Box2dCurve::BndLib_Box2dCurve()
 {
-  BndLib_Add2dCurve::Add(C,
-                        C.FirstParameter(),
-                        C.LastParameter (),
-                        Tol,B);
+  Clear();
 }
-
 //=======================================================================
-//function : Add
+//function : ~
 //purpose  : 
 //=======================================================================
-
-void BndLib_Add2dCurve::Add( const Adaptor2d_Curve2d& C,
-                            const Standard_Real U1,
-                            const Standard_Real U2,
-                            const Standard_Real Tol,
-                            Bnd_Box2d& B ) 
+BndLib_Box2dCurve::~BndLib_Box2dCurve()
+{
+}
+//=======================================================================
+//function : Clear
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::Clear()
+{
+  myBox.SetVoid();
+  //
+  myErrorStatus=-1;
+  myTypeBase=GeomAbs_OtherCurve;
+  myOffsetBase=0.;
+  myOffsetFlag=Standard_False;
+}
+//=======================================================================
+//function : SetCurve
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::SetCurve(const Handle(Geom2d_Curve)& aC2D)
+{
+  myCurve=aC2D;
+}
+//=======================================================================
+//function : Curve
+//purpose  : 
+//=======================================================================
+const Handle(Geom2d_Curve)& BndLib_Box2dCurve::Curve()const
+{
+  return myCurve;
+}
+//=======================================================================
+//function : SetRange
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::SetRange(const Standard_Real aT1,
+                                const Standard_Real aT2)
+{
+  myT1=aT1;
+  myT2=aT2;
+}
+//=======================================================================
+//function : tRange
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::Range(Standard_Real& aT1,
+                             Standard_Real& aT2) const
+{
+  aT1=myT1;
+  aT2=myT2;
+}
+//=======================================================================
+//function : ErrorStatus
+//purpose  : 
+//=======================================================================
+Standard_Integer BndLib_Box2dCurve::ErrorStatus()const
+{
+  return myErrorStatus;
+}
+//=======================================================================
+//function : Box
+//purpose  : 
+//=======================================================================
+const Bnd_Box2d& BndLib_Box2dCurve::Box()const
+{
+  return myBox;
+}
+//=======================================================================
+//function : CheckData
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::CheckData()
+{
+  myErrorStatus=0;
+  //
+  if(myCurve.IsNull()) {
+    myErrorStatus=10;
+    return;
+  }
+  //
+  if(myT1>myT2) {
+    myErrorStatus=12; // invalid range
+    return;
+  }
+}
+//=======================================================================
+//function : Perform
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::Perform()
 {
-  GeomAbs_CurveType Type = C.GetType();
+  Clear();
+  // 
+  myErrorStatus=0;
+  //
+  CheckData();
+  if(myErrorStatus) {
+    return;
+  }
+  //
+  if (myT1==myT2) {
+    PerformOnePoint();
+    return;
+  }
+  //
+  GetInfoBase();
+  if(myErrorStatus) {
+    return;
+  }
+  // 
+  if (myTypeBase==GeomAbs_Line ||
+      myTypeBase==GeomAbs_Circle ||
+      myTypeBase==GeomAbs_Ellipse ||
+      myTypeBase==GeomAbs_Parabola ||
+      myTypeBase==GeomAbs_Hyperbola) { // LineConic
+    PerformLineConic();
+  }
+  else if (myTypeBase==GeomAbs_BezierCurve) { // Bezier
+    PerformBezier();
+  }
+  else if (myTypeBase==GeomAbs_BSplineCurve) { //B-Spline
+    PerformBSpline();
+  }
+  else {
+    myErrorStatus=11; // unknown type base
+  }
+}
+//=======================================================================
+//function : PerformOnePoint
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::PerformOnePoint()
+{
+  gp_Pnt2d aP2D;
+  //
+  myCurve->D0(myT1, aP2D);
+  myBox.Add(aP2D);
+}
+//=======================================================================
+//function : PerformBezier
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::PerformBezier()
+{
+  if (myOffsetFlag) {
+    PerformOther();
+    return;
+  }
+  //
+  Standard_Integer i, aNbPoles;
+  Standard_Real aT1, aT2, aTb[2];
+  gp_Pnt2d aP2D;
+  Handle(Geom2d_Geometry) aG;
+  Handle(Geom2d_BezierCurve) aCBz, aCBzSeg;
+  //
+  myErrorStatus=0;
+  Bnd_Box2d& aBox2D=myBox;
+  //
+  aCBz=Handle(Geom2d_BezierCurve)::DownCast(myCurveBase);
+  aT1=aCBz->FirstParameter();
+  aT2=aCBz->LastParameter();
+  //
+  aTb[0]=myT1;
+  if (aTb[0]<aT1) {
+    aTb[0]=aT1;
+  }
+  //
+  aTb[1]=myT2;
+  if (aTb[1]>aT2) {
+    aTb[1]=aT2;
+  }
+  //
+  if (!(aT1==aTb[0] && aT2==aTb[1])) {  
+    aG=aCBz->Copy();
+    //
+    aCBzSeg=Handle(Geom2d_BezierCurve)::DownCast(aG);
+    aCBzSeg->Segment(aTb[0], aTb[1]);
+    aCBz=aCBzSeg;
+  }
+  //
+  aNbPoles=aCBz->NbPoles();
+  for (i=1; i<=aNbPoles; ++i) {
+    aP2D=aCBz->Pole(i);
+    aBox2D.Add(aP2D);
+  }
+}
+//=======================================================================
+//function : PerformBSpline
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::PerformBSpline()
+{
+  if (myOffsetFlag) {
+    PerformOther();
+    return;
+  }
+  //
+  Standard_Integer i, aNbPoles;
+  Standard_Real  aT1, aT2, aTb[2];
+  gp_Pnt2d aP2D;
+  Handle(Geom2d_Geometry) aG;
+  Handle(Geom2d_BSplineCurve) aCBS, aCBSs;
+  //
+  myErrorStatus=0;
+  Bnd_Box2d& aBox2D=myBox;
+  //
+  aCBS=Handle(Geom2d_BSplineCurve)::DownCast(myCurveBase);
+  aT1=aCBS->FirstParameter();
+  aT2=aCBS->LastParameter();
+  //
+  aTb[0]=myT1;
+  if (aTb[0]<aT1) {
+    aTb[0]=aT1;
+  } 
+  aTb[1]=myT2;
+  if (aTb[1]>aT2) {
+    aTb[1]=aT2;
+  }
 
-  switch (Type) {
-    
-  case GeomAbs_Line: 
-    {
-      BndLib::Add(C.Line(),U1,U2,Tol,B);
-      break;
+  if(aTb[1] < aTb[0])
+  {
+    aTb[0]=aT1;
+    aTb[1]=aT2;
+  }
+
+  //
+  if (!(aT1==aTb[0] && aT2==aTb[1])) {
+    aG=aCBS->Copy();
+    //
+    aCBSs=Handle(Geom2d_BSplineCurve)::DownCast(aG);
+    aCBSs->Segment(aTb[0], aTb[1]);
+    aCBS=aCBSs;
+  }
+  //
+  aNbPoles=aCBS->NbPoles();
+  for (i=1; i<=aNbPoles; ++i) {
+    aP2D=aCBS->Pole(i);
+    aBox2D.Add(aP2D);
+  }
+}
+//=======================================================================
+//function : PerformOther
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::PerformOther()
+{
+  Standard_Integer j, aNb;
+  Standard_Real aT, dT;
+  gp_Pnt2d aP2D;
+  //
+  aNb=33;
+  dT=(myT2-myT1)/(aNb-1);
+  //
+  aT=myT1;
+  for (j=0; j<aNb; ++j) {
+    aT=j*dT;
+    myCurve->D0(aT, aP2D);
+    myBox.Add(aP2D);
+  }
+  myCurve->D0(myT2, aP2D);
+  myBox.Add(aP2D);
+}
+//=======================================================================
+//function : D0
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::D0(const Standard_Real aU,
+                           gp_Pnt2d& aP2D)  
+{
+  gp_Vec2d aV1;
+  //
+  myCurveBase->D1(aU, aP2D, aV1);
+  //
+  if (myOffsetFlag) {
+    Standard_Integer aIndex, aMaxDegree;
+    Standard_Real aA, aB, aR, aRes;
+    //
+    aMaxDegree=9;
+    aIndex = 2;
+    aRes=gp::Resolution();
+    //
+    while (aV1.Magnitude() <= aRes && aIndex <= aMaxDegree) {
+      aV1=myCurveBase->DN(aU, aIndex);
+      ++aIndex;
     }
-  case GeomAbs_Circle: 
-    {
-      BndLib::Add(C.Circle(),U1,U2,Tol,B);
-      break;
+    //
+    aA=aV1.Y();
+    aB=-aV1.X();
+    aR=sqrt(aA*aA+aB*aB);
+    if(aR<=aRes) {
+      myErrorStatus=13;
+      return;
+    } 
+    //
+    aR=myOffsetBase/aR;
+    aA=aA*aR;
+    aB=aB*aR;
+    aP2D.SetCoord(aP2D.X()+aA, aP2D.Y()+aB);
+  }
+  //
+}
+//=======================================================================
+//function : GetInfoBase
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::GetInfoBase()
+{
+  Standard_Boolean bIsTypeBase;
+  Standard_Integer  iTrimmed, iOffset;
+  GeomAbs_CurveType aTypeB;
+  Handle(Geom2d_Curve) aC2DB;
+  Handle(Geom2d_TrimmedCurve) aCT2D;
+  Handle(Geom2d_OffsetCurve) aCF2D;
+  //
+  myErrorStatus=0;
+  myTypeBase=GeomAbs_OtherCurve;
+  myOffsetBase=0;
+  //
+  aC2DB=myCurve;
+  bIsTypeBase=IsTypeBase(aC2DB, aTypeB);
+  if (bIsTypeBase) {
+    myTypeBase=aTypeB;
+    myCurveBase=myCurve;
+    return;
+  }
+  //
+  aC2DB=myCurve;
+  while(!bIsTypeBase) {
+    iTrimmed=0;
+    iOffset=0;
+    aCT2D=Handle(Geom2d_TrimmedCurve)::DownCast(aC2DB);
+    if (!aCT2D.IsNull()) {
+      aC2DB=aCT2D->BasisCurve();
+      ++iTrimmed;
     }
-  case GeomAbs_Ellipse: 
-    {
-      BndLib::Add(C.Ellipse(),U1,U2,Tol,B);
-      break;
+    //
+    aCF2D=Handle(Geom2d_OffsetCurve)::DownCast(aC2DB);
+    if (!aCF2D.IsNull()) {
+      Standard_Real aOffset;
+      //
+      aOffset=aCF2D->Offset();
+      myOffsetBase=myOffsetBase+aOffset;
+      myOffsetFlag=Standard_True;
+      //
+      aC2DB=aCF2D->BasisCurve();
+      ++iOffset;
     }
-  case GeomAbs_Hyperbola: 
-    {
-      BndLib::Add(C.Hyperbola(),U1,U2,Tol,B);
+    //
+    if (!(iTrimmed || iOffset)) {
       break;
     }
-  case GeomAbs_Parabola: 
-    {
-      BndLib::Add(C.Parabola(),U1,U2,Tol,B);
-      break;
+    //
+    bIsTypeBase=IsTypeBase(aC2DB, aTypeB);
+    if (bIsTypeBase) {
+      myTypeBase=aTypeB;
+      myCurveBase=aC2DB;
+      return;
     }
-  case GeomAbs_BezierCurve:  
-    {
-      Handle(Geom2d_BezierCurve) Bz = C.Bezier();
-      if(Abs(Bz->FirstParameter() - U1) > Precision::Parametric(Tol)||
-        Abs(Bz->LastParameter()  - U2) > Precision::Parametric(Tol)) {
-
-       Handle(Geom2d_Geometry) G = Bz->Copy();
-       
-       const  Handle(Geom2d_BezierCurve)& Bzaux = (*((Handle(Geom2d_BezierCurve)*)&G));
-         
-       Bzaux->Segment(U1, U2);
-       for (Standard_Integer i = 1; i <= Bzaux->NbPoles(); i++) {
-         B.Add(Bzaux->Pole(i));
-       }
-
+  }
+  //
+  myErrorStatus=11; // unknown type base
+}
+//=======================================================================
+//function : IsTypeBase
+//purpose  : 
+//=======================================================================
+Standard_Boolean BndLib_Box2dCurve::IsTypeBase
+  (const Handle(Geom2d_Curve)& aC2D,
+   GeomAbs_CurveType& aTypeB)
+{
+  Standard_Boolean bRet; 
+  Handle(Standard_Type) aType;
+  //
+  bRet=Standard_True;
+  //
+  aType=aC2D->DynamicType();
+  if (aType==STANDARD_TYPE(Geom2d_Line)) {
+    aTypeB=GeomAbs_Line;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_Circle)) {
+    aTypeB=GeomAbs_Circle;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_Ellipse)) {
+    aTypeB=GeomAbs_Ellipse;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_Parabola)) {
+    aTypeB=GeomAbs_Parabola;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_Hyperbola)) {
+    aTypeB=GeomAbs_Hyperbola;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_BezierCurve)) {
+    aTypeB=GeomAbs_BezierCurve;
+  }
+  else if (aType==STANDARD_TYPE(Geom2d_BSplineCurve)) {
+    aTypeB=GeomAbs_BSplineCurve;
+  }
+  else {
+    aTypeB=GeomAbs_OtherCurve;
+    bRet=!bRet;
+  }
+  return bRet;
+}
+//=======================================================================
+//function : PerformLineConic
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::PerformLineConic()
+{
+  Standard_Integer i, iInf[2];
+  Standard_Real  aTb[2], aTinf;
+  gp_Pnt2d aP2D;
+  //
+  myErrorStatus=0;
+  //
+  Bnd_Box2d& aBox2D=myBox;
+  //
+  aTinf=Precision::Infinite();
+  iInf[0]=0;
+  iInf[1]=0;
+  aTb[0]=myT1;
+  aTb[1]=myT2;
+  //
+  for (i=0; i<2; ++i) {
+    if (Precision::IsNegativeInfinite(aTb[i])) {
+      D0(aTb[i], aP2D);
+      aBox2D.Add(aP2D);
+      ++iInf[0];
+    }
+    else if (Precision::IsPositiveInfinite(aTb[i])) {
+      D0(aTb[i], aP2D);
+      aBox2D.Add(aP2D);
+      ++iInf[1];
+    }
+    else {
+      D0(aTb[i], aP2D);
+      aBox2D.Add(aP2D);
+    }
+  } 
+  //
+  if (myTypeBase==GeomAbs_Line) {
+    return;
+  }
+  //
+  if (iInf[0] && iInf[1]) {
+    return;
+  }
+  //-------------
+  Handle(Geom2d_Conic) aConic2D;
+  //
+  aConic2D=Handle(Geom2d_Conic)::DownCast(myCurveBase);
+  Compute(aConic2D, myTypeBase, aTb[0], aTb[1], aBox2D);
+  
+}
+//=======================================================================
+//function : Compute
+//purpose  : 
+//=======================================================================
+void BndLib_Box2dCurve::Compute(const Handle(Geom2d_Conic)& aConic2D,
+                               const GeomAbs_CurveType aType,
+                               const Standard_Real aT1,
+                               const Standard_Real aT2,
+                               Bnd_Box2d& aBox2D)
+{
+  Standard_Integer i, aNbT;
+  Standard_Real pT[10], aT, aTwoPI, aT1x, aT2x, dT, aT1z, aT2z, aEps;
+  gp_Pnt2d aP2D;
+  //
+  aNbT=Compute(aConic2D, aType, pT);
+  //
+  if (aType==GeomAbs_Parabola ||  aType==GeomAbs_Hyperbola) {
+    for (i=0; i<aNbT; ++i) {
+      aT=pT[i];
+      if (aT>aT1 && aT<aT2) {
+       D0(aT, aP2D);
+       aBox2D.Add(aP2D);
       }
-
-      else {
-
-       for (Standard_Integer i = 1;i<=Bz->NbPoles();i++) {
-         B.Add(Bz->Pole(i));
-       }
+    }
+    return;
+  }
+  //
+  //aType==GeomAbs_Circle ||  aType==GeomAbs_Ellipse
+  aEps=1.e-14;
+  aTwoPI=2.*M_PI;
+  dT=aT2-aT1;
+  //
+  aT1z=aT1;
+  aT2z=aT2;
+  if (aT1z>=aTwoPI) {
+    aT1z=AdjustToPeriod(aT1z, aTwoPI);
+    aT2z=aT1z+dT;
+  }
+  if (fabs(aT1z)<aEps) {
+    aT1z=0.;
+  }
+  //
+  if (fabs(aT2z-aTwoPI)<aEps) {
+    aT2z=aTwoPI;
+  }
+    //
+  for (i=0; i<aNbT; ++i) {
+    aT=pT[i];
+    if (aT>=aT1z && aT<=aT2z) {
+      D0(aT, aP2D);
+      aBox2D.Add(aP2D);
+    }
+  }
+  //
+  aT1x=AdjustToPeriod(aT1, aTwoPI);
+  aT2x=aT1x+dT;
+  //
+  if (aT1x < aTwoPI && aT2x > aTwoPI) {
+    aT1z=aT1x;
+    aT2z=aTwoPI;
+    for (i=0; i<aNbT; ++i) {
+      aT=pT[i];
+      if (aT>=aT1z && aT<=aT2z) {
+       D0(aT, aP2D);
+       aBox2D.Add(aP2D);
       }
-      B.Enlarge(Tol);
-      break;
     }
-  case GeomAbs_BSplineCurve:  
-    {
-      Handle(Geom2d_BSplineCurve) Bs = C.BSpline();
-      if(Abs(Bs->FirstParameter() - U1) > Precision::Parametric(Tol)||
-        Abs(Bs->LastParameter()  - U2) > Precision::Parametric(Tol)) {
-
-
-       Handle(Geom2d_Geometry) G = Bs->Copy();
-       const Handle(Geom2d_BSplineCurve)& Bsaux = (*((Handle(Geom2d_BSplineCurve)*)&G));
-       Standard_Real u1 = U1, u2 = U2;
-       if (Bsaux->IsPeriodic())
-         ElCLib::AdjustPeriodic( Bsaux->FirstParameter(), Bsaux->LastParameter(), Precision::PConfusion(), u1, u2 );
-       else {
-         ////////////////////////////////////////////////
-         //  modified by NIZHNY-EAP Fri Dec  3 14:29:14 1999 ___BEGIN___
-         // To avoid exeption in Segment
-         if(Bsaux->FirstParameter() > U1) u1 = Bsaux->FirstParameter();
-         if(Bsaux->LastParameter()  < U2 ) u2  = Bsaux->LastParameter();
-         //  modified by NIZHNY-EAP Fri Dec  3 14:29:18 1999 ___END___
-       }
-       Bsaux->Segment(u1, u2);
-       for (Standard_Integer i = 1; i <= Bsaux->NbPoles(); i++) {
-         B.Add(Bsaux->Pole(i));
-       }
-
+    //
+    aT1z=0.;
+    aT2z=aT2x-aTwoPI;
+    for (i=0; i<aNbT; ++i) {
+      aT=pT[i];
+      if (aT>=aT1z && aT<=aT2z) {
+       D0(aT, aP2D);
+       aBox2D.Add(aP2D);
       }
-
-      else {
-
-       for (Standard_Integer i = 1;i<=Bs->NbPoles();i++) {
-         B.Add(Bs->Pole(i));
-       }
-
+    }
+  }
+}
+//=======================================================================
+//function : Compute
+//purpose  : 
+//=======================================================================
+Standard_Integer BndLib_Box2dCurve::Compute
+  (const Handle(Geom2d_Conic)& aConic2D,
+   const GeomAbs_CurveType aType,
+   Standard_Real *pT)
+{
+  Standard_Integer iRet, i, j;
+  Standard_Real aCosBt, aSinBt, aCosGm, aSinGm;
+  Standard_Real aLx, aLy;
+  //
+  iRet=0;
+  //
+  const gp_Ax22d& aPos=aConic2D->Position();
+  const gp_XY& aXDir=aPos.XDirection().XY();
+  const gp_XY& aYDir=aPos.YDirection().XY();
+  //
+  aCosBt=aXDir.X();
+  aSinBt=aXDir.Y();
+  aCosGm=aYDir.X();
+  aSinGm=aYDir.Y();
+  //
+  if (aType==GeomAbs_Circle ||  aType==GeomAbs_Ellipse) {
+    Standard_Real aR1 = 0.0, aR2 = 0.0, aTwoPI = M_PI+M_PI;
+    Standard_Real aA11 = 0.0, aA12 = 0.0, aA21 = 0.0, aA22 = 0.0;
+    Standard_Real aBx = 0.0, aBy = 0.0, aB = 0.0, aCosFi = 0.0, aSinFi = 0.0, aFi = 0.0;
+    //
+    if(aType==GeomAbs_Ellipse) {
+      Handle(Geom2d_Ellipse) aEL2D;
+      //
+      aEL2D=Handle(Geom2d_Ellipse)::DownCast(aConic2D);
+      aR1=aEL2D->MajorRadius();
+      aR2=aEL2D->MinorRadius();
+    }
+    else if(aType==GeomAbs_Circle) {
+      Handle(Geom2d_Circle) aCR2D;
+      //
+      aCR2D=Handle(Geom2d_Circle)::DownCast(aConic2D);
+      aR1=aCR2D->Radius();
+      aR2=aR1;
+    }
+    //
+    aA11=-aR1*aCosBt;
+    aA12= aR2*aCosGm;
+    aA21=-aR1*aSinBt;
+    aA22= aR2*aSinGm;
+    //
+    for (i=0; i<2; ++i) {
+      aLx=(!i) ? 0. : 1.;
+      aLy=(!i) ? 1. : 0.;
+      aBx=aLx*aA21-aLy*aA11;
+      aBy=aLx*aA22-aLy*aA12;
+      aB=sqrt(aBx*aBx+aBy*aBy);
+      //
+      aCosFi=aBx/aB;
+      aSinFi=aBy/aB;
+      //
+      aFi=acos(aCosFi);
+      if (aSinFi<0.) {
+       aFi=aTwoPI-aFi;
       }
-      B.Enlarge(Tol);
-      break;
+      //
+      j=2*i;
+      pT[j]=aTwoPI-aFi;
+      pT[j]=AdjustToPeriod(pT[j], aTwoPI);
+      //
+      pT[j+1]=M_PI-aFi;
+      pT[j+1]=AdjustToPeriod(pT[j+1], aTwoPI);
     }
-  default:
-    {
-      Standard_Real N = 33;
-      gp_Pnt2d P;
-      Standard_Real U  = U1;
-      Standard_Real DU = (U2-U1)/(N-1);
-      for (Standard_Integer j=1;j<N;j++) {
-       C.D0(U,P);
-       U+=DU;
-       B.Add(P);
+    iRet=4;
+  }//if (aType==GeomAbs_Ellipse) {
+  //
+  else if (aType==GeomAbs_Parabola) {
+    Standard_Real aFc, aEps;
+    Standard_Real aA1, aA2;
+    Handle(Geom2d_Parabola) aPR2D;
+    //
+    aEps=1.e-12;
+    //
+    aPR2D=Handle(Geom2d_Parabola)::DownCast(aConic2D);
+    aFc=aPR2D->Focal();
+    //
+    j=0;
+    for (i=0; i<2; i++) {
+      aLx=(!i) ? 0. : 1.;
+      aLy=(!i) ? 1. : 0.;
+      //
+      aA2=aLx*aSinBt-aLy*aCosBt;
+      if (fabs(aA2)<aEps) {
+       continue;
+      } 
+      //
+      aA1=aLy*aCosGm-aLx*aSinGm;
+      //
+      pT[j]=2.*aFc*aA1/aA2;
+      ++j;
+    }
+    iRet=j;
+  }// else if (aType==GeomAbs_Parabola) {
+  //
+  else if (aType==GeomAbs_Hyperbola) {
+    Standard_Integer k;
+    Standard_Real aR1, aR2; 
+    Standard_Real aEps, aB1, aB2, aB12, aB22, aZ, aD;
+    Handle(Geom2d_Hyperbola) aHP2D;
+    //
+    aEps=1.e-12;
+    //
+    aHP2D=Handle(Geom2d_Hyperbola)::DownCast(aConic2D);
+    aR1=aHP2D->MajorRadius();
+    aR2=aHP2D->MinorRadius();
+    //
+    j=0;
+    for (i=0; i<2; i++) {
+      aLx=(!i) ? 0. : 1.;
+      aLy=(!i) ? 1. : 0.;
+      //
+      aB1=aR1*(aLx*aSinBt-aLy*aCosBt);
+      aB2=aR2*(aLx*aSinGm-aLy*aCosGm);
+      // 
+      if (fabs(aB1)<aEps) {
+       continue;
+      } 
+      //
+      if (fabs(aB2)<aEps) {
+       pT[j]=0.;
+       ++j;
+      } 
+      else {
+       aB12=aB1*aB1;
+       aB22=aB2*aB2;
+       if (!(aB12>aB22)) {
+         continue;
+       }
+       //
+       aD=sqrt(aB12-aB22);
+       //-------------
+       for (k=-1; k<2; k+=2) {
+         aZ=(aB1+k*aD)/aB2;
+         if (fabs(aZ)<1.) {
+           pT[j]=-log((1.+aZ)/(1.-aZ));
+           ++j;
+         }
+       }
       }
-      C.D0(U2,P);
-      B.Add(P);
-      B.Enlarge(Tol);
     }
+    iRet=j;
+  }// else if (aType==GeomAbs_Hyperbola) {
+  //
+  return iRet;
+}
+//=======================================================================
+//function : AdjustToPeriod
+//purpose  : 
+//=======================================================================
+Standard_Real BndLib_Box2dCurve::AdjustToPeriod(const Standard_Real aT,
+                                               const Standard_Real aPeriod)
+{
+  Standard_Integer k;
+  Standard_Real aTRet;
+  //
+  aTRet=aT;
+  if (aT<0.) {
+    k=1+(Standard_Integer)(-aT/aPeriod);
+    aTRet=aT+k*aPeriod;
   }
+  else if (aT>aPeriod) {
+    k=(Standard_Integer)(aT/aPeriod);
+    aTRet=aT-k*aPeriod;
+  }
+  if (aTRet==aPeriod) {
+    aTRet=0.;
+  }
+  return aTRet;
 }
+//
+// myErrorStatus:
+//
+// -1 - object is just initialized
+// 10 - myCurve is Null
+// 12 - invalid range myT1 >  myT2l
+// 11 - unknown type of base curve
+// 13 - offset curve can not be computed
+//NMTTest
 
+//=======================================================================
+//function : Add
+//purpose  : 
+//=======================================================================
+void BndLib_Add2dCurve::Add(const Adaptor2d_Curve2d& aC,
+                            const Standard_Real aTol,
+                            Bnd_Box2d& aBox2D) 
+{
+  BndLib_Add2dCurve::Add(aC,
+                         aC.FirstParameter(),
+                         aC.LastParameter (),
+                         aTol,
+                         aBox2D);
+}
+//=======================================================================
+//function : Add
+//purpose  : 
+//=======================================================================
+void BndLib_Add2dCurve::Add(const Adaptor2d_Curve2d& aC,
+                            const Standard_Real aU1,
+                            const Standard_Real aU2,
+                            const Standard_Real aTol,
+                            Bnd_Box2d& aBox2D)
+{
+  Adaptor2d_Curve2d *pC=(Adaptor2d_Curve2d *)&aC;
+  Geom2dAdaptor_Curve *pA=dynamic_cast<Geom2dAdaptor_Curve*>(pC);
+  if (!pA) {
+    Standard_Real U, DU;
+    Standard_Integer N, j;
+    gp_Pnt2d P;
+    N = 33;
+    U  = aU1;
+    DU = (aU2-aU1)/(N-1);
+    for (j=1; j<N; j++) {
+      aC.D0(U,P);
+      U+=DU;
+      aBox2D.Add(P);
+    }
+    aC.D0(aU2,P);
+    aBox2D.Add(P);
+    aBox2D.Enlarge(aTol);
+    return;
+  }
+  //
+  const Handle(Geom2d_Curve)& aC2D=pA->Curve();
+  //
+  BndLib_Add2dCurve::Add(aC2D, aU1, aU2, aTol, aBox2D);
+}
+//=======================================================================
+//function : Add
+//purpose  : 
+//=======================================================================
+void BndLib_Add2dCurve::Add(const Handle(Geom2d_Curve)& aC2D,
+                            const Standard_Real aTol,
+                            Bnd_Box2d& aBox2D)
+{
+  Standard_Real aT1, aT2;
+  //
+  aT1=aC2D->FirstParameter();
+  aT2=aC2D->LastParameter();
+  //
+  BndLib_Add2dCurve::Add(aC2D, aT1, aT2, aTol, aBox2D);
+}
 
-
+//=======================================================================
+//function : Add
+//purpose  : 
+//=======================================================================
+void BndLib_Add2dCurve::Add(const Handle(Geom2d_Curve)& aC2D,
+                            const Standard_Real aT1,
+                            const Standard_Real aT2,
+                            const Standard_Real aTol,
+                            Bnd_Box2d& aBox2D)
+{
+  BndLib_Box2dCurve aBC;
+  //
+  aBC.SetCurve(aC2D);
+  aBC.SetRange(aT1, aT2);
+  //
+  aBC.Perform();
+  //
+  const Bnd_Box2d& aBoxC=aBC.Box();
+  aBox2D.Add(aBoxC);
+  aBox2D.Enlarge(aTol);
+}
index fe9deb8..2b34bba 100644 (file)
@@ -19,6 +19,8 @@
 #include <HLRBRep_HLRToShape.hxx>
 #include <BRep_Builder.hxx>
 #include <gp_Ax3.hxx>
+#include <BRepLib.hxx>
+
 
 //=======================================================================
 //function : HLRAppli_ReflectLines
@@ -76,6 +78,8 @@ void HLRAppli_ReflectLines::Perform()
   HLRBRep_HLRToShape aHLRToShape( aHLRAlgo );
 
   myCompound = aHLRToShape.OutLineVCompound3d();
+
+  BRepLib::SameParameter(myCompound,Precision::PConfusion(),Standard_False);
 }
 
 //=======================================================================
index 81bf9ed..eb8ba6f 100644 (file)
@@ -123,79 +123,79 @@ static
 //
 static
   void TolR3d(const TopoDS_Face& ,
-              const TopoDS_Face& ,
-              Standard_Real& );
+             const TopoDS_Face& ,
+             Standard_Real& );
 static 
   Handle(Geom_Curve) MakeBSpline (const Handle(IntPatch_WLine)&,
-                                  const Standard_Integer,
-                                  const Standard_Integer);
+                                 const Standard_Integer,
+                                 const Standard_Integer);
 
 static 
   void Parameters(const Handle(GeomAdaptor_HSurface)&,
-                  const Handle(GeomAdaptor_HSurface)&,
-                  const gp_Pnt&,
-                  Standard_Real&,
-                  Standard_Real&,
-                  Standard_Real&,
-                  Standard_Real&);
+                 const Handle(GeomAdaptor_HSurface)&,
+                 const gp_Pnt&,
+                 Standard_Real&,
+                 Standard_Real&,
+                 Standard_Real&,
+                 Standard_Real&);
 
 static 
   void BuildPCurves (Standard_Real f,Standard_Real l,Standard_Real& Tol,
-                     const Handle (Geom_Surface)& S,
-                     const Handle (Geom_Curve)&   C,
-                     Handle (Geom2d_Curve)& C2d);
+                    const Handle (Geom_Surface)& S,
+                    const Handle (Geom_Curve)&   C,
+                    Handle (Geom2d_Curve)& C2d);
 
 static 
   void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
-                                const Standard_Real theTolerance,
-                                Standard_Real&      theumin,
-                                Standard_Real&      theumax, 
-                                Standard_Real&      thevmin, 
-                                Standard_Real&      thevmax);
+                               const Standard_Real theTolerance,
+                               Standard_Real&      theumin,
+                               Standard_Real&      theumax, 
+                               Standard_Real&      thevmin, 
+                               Standard_Real&      thevmax);
 static
   Standard_Boolean NotUseSurfacesForApprox
           (const TopoDS_Face& aF1,
-           const TopoDS_Face& aF2,
-           const Handle(IntPatch_WLine)& WL,
-           const Standard_Integer ifprm,
-           const Standard_Integer ilprm);
+          const TopoDS_Face& aF2,
+          const Handle(IntPatch_WLine)& WL,
+          const Standard_Integer ifprm,
+          const Standard_Integer ilprm);
 
 static 
   Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine);
 
 static 
   Standard_Real AdjustPeriodic(const Standard_Real theParameter,
-                               const Standard_Real parmin,
-                               const Standard_Real parmax,
-                               const Standard_Real thePeriod,
-                               Standard_Real&      theOffset);
+                              const Standard_Real parmin,
+                              const Standard_Real parmax,
+                              const Standard_Real thePeriod,
+                              Standard_Real&      theOffset);
 
 static 
   Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
-                                            const Standard_Integer                         ideb,
-                                            const Standard_Integer                         ifin,
-                                            const Standard_Boolean                         onFirst);
+                                           const Standard_Integer                         ideb,
+                                           const Standard_Integer                         ifin,
+                                           const Standard_Boolean                         onFirst);
 
 static 
   Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
-                                        const Handle(GeomAdaptor_HSurface)&            theSurface1, 
-                                        const Handle(GeomAdaptor_HSurface)&            theSurface2,
-                                        const TopoDS_Face&                             theFace1,
-                                        const TopoDS_Face&                             theFace2,
-                                        const IntTools_LineConstructor&                theLConstructor,
-                                        const Standard_Boolean                         theAvoidLConstructor,
-                                        IntPatch_SequenceOfLine&                       theNewLines,
-                                        Standard_Real&                                 theReachedTol3d,
+                                       const Handle(GeomAdaptor_HSurface)&            theSurface1, 
+                                       const Handle(GeomAdaptor_HSurface)&            theSurface2,
+                                       const TopoDS_Face&                             theFace1,
+                                       const TopoDS_Face&                             theFace2,
+                                       const IntTools_LineConstructor&                theLConstructor,
+                                       const Standard_Boolean                         theAvoidLConstructor,
+                                       IntPatch_SequenceOfLine&                       theNewLines,
+                                       Standard_Real&                                 theReachedTol3d,
                                         const Handle(BOPInt_Context)& );
 
 static 
   Standard_Boolean ParameterOutOfBoundary(const Standard_Real       theParameter, 
-                                          const Handle(Geom_Curve)& theCurve, 
-                                          const TopoDS_Face&        theFace1, 
-                                          const TopoDS_Face&        theFace2,
-                                          const Standard_Real       theOtherParameter,
-                                          const Standard_Boolean    bIncreasePar,
-                                          Standard_Real&            theNewParameter,
+                                         const Handle(Geom_Curve)& theCurve, 
+                                         const TopoDS_Face&        theFace1, 
+                                         const TopoDS_Face&        theFace2,
+                                         const Standard_Real       theOtherParameter,
+                                         const Standard_Boolean    bIncreasePar,
+                                         Standard_Real&            theNewParameter,
                                           const Handle(BOPInt_Context)& );
 
 static 
@@ -203,99 +203,99 @@ static
 
 static 
   Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
-                                     const Standard_Real theFirstBoundary,
-                                     const Standard_Real theSecondBoundary,
-                                     const Standard_Real theResolution,
-                                     Standard_Boolean&   IsOnFirstBoundary);
+                                    const Standard_Real theFirstBoundary,
+                                    const Standard_Real theSecondBoundary,
+                                    const Standard_Real theResolution,
+                                    Standard_Boolean&   IsOnFirstBoundary);
 static
   Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
-                             const gp_Pnt2d&     theLastPoint,
-                             const Standard_Real theUmin, 
-                             const Standard_Real theUmax,
-                             const Standard_Real theVmin,
-                             const Standard_Real theVmax,
-                             gp_Pnt2d&           theNewPoint);
+                            const gp_Pnt2d&     theLastPoint,
+                            const Standard_Real theUmin, 
+                            const Standard_Real theUmax,
+                            const Standard_Real theVmin,
+                            const Standard_Real theVmax,
+                            gp_Pnt2d&           theNewPoint);
 
 
 static 
   Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
-                                       const Handle(GeomAdaptor_HSurface)&  theSurface2,
-                                       const TopoDS_Face&                   theFace1,
-                                       const TopoDS_Face&                   theFace2,
-                                       Handle(TColgp_HArray1OfPnt2d)&       theResultOnS1,
-                                       Handle(TColgp_HArray1OfPnt2d)&       theResultOnS2,
-                                       Handle(TColStd_HArray1OfReal)&       theResultRadius,
+                                      const Handle(GeomAdaptor_HSurface)&  theSurface2,
+                                      const TopoDS_Face&                   theFace1,
+                                      const TopoDS_Face&                   theFace2,
+                                      Handle(TColgp_HArray1OfPnt2d)&       theResultOnS1,
+                                      Handle(TColgp_HArray1OfPnt2d)&       theResultOnS2,
+                                      Handle(TColStd_HArray1OfReal)&       theResultRadius,
                                        const Handle(BOPInt_Context)& );
 
 static
   Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
-                             const gp_Pnt2d&     theLastPoint,
-                             const Standard_Real theUmin, 
-                             const Standard_Real theUmax,
-                             const Standard_Real theVmin,
-                             const Standard_Real theVmax,
-                             const gp_Pnt2d&     theTanZoneCenter,
-                             const Standard_Real theZoneRadius,
-                             Handle(GeomAdaptor_HSurface) theGASurface,
-                             gp_Pnt2d&           theNewPoint);
+                            const gp_Pnt2d&     theLastPoint,
+                            const Standard_Real theUmin, 
+                            const Standard_Real theUmax,
+                            const Standard_Real theVmin,
+                            const Standard_Real theVmax,
+                            const gp_Pnt2d&     theTanZoneCenter,
+                            const Standard_Real theZoneRadius,
+                            Handle(GeomAdaptor_HSurface) theGASurface,
+                            gp_Pnt2d&           theNewPoint);
 
 static
   Standard_Boolean IsInsideTanZone(const gp_Pnt2d&     thePoint,
-                                   const gp_Pnt2d&     theTanZoneCenter,
-                                   const Standard_Real theZoneRadius,
-                                   Handle(GeomAdaptor_HSurface) theGASurface);
+                                  const gp_Pnt2d&     theTanZoneCenter,
+                                  const Standard_Real theZoneRadius,
+                                  Handle(GeomAdaptor_HSurface) theGASurface);
 
 static
   gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d&     theaNeighbourPoint,
-                             const gp_Pnt2d&     theOriginalPoint,
-                             Handle(GeomAdaptor_HSurface) theGASurface);
+                            const gp_Pnt2d&     theOriginalPoint,
+                            Handle(GeomAdaptor_HSurface) theGASurface);
 static
   Standard_Boolean  ApproxWithPCurves(const gp_Cylinder& theCyl, 
-                                      const gp_Sphere& theSph);
+                                     const gp_Sphere& theSph);
 
 static void  PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1, 
-                           const Handle(GeomAdaptor_HSurface)& theS2, 
-                           const Standard_Real TolAng, 
-                           const Standard_Real TolTang, 
-                           const Standard_Boolean theApprox1,
-                           const Standard_Boolean theApprox2,
+                          const Handle(GeomAdaptor_HSurface)& theS2, 
+                          const Standard_Real TolAng, 
+                          const Standard_Real TolTang, 
+                          const Standard_Boolean theApprox1,
+                          const Standard_Boolean theApprox2,
                            IntTools_SequenceOfCurves& theSeqOfCurve, 
-                           Standard_Boolean& theTangentFaces);
+                          Standard_Boolean& theTangentFaces);
 
 static Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS, 
-                                      const gp_Lin2d& theLin2d, 
-                                      const Standard_Real theTol,
-                                      Standard_Real& theP1, 
-                                      Standard_Real& theP2);
+                                     const gp_Lin2d& theLin2d, 
+                                     const Standard_Real theTol,
+                                     Standard_Real& theP1, 
+                                     Standard_Real& theP2);
 //
 static
   void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
-                        const Handle(GeomAdaptor_HSurface)& aHS2,
-                        Standard_Integer& iDegMin,
-                        Standard_Integer& iNbIter,
-                        Standard_Integer& iDegMax);
+                       const Handle(GeomAdaptor_HSurface)& aHS2,
+                       Standard_Integer& iDegMin,
+                       Standard_Integer& iNbIter,
+                       Standard_Integer& iDegMax);
 
 static
   void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
-                  const Handle(GeomAdaptor_HSurface)& aHS2,
+                 const Handle(GeomAdaptor_HSurface)& aHS2,
                   Standard_Real& aTolTang);
 
 static
   Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
-                             const GeomAbs_SurfaceType aType2);
+                            const GeomAbs_SurfaceType aType2);
 static
   Standard_Integer IndexType(const GeomAbs_SurfaceType aType);
 
 //
 static
   Standard_Real MaxSquareDistance (const Standard_Real aT,
-                                   const Handle(Geom_Curve)& aC3D,
-                                   const Handle(Geom2d_Curve)& aC2D1,
-                                   const Handle(Geom2d_Curve)& aC2D2,
-                                   const Handle(GeomAdaptor_HSurface) myHS1,
-                                   const Handle(GeomAdaptor_HSurface) myHS2,
-                                   const TopoDS_Face& aF1,
-                                   const TopoDS_Face& aF2,
+                                  const Handle(Geom_Curve)& aC3D,
+                                  const Handle(Geom2d_Curve)& aC2D1,
+                                  const Handle(Geom2d_Curve)& aC2D2,
+                                  const Handle(GeomAdaptor_HSurface) myHS1,
+                                  const Handle(GeomAdaptor_HSurface) myHS2,
+                                  const TopoDS_Face& aF1,
+                                  const TopoDS_Face& aF2,
                                    const Handle(BOPInt_Context)& aCtx);
 
 static
@@ -305,15 +305,15 @@ static
 //
 static
   Standard_Real FindMaxSquareDistance (const Standard_Real aA,
-                                       const Standard_Real aB,
-                                       const Standard_Real aEps,
-                                       const Handle(Geom_Curve)& aC3D,
-                                       const Handle(Geom2d_Curve)& aC2D1,
-                                       const Handle(Geom2d_Curve)& aC2D2,
-                                       const Handle(GeomAdaptor_HSurface)& myHS1,
-                                       const Handle(GeomAdaptor_HSurface)& myHS2,
-                                       const TopoDS_Face& aF1,
-                                       const TopoDS_Face& aF2,
+                                      const Standard_Real aB,
+                                      const Standard_Real aEps,
+                                      const Handle(Geom_Curve)& aC3D,
+                                      const Handle(Geom2d_Curve)& aC2D1,
+                                      const Handle(Geom2d_Curve)& aC2D2,
+                                      const Handle(GeomAdaptor_HSurface)& myHS1,
+                                      const Handle(GeomAdaptor_HSurface)& myHS2,
+                                      const TopoDS_Face& aF1,
+                                      const TopoDS_Face& aF2,
                                        const Handle(BOPInt_Context)& aCtx);
 
 //=======================================================================
@@ -420,9 +420,9 @@ Standard_Real IntTools_FaceFace::TolReached2d() const
 //
 // =======================================================================
 void IntTools_FaceFace::SetParameters(const Standard_Boolean ToApproxC3d,
-                                      const Standard_Boolean ToApproxC2dOnS1,
-                                      const Standard_Boolean ToApproxC2dOnS2,
-                                      const Standard_Real ApproximationTolerance) 
+                                     const Standard_Boolean ToApproxC2dOnS1,
+                                     const Standard_Boolean ToApproxC2dOnS2,
+                                     const Standard_Real ApproximationTolerance) 
 {
   myApprox = ToApproxC3d;
   myApprox1 = ToApproxC2dOnS1;
@@ -516,7 +516,7 @@ static Standard_Boolean isTreatAnalityc(const TopoDS_Face& theF1,
 //function : Perform
 //purpose  : intersect surfaces of the faces
 //=======================================================================
-void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
+  void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
                                 const TopoDS_Face& aF2)
 {
   Standard_Boolean RestrictLine = Standard_False, hasCone = Standard_False;
@@ -555,9 +555,9 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       aItP2S.Initialize(myListOfPnts);
       for (; aItP2S.More(); aItP2S.Next())
       {
-        IntSurf_PntOn2S& aP2S=aItP2S.Value();
-        aP2S.Parameters(aU1,aV1,aU2,aV2);
-        aP2S.SetValue(aU2,aV2,aU1,aV1);
+       IntSurf_PntOn2S& aP2S=aItP2S.Value();
+       aP2S.Parameters(aU1,aV1,aU2,aV2);
+       aP2S.SetValue(aU2,aV2,aU1,aV1);
       }
     }
   }
@@ -604,7 +604,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
     //
     Standard_Real TolAng = 1.e-8;
     //
-    PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2,
+    PerformPlanes(myHS1, myHS2, TolAng, TolTang, myApprox1, myApprox2, 
                   mySeqOfCurve, myTangentFaces);
     //
     myIsDone = Standard_True;
@@ -612,26 +612,26 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
     if(!myTangentFaces) {
       const Standard_Integer NbLinPP = mySeqOfCurve.Length();
       if(NbLinPP) {
-        Standard_Real aTolFMax;
-        myTolReached3d = 1.e-7;
-        aTolFMax=Max(aTolF1, aTolF2);
+       Standard_Real aTolFMax;
+       myTolReached3d = 1.e-7;
+       aTolFMax=Max(aTolF1, aTolF2);
         if (aTolFMax>myTolReached3d) {
-          myTolReached3d=aTolFMax;
-        }
+         myTolReached3d=aTolFMax;
+       }
         //
-        myTolReached2d = myTolReached3d;
+       myTolReached2d = myTolReached3d;
 
         if (bReverse) {
-          Handle(Geom2d_Curve) aC2D1, aC2D2;
+         Handle(Geom2d_Curve) aC2D1, aC2D2;
           const Standard_Integer aNbLin = mySeqOfCurve.Length();
           for (Standard_Integer i = 1; i <= aNbLin; ++i) {
-            IntTools_Curve& aIC=mySeqOfCurve(i);
-            aC2D1=aIC.FirstCurve2d();
-            aC2D2=aIC.SecondCurve2d();
-            aIC.SetFirstCurve2d(aC2D2);
-            aIC.SetSecondCurve2d(aC2D1);
-          }
-        }
+           IntTools_Curve& aIC=mySeqOfCurve(i);
+           aC2D1=aIC.FirstCurve2d();
+           aC2D2=aIC.SecondCurve2d();
+           aIC.SetFirstCurve2d(aC2D2);
+           aIC.SetSecondCurve2d(aC2D1);
+         }
+       }
       }
     }
     return;
@@ -708,7 +708,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
   {
     const Standard_Real UVMaxStep = 0.001;
     const Standard_Real Deflection = (hasCone) ? 0.085 : 0.1;
-    myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection);
+  myIntersector.SetTolerances(TolArc, TolTang, UVMaxStep, Deflection); 
   }
   
   if((myHS1->IsUClosed() && !myHS1->IsUPeriodic()) || 
@@ -720,10 +720,10 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
   }
   //
   if((aType1 != GeomAbs_BSplineSurface) &&
-     (aType1 != GeomAbs_BezierSurface) &&
+      (aType1 != GeomAbs_BezierSurface)  &&
      (aType1 != GeomAbs_OtherSurface)  &&
      (aType2 != GeomAbs_BSplineSurface) &&
-     (aType2 != GeomAbs_BezierSurface) &&
+      (aType2 != GeomAbs_BezierSurface)  &&
      (aType2 != GeomAbs_OtherSurface))
   {
     RestrictLine = Standard_True;
@@ -745,13 +745,13 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       aExp.Init(aF, TopAbs_EDGE);
       for(; aExp.More(); aExp.Next())
       {
-        const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
+       const TopoDS_Edge& aE=TopoDS::Edge(aExp.Current());
 
         if(BRep_Tool::Degenerated(aE))
         {
-          RestrictLine = Standard_True;
-          break;
-        }
+         RestrictLine = Standard_True;
+         break;
+       }
       }
     }
   }
@@ -786,11 +786,11 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       const Standard_Integer aNbLin=mySeqOfCurve.Length();
       for (Standard_Integer i=1; i<=aNbLin; ++i)
       {
-        IntTools_Curve& aIC=mySeqOfCurve(i);
-        aC2D1=aIC.FirstCurve2d();
-        aC2D2=aIC.SecondCurve2d();
-        aIC.SetFirstCurve2d(aC2D2);
-        aIC.SetSecondCurve2d(aC2D1);
+       IntTools_Curve& aIC=mySeqOfCurve(i);
+       aC2D1=aIC.FirstCurve2d();
+       aC2D2=aIC.SecondCurve2d();
+       aIC.SetFirstCurve2d(aC2D2);
+       aIC.SetSecondCurve2d(aC2D1);
       }
     }
 
@@ -810,13 +810,13 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       //
       if (!bReverse)
       {
-        aPntOn2Faces.SetP1(aPntOnF1);
-        aPntOn2Faces.SetP2(aPntOnF2);
+       aPntOn2Faces.SetP1(aPntOnF1);
+       aPntOn2Faces.SetP2(aPntOnF2);
       }
       else
       {
-        aPntOn2Faces.SetP2(aPntOnF1);
-        aPntOn2Faces.SetP1(aPntOnF2);
+       aPntOn2Faces.SetP2(aPntOnF1);
+       aPntOn2Faces.SetP1(aPntOnF2);
       }
 
       myPnts.Append(aPntOn2Faces);
@@ -855,20 +855,20 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       aTL1=aIL1->ArcType();
       aTL2=aIL2->ArcType();
       if (aTL1==IntPatch_Lin && aTL2==IntPatch_Lin) {
-        Standard_Real aD, aDTresh, dTol;
-        gp_Lin aL1, aL2;
-        //
-        dTol=1.e-8;
-        aDTresh=1.5e-6;
-        //
-        aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
-        aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
-        aD=aL1.Distance(aL2);
-        aD=0.5*aD;
-        if (aD<aDTresh) {
-          myTolReached3d=aD+dTol;
-        }
-        return;
+       Standard_Real aD, aDTresh, dTol;
+       gp_Lin aL1, aL2;
+       //
+       dTol=1.e-8;
+       aDTresh=1.5e-6;
+       //
+       aL1=Handle(IntPatch_GLine)::DownCast(aIL1)->Line();
+       aL2=Handle(IntPatch_GLine)::DownCast(aIL2)->Line();
+       aD=aL1.Distance(aL2);
+       aD=0.5*aD;
+       if (aD<aDTresh) {
+         myTolReached3d=aD+dTol;
+       }
+       return;
       }
     }
     //ZZ
@@ -881,34 +881,34 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       aNbLin=mySeqOfCurve.Length();
       //
       for (i=1; i<=aNbLin; ++i) {
-        const IntTools_Curve& aIC=mySeqOfCurve(i);
-        const Handle(Geom_Curve)& aC3D=aIC.Curve();
-        const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
-        const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
-        //
-        if (aC3D.IsNull()) {
-          continue;
-        }
-        const Handle(Geom_BSplineCurve)& aBC=
-          Handle(Geom_BSplineCurve)::DownCast(aC3D);
-        if (aBC.IsNull()) {
-          continue;
-        }
-        //
-        aT1=aBC->FirstParameter();
-        aT2=aBC->LastParameter();
-        //
-        aEps=0.01*(aT2-aT1);
-        dT=(aT2-aT1)/aNbP;
-        for (j=1; j<aNbP; ++j) {
-          aT11=aT1+j*dT;
-          aT12=aT11+dT;
-          aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
-                                    myHS1, myHS2, myFace1, myFace2, myContext);
-          if (aD2>aD2Max) {
-            aD2Max=aD2;
-          }
-        }
+       const IntTools_Curve& aIC=mySeqOfCurve(i);
+       const Handle(Geom_Curve)& aC3D=aIC.Curve();
+       const Handle(Geom2d_Curve)& aC2D1=aIC.FirstCurve2d();
+       const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
+       //
+       if (aC3D.IsNull()) {
+         continue;
+       }
+       const Handle(Geom_BSplineCurve)& aBC=
+         Handle(Geom_BSplineCurve)::DownCast(aC3D);
+       if (aBC.IsNull()) {
+         continue;
+       }
+       //
+       aT1=aBC->FirstParameter();
+       aT2=aBC->LastParameter();
+       //
+       aEps=0.01*(aT2-aT1);
+       dT=(aT2-aT1)/aNbP;
+       for (j=1; j<aNbP; ++j) {
+         aT11=aT1+j*dT;
+         aT12=aT11+dT;
+         aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
+                                   myHS1, myHS2, myFace1, myFace2, myContext);
+         if (aD2>aD2Max) {
+           aD2Max=aD2;
+         }
+       }
       }//for (i=1; i<=aNbLin; ++i) {
       //
       myTolReached3d=sqrt(aD2Max);
@@ -932,40 +932,40 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
   //t
   //IFV Bug OCC20297 
   else if((aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) ||
-          (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
+         (aType2 == GeomAbs_Cylinder && aType1 == GeomAbs_Plane)) {
     if(aNbLin == 1) {
       const Handle(IntPatch_Line)& aIL1 = myIntersector.Line(1);
       if(aIL1->ArcType() == IntPatch_Circle) {
-        gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
-        gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
-        gp_XYZ aPlDir;
-        gp_Pln aPln;
-        if(aType1 == GeomAbs_Plane) {
-          aPln = myHS1->Surface().Plane();
-        }
-        else {
-          aPln = myHS2->Surface().Plane();
-        }
-        aPlDir = aPln.Axis().Direction().XYZ();
-        Standard_Real cs = aCirDir*aPlDir;
-        if(cs < 0.) aPlDir.Reverse();
-        Standard_Real eps = 1.e-14;
-        if(!aPlDir.IsEqual(aCirDir, eps)) {
-          Standard_Integer aNbP = 11;
-          Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
-          for(t = 0.; t < 2.*M_PI; t += dt) {
-            Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir)); 
-            if(myTolReached3d < d) myTolReached3d = d;
-          }
-          myTolReached3d *= 1.1;
-        }
+       gp_Circ aCir = Handle(IntPatch_GLine)::DownCast(aIL1)->Circle();
+       gp_XYZ aCirDir = aCir.Axis().Direction().XYZ();
+       gp_XYZ aPlDir;
+       gp_Pln aPln;
+       if(aType1 == GeomAbs_Plane) {
+         aPln = myHS1->Surface().Plane();
+       }
+       else {
+         aPln = myHS2->Surface().Plane();
+       }
+       aPlDir = aPln.Axis().Direction().XYZ();
+       Standard_Real cs = aCirDir*aPlDir;
+       if(cs < 0.) aPlDir.Reverse();
+       Standard_Real eps = 1.e-14;
+       if(!aPlDir.IsEqual(aCirDir, eps)) {
+         Standard_Integer aNbP = 11;
+         Standard_Real dt = 2.*M_PI / (aNbP - 1), t;
+         for(t = 0.; t < 2.*M_PI; t += dt) {
+           Standard_Real d = aPln.Distance(ElCLib::Value(t, aCir)); 
+           if(myTolReached3d < d) myTolReached3d = d;
+         }
+         myTolReached3d *= 1.1;
+       }
       } //aIL1->ArcType() == IntPatch_Circle
     } //aNbLin == 1
   } // aType1 == GeomAbs_Cylinder && aType2 == GeomAbs_Plane) 
   //End IFV Bug OCC20297
   //
   else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
-           (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
+          (aType2==GeomAbs_Plane && aType1==GeomAbs_Torus)) {
     aNbLin=mySeqOfCurve.Length();
     if (aNbLin!=1) {
       return;
@@ -998,7 +998,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
     for (i=0; i<aNbP; ++i) {
       aT=aT1+i*dT;
       if (i==aNbP-1) {
-        aT=aT2;
+       aT=aT2;
       }
       //
       aC3D->D0(aT, aP);
@@ -1007,14 +1007,14 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       aPP=ElSLib::Value(aUP, aVP, aPln);
       aDP=aP.SquareDistance(aPP);
       if (aDP>aDmax) {
-        aDmax=aDP;
+       aDmax=aDP;
       }
       //
       ElSLib::Parameters(aTorus, aP, aUT, aVT);
       aPT=ElSLib::Value(aUT, aVT, aTorus);
       aDT=aP.SquareDistance(aPT);
       if (aDT>aDmax) {
-        aDmax=aDT;
+       aDmax=aDT;
       }
     }
     //
@@ -1025,7 +1025,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
   }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Torus) ||
   //
   else if ((aType1==GeomAbs_SurfaceOfRevolution && aType2==GeomAbs_Cylinder) ||
-           (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
+          (aType2==GeomAbs_SurfaceOfRevolution && aType1==GeomAbs_Cylinder)) {
     Standard_Integer j, aNbP;
     Standard_Real aT, aT1, aT2, dT, aD2max, aD2;
     //
@@ -1040,12 +1040,12 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
       //
       if (aC3D.IsNull()) {
-        continue;
+       continue;
       }
       const Handle(Geom_BSplineCurve)& aBC=
-        Handle(Geom_BSplineCurve)::DownCast(aC3D);
+       Handle(Geom_BSplineCurve)::DownCast(aC3D);
       if (aBC.IsNull()) {
-        return;
+       return;
       }
       //
       aT1=aBC->FirstParameter();
@@ -1053,16 +1053,16 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       //
       dT=(aT2-aT1)/(aNbP-1);
       for (j=0; j<aNbP; ++j) {
-        aT=aT1+j*dT;
-        if (j==aNbP-1) {
-          aT=aT2;
-        }
-        //
-        aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
-                              myHS1, myHS2, myFace1, myFace2, myContext);
-        if (aD2>aD2max) {
-          aD2max=aD2;
-        }
+       aT=aT1+j*dT;
+       if (j==aNbP-1) {
+         aT=aT2;
+       }
+       //
+       aD2=MaxSquareDistance(aT, aC3D, aC2D1, aC2D2,
+                             myHS1, myHS2, myFace1, myFace2, myContext);
+       if (aD2>aD2max) {
+         aD2max=aD2;
+       }
       }//for (j=0; j<aNbP; ++j) {
      
     }//for (i=1; i<=aNbLin; ++i) {
@@ -1073,7 +1073,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
     }
   }//if((aType1==GeomAbs_SurfaceOfRevolution ...
   else if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Sphere) ||
-           (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
+          (aType2==GeomAbs_Plane && aType1==GeomAbs_Sphere)) {
     Standard_Integer  j, aNbP;
     Standard_Real aT1, aT2, dT, aD2max, aD2, aEps, aT11, aT12;
     //
@@ -1088,37 +1088,37 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       const Handle(Geom2d_Curve)& aC2D2=aIC.SecondCurve2d();
       //
       const Handle(Geom2d_BSplineCurve)& aBC2D1=
-        Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
+       Handle(Geom2d_BSplineCurve)::DownCast(aC2D1);
       const Handle(Geom2d_BSplineCurve)& aBC2D2=
-        Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
+       Handle(Geom2d_BSplineCurve)::DownCast(aC2D2);
       //
       if (aBC2D1.IsNull() && aBC2D2.IsNull()) {
-        return;
+       return;
       }
       //
       if (!aBC2D1.IsNull()) {
-        aT1=aBC2D1->FirstParameter();
-        aT2=aBC2D1->LastParameter();
+       aT1=aBC2D1->FirstParameter();
+       aT2=aBC2D1->LastParameter();
       }
       else {
-        aT1=aBC2D2->FirstParameter();
-        aT2=aBC2D2->LastParameter();
+       aT1=aBC2D2->FirstParameter();
+       aT2=aBC2D2->LastParameter();
       }
       //
       aEps=0.01*(aT2-aT1);
       dT=(aT2-aT1)/aNbP;
       for (j=0; j<aNbP; ++j) {
-        aT11=aT1+j*dT;
-        aT12=aT11+dT;
-        if (j==aNbP-1) {
-          aT12=aT2;
-        }
-        //
-        aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
-                                  myHS1, myHS2, myFace1, myFace2, myContext);
-        if (aD2>aD2max) {
-          aD2max=aD2;
-        }
+       aT11=aT1+j*dT;
+       aT12=aT11+dT;
+       if (j==aNbP-1) {
+         aT12=aT2;
+       }
+       //
+       aD2=FindMaxSquareDistance(aT11, aT12, aEps, aC3D, aC2D1, aC2D2,
+                                 myHS1, myHS2, myFace1, myFace2, myContext);
+       if (aD2>aD2max) {
+         aD2max=aD2;
+       }
       }//for (j=0; j<aNbP; ++j) {
      
     }//for (i=1; i<=aNbLin; ++i) {
@@ -1144,7 +1144,7 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
       //
       if (aC3D.IsNull()) {
         continue;
-      }
+}
       const Handle(Geom_BSplineCurve)& aBC=
         Handle(Geom_BSplineCurve)::DownCast(aC3D);
       if (aBC.IsNull()) {
@@ -1175,8 +1175,8 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
 //purpose  : 
 //=======================================================================
   void IntTools_FaceFace::MakeCurve(const Standard_Integer Index,
-                                    const Handle(Adaptor3d_TopolTool)& dom1,
-                                    const Handle(Adaptor3d_TopolTool)& dom2) 
+                                   const Handle(Adaptor3d_TopolTool)& dom1,
+                                   const Handle(Adaptor3d_TopolTool)& dom2) 
 {
   Standard_Boolean bDone, rejectSurface, reApprox, bAvoidLineConstructor;
   Standard_Boolean ok, bPCurvesOk;
@@ -1194,9 +1194,9 @@ void IntTools_FaceFace::Perform(const TopoDS_Face& aF1,
   reApprox = Standard_False;
   //
   bPCurvesOk = Standard_True;
-
-reapprox:;
-
+ reapprox:;
+  
   Tolpc = myTolApprox;
   bAvoidLineConstructor = Standard_False;
   L = myIntersector.Line(Index);
@@ -1246,29 +1246,29 @@ reapprox:;
     }
   }
   // Do the Curve
-
-
+  
+  
   typl=L->ArcType();
   switch (typl) {
-    //########################################  
-    // Line, Parabola, Hyperbola
-    //########################################  
+  //########################################  
+  // Line, Parabola, Hyperbola
+  //########################################  
   case IntPatch_Lin:
   case IntPatch_Parabola: 
   case IntPatch_Hyperbola: {
     if (typl == IntPatch_Lin) {
       newc = 
-        new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
+       new Geom_Line (Handle(IntPatch_GLine)::DownCast(L)->Line());
     }
 
     else if (typl == IntPatch_Parabola) {
       newc = 
-        new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
+       new Geom_Parabola(Handle(IntPatch_GLine)::DownCast(L)->Parabola());
     }
-
+    
     else if (typl == IntPatch_Hyperbola) {
       newc = 
-        new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
+       new Geom_Hyperbola (Handle(IntPatch_GLine)::DownCast(L)->Hyperbola());
     }
     //
     // myTolReached3d
@@ -1279,75 +1279,75 @@ reapprox:;
     aNbParts=myLConstruct.NbParts();
     for (i=1; i<=aNbParts; i++) {
       myLConstruct.Part(i, fprm, lprm);
-
+      
       if (!Precision::IsNegativeInfinite(fprm) && 
-          !Precision::IsPositiveInfinite(lprm)) {
-        //
-        IntTools_Curve aCurve;
-        //
-        Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
-        aCurve.SetCurve(aCT3D);
-        if (typl == IntPatch_Parabola) {
-          Standard_Real aTolF1, aTolF2, aTolBase;
-
-          aTolF1 = BRep_Tool::Tolerance(myFace1);
-          aTolF2 = BRep_Tool::Tolerance(myFace2);
-          aTolBase=aTolF1+aTolF2;
-          myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
-        }
-        //
-        aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
-        if(myApprox1) { 
-          Handle (Geom2d_Curve) C2d;
-          BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
-          if(Tolpc>myTolReached2d || myTolReached2d==0.) { 
-            myTolReached2d=Tolpc;
-          }
-          //            
-          aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
-        }
-        else { 
-          Handle(Geom2d_BSplineCurve) H1;
-          //
-          aCurve.SetFirstCurve2d(H1);
-        }
-
-        if(myApprox2) { 
-          Handle (Geom2d_Curve) C2d;
-          BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
-          if(Tolpc>myTolReached2d || myTolReached2d==0.) { 
-            myTolReached2d=Tolpc;
-          }
-          //
-          aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
-        }
-        else { 
-          Handle(Geom2d_BSplineCurve) H1;
-          //
-          aCurve.SetSecondCurve2d(H1);
-        }
-        mySeqOfCurve.Append(aCurve);
+         !Precision::IsPositiveInfinite(lprm)) {
+       //
+       IntTools_Curve aCurve;
+       //
+       Handle(Geom_TrimmedCurve) aCT3D=new Geom_TrimmedCurve(newc, fprm, lprm);
+       aCurve.SetCurve(aCT3D);
+       if (typl == IntPatch_Parabola) {
+         Standard_Real aTolF1, aTolF2, aTolBase;
+         
+         aTolF1 = BRep_Tool::Tolerance(myFace1);
+         aTolF2 = BRep_Tool::Tolerance(myFace2);
+         aTolBase=aTolF1+aTolF2;
+         myTolReached3d=IntTools_Tools::CurveTolerance(aCT3D, aTolBase);
+       }
+       //
+       aCurve.SetCurve(new Geom_TrimmedCurve(newc, fprm, lprm));
+       if(myApprox1) { 
+         Handle (Geom2d_Curve) C2d;
+         BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
+         if(Tolpc>myTolReached2d || myTolReached2d==0.) { 
+           myTolReached2d=Tolpc;
+         }
+           //     
+           aCurve.SetFirstCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
+         }
+         else { 
+           Handle(Geom2d_BSplineCurve) H1;
+           //
+           aCurve.SetFirstCurve2d(H1);
+         }
+       
+       if(myApprox2) { 
+         Handle (Geom2d_Curve) C2d;
+         BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
+         if(Tolpc>myTolReached2d || myTolReached2d==0.) { 
+           myTolReached2d=Tolpc;
+         }
+         //
+         aCurve.SetSecondCurve2d(new Geom2d_TrimmedCurve(C2d,fprm,lprm));
+         }
+       else { 
+         Handle(Geom2d_BSplineCurve) H1;
+         //
+         aCurve.SetSecondCurve2d(H1);
+       }
+       mySeqOfCurve.Append(aCurve);
       } // end of if (!Precision::IsNegativeInfinite(fprm) &&  !Precision::IsPositiveInfinite(lprm))
       else {
-        //  on regarde si on garde
-        //
-        Standard_Boolean bFNIt, bLPIt;
-        Standard_Real aTestPrm, dT=100.;
-
-        bFNIt=Precision::IsNegativeInfinite(fprm);
-        bLPIt=Precision::IsPositiveInfinite(lprm);
-
-        aTestPrm=0.;
-
-        if (bFNIt && !bLPIt) {
-          aTestPrm=lprm-dT;
-        }
-        else if (!bFNIt && bLPIt) {
-          aTestPrm=fprm+dT;
-        }
-
-        gp_Pnt ptref(newc->Value(aTestPrm));
-        //
+       //  on regarde si on garde
+       //
+       Standard_Boolean bFNIt, bLPIt;
+       Standard_Real aTestPrm, dT=100.;
+
+       bFNIt=Precision::IsNegativeInfinite(fprm);
+       bLPIt=Precision::IsPositiveInfinite(lprm);
+       
+       aTestPrm=0.;
+       
+       if (bFNIt && !bLPIt) {
+         aTestPrm=lprm-dT;
+       }
+       else if (!bFNIt && bLPIt) {
+         aTestPrm=fprm+dT;
+       }
+       
+       gp_Pnt ptref(newc->Value(aTestPrm));
+       //
         GeomAbs_SurfaceType typS1 = myHS1->GetType();
         GeomAbs_SurfaceType typS2 = myHS2->GetType();
         if( typS1 == GeomAbs_SurfaceOfExtrusion ||
@@ -1362,36 +1362,36 @@ reapprox:;
           continue;
         }
 
-        Standard_Real u1, v1, u2, v2, Tol;
-
-        Tol = Precision::Confusion();
-        Parameters(myHS1, myHS2, ptref,  u1, v1, u2, v2);
-        ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
-        if(ok) { 
-          ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); 
-        }
-        if (ok) {
-          Handle(Geom2d_BSplineCurve) H1;
-          mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
-        }
+       Standard_Real u1, v1, u2, v2, Tol;
+       
+       Tol = Precision::Confusion();
+       Parameters(myHS1, myHS2, ptref,  u1, v1, u2, v2);
+       ok = (dom1->Classify(gp_Pnt2d(u1, v1), Tol) != TopAbs_OUT);
+       if(ok) { 
+         ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT); 
+       }
+       if (ok) {
+         Handle(Geom2d_BSplineCurve) H1;
+         mySeqOfCurve.Append(IntTools_Curve(newc, H1, H1));
+       }
       }
     }// end of for (i=1; i<=myLConstruct.NbParts(); i++)
   }// case IntPatch_Lin:  case IntPatch_Parabola:  case IntPatch_Hyperbola:
-  break;
+    break;
 
-    //########################################  
-    // Circle and Ellipse
-    //########################################  
+  //########################################  
+  // Circle and Ellipse
+  //########################################  
   case IntPatch_Circle: 
   case IntPatch_Ellipse: {
 
     if (typl == IntPatch_Circle) {
       newc = new Geom_Circle
-        (Handle(IntPatch_GLine)::DownCast(L)->Circle());
+       (Handle(IntPatch_GLine)::DownCast(L)->Circle());
     }
     else { //IntPatch_Ellipse
       newc = new Geom_Ellipse
-        (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
+       (Handle(IntPatch_GLine)::DownCast(L)->Ellipse());
     }
     //
     // myTolReached3d
@@ -1401,7 +1401,7 @@ reapprox:;
     //
     Standard_Real aPeriod, aNul;
     TColStd_SequenceOfReal aSeqFprm,  aSeqLprm;
-
+    
     aNul=0.;
     aPeriod=M_PI+M_PI;
 
@@ -1409,62 +1409,62 @@ reapprox:;
       myLConstruct.Part(i, fprm, lprm);
 
       if (fprm < aNul && lprm > aNul) {
-        // interval that goes through 0. is divided on two intervals;
-        while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
-        while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
-        //
-        if((aPeriod - fprm) > Tolpc) {
-          aSeqFprm.Append(fprm);
-          aSeqLprm.Append(aPeriod);
-        }
-        else {
-          gp_Pnt P1 = newc->Value(fprm);
-          gp_Pnt P2 = newc->Value(aPeriod);
-          Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
-          aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
-
-          if(P1.Distance(P2) > aTolDist) {
-            Standard_Real anewpar = fprm;
+       // interval that goes through 0. is divided on two intervals;
+       while (fprm<aNul || fprm>aPeriod) fprm=fprm+aPeriod;
+       while (lprm<aNul || lprm>aPeriod) lprm=lprm+aPeriod;
+       //
+       if((aPeriod - fprm) > Tolpc) {
+         aSeqFprm.Append(fprm);
+         aSeqLprm.Append(aPeriod);
+       }
+       else {
+         gp_Pnt P1 = newc->Value(fprm);
+         gp_Pnt P2 = newc->Value(aPeriod);
+         Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
+         aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
+
+         if(P1.Distance(P2) > aTolDist) {
+           Standard_Real anewpar = fprm;
 
             if(ParameterOutOfBoundary(fprm, newc, myFace1, myFace2, 
                                       lprm, Standard_False, anewpar, myContext)) {
-              fprm = anewpar;
-            }
-            aSeqFprm.Append(fprm);
-            aSeqLprm.Append(aPeriod);
-          }
-        }
-
-        //
-        if((lprm - aNul) > Tolpc) {
-          aSeqFprm.Append(aNul);
-          aSeqLprm.Append(lprm);
-        }
-        else {
-          gp_Pnt P1 = newc->Value(aNul);
-          gp_Pnt P2 = newc->Value(lprm);
-          Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
-          aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
-
-          if(P1.Distance(P2) > aTolDist) {
-            Standard_Real anewpar = lprm;
+             fprm = anewpar;
+           }
+           aSeqFprm.Append(fprm);
+           aSeqLprm.Append(aPeriod);
+         }
+       }
+
+       //
+       if((lprm - aNul) > Tolpc) {
+         aSeqFprm.Append(aNul);
+         aSeqLprm.Append(lprm);
+       }
+       else {
+         gp_Pnt P1 = newc->Value(aNul);
+         gp_Pnt P2 = newc->Value(lprm);
+         Standard_Real aTolDist = BRep_Tool::Tolerance(myFace1) + BRep_Tool::Tolerance(myFace2);
+         aTolDist = (myTolReached3d > aTolDist) ? myTolReached3d : aTolDist;
+
+         if(P1.Distance(P2) > aTolDist) {
+           Standard_Real anewpar = lprm;
 
             if(ParameterOutOfBoundary(lprm, newc, myFace1, myFace2, 
                                       fprm, Standard_True, anewpar, myContext)) {
-              lprm = anewpar;
-            }
-            aSeqFprm.Append(aNul);
-            aSeqLprm.Append(lprm);
-          }
-        }
+             lprm = anewpar;
+           }
+           aSeqFprm.Append(aNul);
+           aSeqLprm.Append(lprm);
+         }
+       }
       }
       else {
-        // usual interval 
-        aSeqFprm.Append(fprm);
-        aSeqLprm.Append(lprm);
+       // usual interval 
+       aSeqFprm.Append(fprm);
+       aSeqLprm.Append(lprm);
       }
     }
-
+    
     //
     aNbParts=aSeqFprm.Length();
     for (i=1; i<=aNbParts; i++) {
@@ -1473,233 +1473,233 @@ reapprox:;
       //
       Standard_Real aRealEpsilon=RealEpsilon();
       if (Abs(fprm) > aRealEpsilon || Abs(lprm-2.*M_PI) > aRealEpsilon) {
-        //==============================================
-        ////
-        IntTools_Curve aCurve;
-        Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
-        aCurve.SetCurve(aTC3D);
-        fprm=aTC3D->FirstParameter();
-        lprm=aTC3D->LastParameter ();
-        ////         
-        if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {//// 
-          if(myApprox1) { 
-            Handle (Geom2d_Curve) C2d;
-            BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
-            if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-              myTolReached2d=Tolpc;
-            }
-            //
-            aCurve.SetFirstCurve2d(C2d);
-          }
-          else { //// 
-            Handle(Geom2d_BSplineCurve) H1;
-            aCurve.SetFirstCurve2d(H1);
-          }
-
-
-          if(myApprox2) { 
-            Handle (Geom2d_Curve) C2d;
-            BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
-            if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-              myTolReached2d=Tolpc;
-            }
-            //
-            aCurve.SetSecondCurve2d(C2d);
-          }
-          else { 
-            Handle(Geom2d_BSplineCurve) H1;
-            aCurve.SetSecondCurve2d(H1);
-          }
-        }
-
-        else { 
-          Handle(Geom2d_BSplineCurve) H1;
-          aCurve.SetFirstCurve2d(H1);
-          aCurve.SetSecondCurve2d(H1);
-        }
-        mySeqOfCurve.Append(aCurve);
-        //==============================================        
+       //==============================================
+       ////
+       IntTools_Curve aCurve;
+       Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
+       aCurve.SetCurve(aTC3D);
+       fprm=aTC3D->FirstParameter();
+       lprm=aTC3D->LastParameter ();
+       ////    
+       if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {//// 
+         if(myApprox1) { 
+           Handle (Geom2d_Curve) C2d;
+           BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
+           if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+             myTolReached2d=Tolpc;
+           }
+           //
+           aCurve.SetFirstCurve2d(C2d);
+         }
+         else { //// 
+           Handle(Geom2d_BSplineCurve) H1;
+           aCurve.SetFirstCurve2d(H1);
+         }
+
+
+         if(myApprox2) { 
+           Handle (Geom2d_Curve) C2d;
+           BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
+           if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+             myTolReached2d=Tolpc;
+           }
+           //
+           aCurve.SetSecondCurve2d(C2d);
+         }
+         else { 
+           Handle(Geom2d_BSplineCurve) H1;
+           aCurve.SetSecondCurve2d(H1);
+         }
+       }
+       
+       else { 
+         Handle(Geom2d_BSplineCurve) H1;
+         aCurve.SetFirstCurve2d(H1);
+         aCurve.SetSecondCurve2d(H1);
+       }
+       mySeqOfCurve.Append(aCurve);
+         //==============================================      
       } //if (Abs(fprm) > RealEpsilon() || Abs(lprm-2.*M_PI) > RealEpsilon())
 
       else {
-        //  on regarde si on garde
-        //
-        if (aNbParts==1) {
-          //           if (Abs(fprm) < RealEpsilon() &&  Abs(lprm-2.*M_PI) < RealEpsilon()) {
-          if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
-            IntTools_Curve aCurve;
-            Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
-            aCurve.SetCurve(aTC3D);
-            fprm=aTC3D->FirstParameter();
-            lprm=aTC3D->LastParameter ();
-
-            if(myApprox1) { 
-              Handle (Geom2d_Curve) C2d;
-              BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
-              if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-                myTolReached2d=Tolpc;
-              }
-              //
-              aCurve.SetFirstCurve2d(C2d);
-            }
-            else { //// 
-              Handle(Geom2d_BSplineCurve) H1;
-              aCurve.SetFirstCurve2d(H1);
-            }
-
-            if(myApprox2) { 
-              Handle (Geom2d_Curve) C2d;
-              BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
-              if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-                myTolReached2d=Tolpc;
-              }
-              //
-              aCurve.SetSecondCurve2d(C2d);
-            }
-            else { 
-              Handle(Geom2d_BSplineCurve) H1;
-              aCurve.SetSecondCurve2d(H1);
-            }
-            mySeqOfCurve.Append(aCurve);
-            break;
-          }
-        }
-        //
-        Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
-
-        aTwoPIdiv17=2.*M_PI/17.;
-
-        for (j=0; j<=17; j++) {
-          gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
-          Tol = Precision::Confusion();
-
-          Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
-          ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
-          if(ok) { 
-            ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
-          }
-          if (ok) {
-            IntTools_Curve aCurve;
-            aCurve.SetCurve(newc);
-            //==============================================
-            if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
-
-              if(myApprox1) { 
-                Handle (Geom2d_Curve) C2d;
-                BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
-                if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-                  myTolReached2d=Tolpc;
-                }
-                // 
-                aCurve.SetFirstCurve2d(C2d);
-              }
-              else { 
-                Handle(Geom2d_BSplineCurve) H1;
-                aCurve.SetFirstCurve2d(H1);
-              }
-
-              if(myApprox2) { 
-                Handle (Geom2d_Curve) C2d;
-                BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
-                if(Tolpc>myTolReached2d || myTolReached2d==0) { 
-                  myTolReached2d=Tolpc;
-                }
-                //                 
-                aCurve.SetSecondCurve2d(C2d);
-              }
-
-              else { 
-                Handle(Geom2d_BSplineCurve) H1;
-                aCurve.SetSecondCurve2d(H1);
-              }
-            }//  end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
-
-            else { 
-              Handle(Geom2d_BSplineCurve) H1;
-              //         
-              aCurve.SetFirstCurve2d(H1);
-              aCurve.SetSecondCurve2d(H1);
-            }
-            //==============================================        
-            //
-            mySeqOfCurve.Append(aCurve);
-            break;
-
-          }//  end of if (ok) {
-        }//  end of for (Standard_Integer j=0; j<=17; j++)
-      }//  end of else { on regarde si on garde
-    }// for (i=1; i<=myLConstruct.NbParts(); i++)
-  }// IntPatch_Circle: IntPatch_Ellipse:
-  break;
-
+       //  on regarde si on garde
+       //
+       if (aNbParts==1) {
+//       if (Abs(fprm) < RealEpsilon() &&  Abs(lprm-2.*M_PI) < RealEpsilon()) {
+         if (Abs(fprm) <= aRealEpsilon && Abs(lprm-2.*M_PI) <= aRealEpsilon) {
+           IntTools_Curve aCurve;
+           Handle(Geom_TrimmedCurve) aTC3D=new Geom_TrimmedCurve(newc,fprm,lprm);
+           aCurve.SetCurve(aTC3D);
+           fprm=aTC3D->FirstParameter();
+           lprm=aTC3D->LastParameter ();
+           
+           if(myApprox1) { 
+             Handle (Geom2d_Curve) C2d;
+             BuildPCurves(fprm,lprm,Tolpc,myHS1->ChangeSurface().Surface(),newc,C2d);
+             if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+               myTolReached2d=Tolpc;
+             }
+             //
+             aCurve.SetFirstCurve2d(C2d);
+           }
+           else { //// 
+             Handle(Geom2d_BSplineCurve) H1;
+             aCurve.SetFirstCurve2d(H1);
+           }
+
+           if(myApprox2) { 
+             Handle (Geom2d_Curve) C2d;
+             BuildPCurves(fprm,lprm,Tolpc,myHS2->ChangeSurface().Surface(),newc,C2d);
+             if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+               myTolReached2d=Tolpc;
+             }
+             //
+             aCurve.SetSecondCurve2d(C2d);
+           }
+           else { 
+             Handle(Geom2d_BSplineCurve) H1;
+             aCurve.SetSecondCurve2d(H1);
+           }
+           mySeqOfCurve.Append(aCurve);
+           break;
+         }
+       }
+       //
+       Standard_Real aTwoPIdiv17, u1, v1, u2, v2, Tol;
+
+       aTwoPIdiv17=2.*M_PI/17.;
+
+       for (j=0; j<=17; j++) {
+         gp_Pnt ptref (newc->Value (j*aTwoPIdiv17));
+         Tol = Precision::Confusion();
+
+         Parameters(myHS1, myHS2, ptref, u1, v1, u2, v2);
+         ok = (dom1->Classify(gp_Pnt2d(u1,v1),Tol) != TopAbs_OUT);
+         if(ok) { 
+           ok = (dom2->Classify(gp_Pnt2d(u2,v2),Tol) != TopAbs_OUT);
+         }
+         if (ok) {
+           IntTools_Curve aCurve;
+           aCurve.SetCurve(newc);
+           //==============================================
+           if (typl == IntPatch_Circle || typl == IntPatch_Ellipse) {
+             
+             if(myApprox1) { 
+               Handle (Geom2d_Curve) C2d;
+               BuildPCurves(fprm, lprm, Tolpc, myHS1->ChangeSurface().Surface(), newc, C2d);
+               if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+                 myTolReached2d=Tolpc;
+               }
+               // 
+               aCurve.SetFirstCurve2d(C2d);
+             }
+             else { 
+               Handle(Geom2d_BSplineCurve) H1;
+               aCurve.SetFirstCurve2d(H1);
+             }
+               
+             if(myApprox2) { 
+               Handle (Geom2d_Curve) C2d;
+               BuildPCurves(fprm, lprm, Tolpc,myHS2->ChangeSurface().Surface(), newc, C2d);
+               if(Tolpc>myTolReached2d || myTolReached2d==0) { 
+                 myTolReached2d=Tolpc;
+               }
+               //              
+               aCurve.SetSecondCurve2d(C2d);
+             }
+               
+             else { 
+               Handle(Geom2d_BSplineCurve) H1;
+               aCurve.SetSecondCurve2d(H1);
+             }
+           }//  end of if (typl == IntPatch_Circle || typl == IntPatch_Ellipse)
+            
+           else { 
+             Handle(Geom2d_BSplineCurve) H1;
+             //        
+             aCurve.SetFirstCurve2d(H1);
+             aCurve.SetSecondCurve2d(H1);
+           }
+           //==============================================    
+           //
+           mySeqOfCurve.Append(aCurve);
+           break;
+
+           }//  end of if (ok) {
+         }//  end of for (Standard_Integer j=0; j<=17; j++)
+       }//  end of else { on regarde si on garde
+      }// for (i=1; i<=myLConstruct.NbParts(); i++)
+    }// IntPatch_Circle: IntPatch_Ellipse:
+    break;
+    
   case IntPatch_Analytic: {
     IntSurf_Quadric quad1,quad2;
     GeomAbs_SurfaceType typs = myHS1->Surface().GetType();
-
+    
     switch (typs) {
-    case GeomAbs_Plane:
-      quad1.SetValue(myHS1->Surface().Plane());
-      break;
-    case GeomAbs_Cylinder:
-      quad1.SetValue(myHS1->Surface().Cylinder());
-      break;
-    case GeomAbs_Cone:
-      quad1.SetValue(myHS1->Surface().Cone());
-      break;
-    case GeomAbs_Sphere:
-      quad1.SetValue(myHS1->Surface().Sphere());
-      break;
+      case GeomAbs_Plane:
+        quad1.SetValue(myHS1->Surface().Plane());
+       break;
+      case GeomAbs_Cylinder:
+       quad1.SetValue(myHS1->Surface().Cylinder());
+       break;
+      case GeomAbs_Cone:
+       quad1.SetValue(myHS1->Surface().Cone());
+       break;
+      case GeomAbs_Sphere:
+       quad1.SetValue(myHS1->Surface().Sphere());
+       break;
     case GeomAbs_Torus:
       quad1.SetValue(myHS1->Surface().Torus());
       break;
-    default:
-      Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
-    }
-
+      default:
+       Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 1");
+      }
+      
     typs = myHS2->Surface().GetType();
-
+    
     switch (typs) {
-    case GeomAbs_Plane:
-      quad2.SetValue(myHS2->Surface().Plane());
-      break;
-    case GeomAbs_Cylinder:
-      quad2.SetValue(myHS2->Surface().Cylinder());
-      break;
-    case GeomAbs_Cone:
-      quad2.SetValue(myHS2->Surface().Cone());
-      break;
-    case GeomAbs_Sphere:
-      quad2.SetValue(myHS2->Surface().Sphere());
-      break;
+      case GeomAbs_Plane:
+        quad2.SetValue(myHS2->Surface().Plane());
+       break;
+      case GeomAbs_Cylinder:
+       quad2.SetValue(myHS2->Surface().Cylinder());
+       break;
+      case GeomAbs_Cone:
+       quad2.SetValue(myHS2->Surface().Cone());
+       break;
+      case GeomAbs_Sphere:
+       quad2.SetValue(myHS2->Surface().Sphere());
+       break;
     case GeomAbs_Torus:
       quad2.SetValue(myHS2->Surface().Torus());
       break;
-    default:
-      Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
-    }
+      default:
+       Standard_ConstructionError::Raise("GeomInt_IntSS::MakeCurve 2");
+      }
     //
     //=========
     IntPatch_ALineToWLine convert (quad1, quad2);
-
+      
     if (!myApprox) {
       aNbParts=myLConstruct.NbParts();
       for (i=1; i<=aNbParts; i++) {
-        myLConstruct.Part(i, fprm, lprm);
-        Handle(IntPatch_WLine) WL = 
-          convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
-        //
-        Handle(Geom2d_BSplineCurve) H1;
-        Handle(Geom2d_BSplineCurve) H2;
-
-        if(myApprox1) {
-          H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
-        }
-
-        if(myApprox2) {
-          H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
-        }
-        //          
-        mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
+       myLConstruct.Part(i, fprm, lprm);
+       Handle(IntPatch_WLine) WL = 
+         convert.MakeWLine(Handle(IntPatch_ALine)::DownCast(L), fprm, lprm);
+       //
+       Handle(Geom2d_BSplineCurve) H1;
+       Handle(Geom2d_BSplineCurve) H2;
+
+       if(myApprox1) {
+         H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
+       }
+       
+       if(myApprox2) {
+         H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
+       }
+       //       
+       mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
       }
     } // if (!myApprox)
 
@@ -1707,111 +1707,111 @@ reapprox:;
       GeomInt_WLApprox theapp3d;
       // 
       Standard_Real tol2d = myTolApprox;
-      //         
+      //       
       theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True);
-
+      
       aNbParts=myLConstruct.NbParts();
       for (i=1; i<=aNbParts; i++) {
-        myLConstruct.Part(i, fprm, lprm);
-        Handle(IntPatch_WLine) WL = 
-          convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
-
-        theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
-
-        if (!theapp3d.IsDone()) {
-          //
-          Handle(Geom2d_BSplineCurve) H1;
-          Handle(Geom2d_BSplineCurve) H2;
-
-          if(myApprox1) {
-            H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
-          }
-
-          if(myApprox2) {
-            H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
-          }
-          //          
-          mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
-        }
-
-        else {
-          if(myApprox1 || myApprox2) { 
-            if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) { 
-              myTolReached2d = theapp3d.TolReached2d();
-            }
-          }
-
-          if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) { 
-            myTolReached3d = theapp3d.TolReached3d();
-          }
-
-          Standard_Integer aNbMultiCurves, nbpoles;
-          aNbMultiCurves=theapp3d.NbMultiCurves();
-          for (j=1; j<=aNbMultiCurves; j++) {
-            const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
-            nbpoles = mbspc.NbPoles();
-
-            TColgp_Array1OfPnt tpoles(1, nbpoles);
-            mbspc.Curve(1, tpoles);
-            Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
-              mbspc.Knots(),
-              mbspc.Multiplicities(),
-              mbspc.Degree());
-
-            GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
-            Check.FixTangent(Standard_True,Standard_True);
-            // 
-            IntTools_Curve aCurve;
-            aCurve.SetCurve(BS);
-
-            if(myApprox1) { 
-              TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
-              mbspc.Curve(2,tpoles2d);
-              Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
-                mbspc.Knots(),
-                mbspc.Multiplicities(),
-                mbspc.Degree());
-
-              GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
-              newCheck.FixTangent(Standard_True,Standard_True);
-              //                 
-              aCurve.SetFirstCurve2d(BS2);
-            }
-            else {
-              Handle(Geom2d_BSplineCurve) H1;
-              aCurve.SetFirstCurve2d(H1);
-            }
-
-            if(myApprox2) { 
-              TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
-              Standard_Integer TwoOrThree;
-              TwoOrThree=myApprox1 ? 3 : 2;
-              mbspc.Curve(TwoOrThree, tpoles2d);
-              Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
-                mbspc.Knots(),
-                mbspc.Multiplicities(),
-                mbspc.Degree());
-
-              GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
-              newCheck.FixTangent(Standard_True,Standard_True);
-              //         
-              aCurve.SetSecondCurve2d(BS2);
-            }
-            else { 
-              Handle(Geom2d_BSplineCurve) H2;
-              aCurve.SetSecondCurve2d(H2);
-            }
-            // 
-            mySeqOfCurve.Append(aCurve);
-
-          }// for (j=1; j<=aNbMultiCurves; j++) {
-        }// else from if (!theapp3d.IsDone())
+       myLConstruct.Part(i, fprm, lprm);
+       Handle(IntPatch_WLine) WL = 
+         convert.MakeWLine(Handle(IntPatch_ALine):: DownCast(L),fprm,lprm);
+
+       theapp3d.Perform(myHS1,myHS2,WL,Standard_True,myApprox1,myApprox2, 1, WL->NbPnts());
+
+       if (!theapp3d.IsDone()) {
+         //
+         Handle(Geom2d_BSplineCurve) H1;
+         Handle(Geom2d_BSplineCurve) H2;
+
+         if(myApprox1) {
+           H1 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_True);
+         }
+         
+         if(myApprox2) {
+           H2 = MakeBSpline2d(WL, 1, WL->NbPnts(), Standard_False);
+         }
+         //     
+         mySeqOfCurve.Append(IntTools_Curve(MakeBSpline(WL,1,WL->NbPnts()), H1, H2));
+       }
+
+       else {
+         if(myApprox1 || myApprox2) { 
+           if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0) { 
+             myTolReached2d = theapp3d.TolReached2d();
+           }
+         }
+         
+         if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0) { 
+           myTolReached3d = theapp3d.TolReached3d();
+         }
+
+         Standard_Integer aNbMultiCurves, nbpoles;
+         aNbMultiCurves=theapp3d.NbMultiCurves();
+         for (j=1; j<=aNbMultiCurves; j++) {
+           const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+           nbpoles = mbspc.NbPoles();
+           
+           TColgp_Array1OfPnt tpoles(1, nbpoles);
+           mbspc.Curve(1, tpoles);
+           Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
+                                                              mbspc.Knots(),
+                                                              mbspc.Multiplicities(),
+                                                              mbspc.Degree());
+           
+           GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+           Check.FixTangent(Standard_True,Standard_True);
+           // 
+           IntTools_Curve aCurve;
+           aCurve.SetCurve(BS);
+           
+           if(myApprox1) { 
+             TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+             mbspc.Curve(2,tpoles2d);
+             Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
+                                                                     mbspc.Knots(),
+                                                                     mbspc.Multiplicities(),
+                                                                     mbspc.Degree());
+
+             GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+             newCheck.FixTangent(Standard_True,Standard_True);
+             //                
+             aCurve.SetFirstCurve2d(BS2);
+           }
+           else {
+             Handle(Geom2d_BSplineCurve) H1;
+             aCurve.SetFirstCurve2d(H1);
+           }
+           
+           if(myApprox2) { 
+             TColgp_Array1OfPnt2d tpoles2d(1, nbpoles);
+             Standard_Integer TwoOrThree;
+             TwoOrThree=myApprox1 ? 3 : 2;
+             mbspc.Curve(TwoOrThree, tpoles2d);
+             Handle(Geom2d_BSplineCurve) BS2 =new Geom2d_BSplineCurve(tpoles2d,
+                                                                      mbspc.Knots(),
+                                                                      mbspc.Multiplicities(),
+                                                                      mbspc.Degree());
+               
+             GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+             newCheck.FixTangent(Standard_True,Standard_True);
+             //        
+             aCurve.SetSecondCurve2d(BS2);
+           }
+           else { 
+             Handle(Geom2d_BSplineCurve) H2;
+             aCurve.SetSecondCurve2d(H2);
+           }
+           // 
+           mySeqOfCurve.Append(aCurve);
+
+         }// for (j=1; j<=aNbMultiCurves; j++) {
+       }// else from if (!theapp3d.IsDone())
       }// for (i=1; i<=aNbParts; i++) {
     }// else { // myApprox=TRUE
   }// case IntPatch_Analytic:
-  break;
+    break;
 
-  case IntPatch_Walking: {
+  case IntPatch_Walking:{
     Handle(IntPatch_WLine) WL = 
       Handle(IntPatch_WLine)::DownCast(L);
     //
@@ -1820,33 +1820,33 @@ reapprox:;
     if (!myApprox) {
       aNbParts = 1;
       if(!bAvoidLineConstructor){
-        aNbParts=myLConstruct.NbParts();
+       aNbParts=myLConstruct.NbParts();
       }
       for (i=1; i<=aNbParts; ++i) {
-        Handle(Geom2d_BSplineCurve) H1, H2;
-        Handle(Geom_Curve) aBSp;
-        //
-        if(bAvoidLineConstructor) {
-          ifprm = 1;
-          ilprm = WL->NbPnts();
-        }
-        else {
-          myLConstruct.Part(i, fprm, lprm);
-          ifprm=(Standard_Integer)fprm;
-          ilprm=(Standard_Integer)lprm;
-        }
-        //
-        if(myApprox1) {
-          H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
-        }
-        //
-        if(myApprox2) {
-          H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
-        }
-        //           
-        aBSp=MakeBSpline(WL, ifprm, ilprm);
-        IntTools_Curve aIC(aBSp, H1, H2);
-        mySeqOfCurve.Append(aIC);
+       Handle(Geom2d_BSplineCurve) H1, H2;
+       Handle(Geom_Curve) aBSp;
+       //
+       if(bAvoidLineConstructor) {
+         ifprm = 1;
+         ilprm = WL->NbPnts();
+       }
+       else {
+         myLConstruct.Part(i, fprm, lprm);
+         ifprm=(Standard_Integer)fprm;
+         ilprm=(Standard_Integer)lprm;
+       }
+       //
+       if(myApprox1) {
+         H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
+       }
+       //
+       if(myApprox2) {
+         H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
+       }
+       //        
+       aBSp=MakeBSpline(WL, ifprm, ilprm);
+       IntTools_Curve aIC(aBSp, H1, H2);
+       mySeqOfCurve.Append(aIC);
       }// for (i=1; i<=aNbParts; ++i) {
     }// if (!myApprox) {
     //
@@ -1870,346 +1870,346 @@ reapprox:;
       Standard_Boolean anWithPC = Standard_True;
 
       if(typs1 == GeomAbs_Cylinder && typs2 == GeomAbs_Sphere) {
-        anWithPC = 
-          ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
+       anWithPC = 
+         ApproxWithPCurves(myHS1->Surface().Cylinder(), myHS2->Surface().Sphere());
       }
       else if (typs1 == GeomAbs_Sphere && typs2 == GeomAbs_Cylinder) {
-        anWithPC = 
-          ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
+       anWithPC = 
+         ApproxWithPCurves(myHS2->Surface().Cylinder(), myHS1->Surface().Sphere());
       }
       //
       if(!anWithPC) {
         myTolApprox = aTolApproxImp;//1.e-5; 
-        anApprox1 = Standard_False;
-        anApprox2 = Standard_False;
-        //         
-        tol2d = myTolApprox;
+       anApprox1 = Standard_False;
+       anApprox2 = Standard_False;
+       //      
+       tol2d = myTolApprox;
       }
-
+       
       if(myHS1 == myHS2) { 
-        theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
-        rejectSurface = Standard_True;
+       theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
+       rejectSurface = Standard_True;
       }
       else { 
-        if(reApprox && !rejectSurface)
-          theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
-        else {
-          Standard_Integer iDegMax, iDegMin, iNbIter;
-          //
-          ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
-          theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
-        }
+       if(reApprox && !rejectSurface)
+         theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
+       else {
+         Standard_Integer iDegMax, iDegMin, iNbIter;
+         //
+         ApproxParameters(myHS1, myHS2, iDegMin, iDegMax, iNbIter);
+         theapp3d.SetParameters(myTolApprox, tol2d, iDegMin, iDegMax, iNbIter, Standard_True, aParType);
+       }
       }
       //
       Standard_Real aReachedTol = Precision::Confusion();
       bIsDecomposited=DecompositionOfWLine(WL,
-                                           myHS1, 
-                                           myHS2, 
-                                           myFace1, 
-                                           myFace2, 
-                                           myLConstruct, 
-                                           bAvoidLineConstructor, 
-                                           aSeqOfL, 
-                                           aReachedTol,
-                                           myContext);
+                                          myHS1, 
+                                          myHS2, 
+                                          myFace1, 
+                                          myFace2, 
+                                          myLConstruct, 
+                                          bAvoidLineConstructor, 
+                                          aSeqOfL, 
+                                          aReachedTol,
+                                          myContext);
       if ( bIsDecomposited && ( myTolReached3d < aReachedTol ) ) {
-        myTolReached3d = aReachedTol;
+       myTolReached3d = aReachedTol;
       }
       //
       aNbSeqOfL=aSeqOfL.Length();
       //
       if (bIsDecomposited) {
-        nbiter=aNbSeqOfL;
+       nbiter=aNbSeqOfL;
       }
       else {
-        nbiter=1;
-        aNbParts=1;
-        if (!bAvoidLineConstructor) {
-          aNbParts=myLConstruct.NbParts();
-          nbiter=aNbParts;
-        }
+       nbiter=1;
+       aNbParts=1;
+       if (!bAvoidLineConstructor) {
+         aNbParts=myLConstruct.NbParts();
+         nbiter=aNbParts;
+       }
       }
       //
       for(i = 1; i <= nbiter; ++i) {
-        if(bIsDecomposited) {
-          WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
-          ifprm = 1;
-          ilprm = WL->NbPnts();
-        }
-        else {
-          if(bAvoidLineConstructor) {
-            ifprm = 1;
-            ilprm = WL->NbPnts();
-          }
-          else {
-            myLConstruct.Part(i, fprm, lprm);
-            ifprm = (Standard_Integer)fprm;
-            ilprm = (Standard_Integer)lprm;
-          }
-        }
-        //-- lbr : 
-        //-- Si une des surfaces est un plan , on approxime en 2d
-        //-- sur cette surface et on remonte les points 2d en 3d.
-        if(typs1 == GeomAbs_Plane) { 
-          theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
-        }          
-        else if(typs2 == GeomAbs_Plane) { 
-          theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
-        }
-        else { 
-          //
-          if (myHS1 != myHS2){
-            if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
-              (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
-
-              theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
-
-              Standard_Boolean bUseSurfaces;
-              bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm,  ilprm);
-              if (bUseSurfaces) {
-                // ######
-                rejectSurface = Standard_True;
-                // ######
-                theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
-              }
-            }
-          }
-          //
-          theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
-        }
-        //
+       if(bIsDecomposited) {
+         WL = Handle(IntPatch_WLine)::DownCast(aSeqOfL.Value(i));
+         ifprm = 1;
+         ilprm = WL->NbPnts();
+       }
+       else {
+         if(bAvoidLineConstructor) {
+           ifprm = 1;
+           ilprm = WL->NbPnts();
+         }
+         else {
+           myLConstruct.Part(i, fprm, lprm);
+           ifprm = (Standard_Integer)fprm;
+           ilprm = (Standard_Integer)lprm;
+         }
+       }
+       //-- lbr : 
+       //-- Si une des surfaces est un plan , on approxime en 2d
+       //-- sur cette surface et on remonte les points 2d en 3d.
+       if(typs1 == GeomAbs_Plane) { 
+         theapp3d.Perform(myHS1, myHS2, WL, Standard_False,Standard_True, myApprox2,ifprm,ilprm);
+       }         
+       else if(typs2 == GeomAbs_Plane) { 
+         theapp3d.Perform(myHS1,myHS2,WL,Standard_False,myApprox1,Standard_True,ifprm,ilprm);
+       }
+       else { 
+         //
+         if (myHS1 != myHS2){
+           if ((typs1==GeomAbs_BezierSurface || typs1==GeomAbs_BSplineSurface) &&
+               (typs2==GeomAbs_BezierSurface || typs2==GeomAbs_BSplineSurface)) {
+            
+             theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_True, aParType);
+             
+             Standard_Boolean bUseSurfaces;
+             bUseSurfaces=NotUseSurfacesForApprox(myFace1, myFace2, WL, ifprm,  ilprm);
+             if (bUseSurfaces) {
+               // ######
+               rejectSurface = Standard_True;
+               // ######
+               theapp3d.SetParameters(myTolApprox, tol2d, 4, 8, 0, Standard_False, aParType);
+             }
+           }
+         }
+         //
+         theapp3d.Perform(myHS1,myHS2,WL,Standard_True,anApprox1,anApprox2,ifprm,ilprm);
+       }
+         //      
         if (!theapp3d.IsDone()) {
-          Handle(Geom2d_BSplineCurve) H1;
+         Handle(Geom2d_BSplineCurve) H1;
           Handle(Geom2d_BSplineCurve) H2;
-          //           
-          Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
+         //      
+         Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
           //
-          if(myApprox1) {
-            H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
-          }
+         if(myApprox1) {
+           H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
+         }
           //
-          if(myApprox2) {
-            H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
-          }
-          //           
-          IntTools_Curve aIC(aBSp, H1, H2);
-          mySeqOfCurve.Append(aIC);
-        }
-
-        else {
-          if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) { 
-            if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) { 
-              myTolReached2d = theapp3d.TolReached2d();
-            }
-          }
-          if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) { 
-            myTolReached3d = myTolReached2d;
-            //
-            if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
-              if (myTolReached3d<1.e-6) {
-                myTolReached3d = theapp3d.TolReached3d();
-                myTolReached3d=1.e-6;
-              }
-            }
-          }
-          else  if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) { 
-            myTolReached3d = theapp3d.TolReached3d();
-          }
-
-          Standard_Integer aNbMultiCurves, nbpoles;
-          aNbMultiCurves=theapp3d.NbMultiCurves(); 
-          for (j=1; j<=aNbMultiCurves; j++) {
-            if(typs1 == GeomAbs_Plane) {
-              const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
-              nbpoles = mbspc.NbPoles();
-
-              TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
-              TColgp_Array1OfPnt   tpoles(1,nbpoles);
-
-              mbspc.Curve(1,tpoles2d);
-              const gp_Pln&  Pln = myHS1->Surface().Plane();
-              //
-              Standard_Integer ik; 
-              for(ik = 1; ik<= nbpoles; ik++) { 
-                tpoles.SetValue(ik,
-                  ElSLib::Value(tpoles2d.Value(ik).X(),
-                  tpoles2d.Value(ik).Y(),
-                  Pln));
-              }
-              //
-              Handle(Geom_BSplineCurve) BS = 
-                new Geom_BSplineCurve(tpoles,
-                mbspc.Knots(),
-                mbspc.Multiplicities(),
-                mbspc.Degree());
-              GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
-              Check.FixTangent(Standard_True, Standard_True);
-              //         
-              IntTools_Curve aCurve;
-              aCurve.SetCurve(BS);
-
-              if(myApprox1) { 
-                Handle(Geom2d_BSplineCurve) BS1 = 
-                  new Geom2d_BSplineCurve(tpoles2d,
-                  mbspc.Knots(),
-                  mbspc.Multiplicities(),
-                  mbspc.Degree());
-                GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
-                Check1.FixTangent(Standard_True,Standard_True);
-                //
-                // ############################################
-                if(!rejectSurface && !reApprox) {
-                  Standard_Boolean isValid = IsCurveValid(BS1);
-                  if(!isValid) {
-                    reApprox = Standard_True;
-                    goto reapprox;
-                  }
-                }
-                // ############################################
-                aCurve.SetFirstCurve2d(BS1);
-              }
-              else {
-                Handle(Geom2d_BSplineCurve) H1;
-                aCurve.SetFirstCurve2d(H1);
-              }
-
-              if(myApprox2) { 
-                mbspc.Curve(2, tpoles2d);
-
-                Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
-                  mbspc.Knots(),
-                  mbspc.Multiplicities(),
-                  mbspc.Degree());
-                GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
-                newCheck.FixTangent(Standard_True,Standard_True);
-
-                // ###########################################
-                if(!rejectSurface && !reApprox) {
-                  Standard_Boolean isValid = IsCurveValid(BS2);
-                  if(!isValid) {
-                    reApprox = Standard_True;
-                    goto reapprox;
-                  }
-                }
-                // ###########################################
-                // 
-                aCurve.SetSecondCurve2d(BS2);
-              }
-              else { 
-                Handle(Geom2d_BSplineCurve) H2;
-                //                 
-                aCurve.SetSecondCurve2d(H2);
-              }
-              //
-              mySeqOfCurve.Append(aCurve);
+         if(myApprox2) {
+           H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
+         }
+         //      
+         IntTools_Curve aIC(aBSp, H1, H2);
+         mySeqOfCurve.Append(aIC);
+       }
+       
+       else {
+         if(myApprox1 || myApprox2 || (typs1==GeomAbs_Plane || typs2==GeomAbs_Plane)) { 
+           if( theapp3d.TolReached2d()>myTolReached2d || myTolReached2d==0.) { 
+             myTolReached2d = theapp3d.TolReached2d();
+           }
+         }
+         if(typs1==GeomAbs_Plane || typs2==GeomAbs_Plane) { 
+           myTolReached3d = myTolReached2d;
+           //
+           if (typs1==GeomAbs_Torus || typs2==GeomAbs_Torus) {
+             if (myTolReached3d<1.e-6) {
+               myTolReached3d = theapp3d.TolReached3d();
+               myTolReached3d=1.e-6;
+             }
+           }
+         }
+         else  if( theapp3d.TolReached3d()>myTolReached3d || myTolReached3d==0.) { 
+           myTolReached3d = theapp3d.TolReached3d();
+         }
+         
+         Standard_Integer aNbMultiCurves, nbpoles;
+         aNbMultiCurves=theapp3d.NbMultiCurves(); 
+         for (j=1; j<=aNbMultiCurves; j++) {
+           if(typs1 == GeomAbs_Plane) {
+             const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+             nbpoles = mbspc.NbPoles();
+             
+             TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+             TColgp_Array1OfPnt   tpoles(1,nbpoles);
+             
+             mbspc.Curve(1,tpoles2d);
+             const gp_Pln&  Pln = myHS1->Surface().Plane();
+             //
+             Standard_Integer ik; 
+             for(ik = 1; ik<= nbpoles; ik++) { 
+               tpoles.SetValue(ik,
+                               ElSLib::Value(tpoles2d.Value(ik).X(),
+                                             tpoles2d.Value(ik).Y(),
+                                             Pln));
+             }
+             //
+             Handle(Geom_BSplineCurve) BS = 
+               new Geom_BSplineCurve(tpoles,
+                                     mbspc.Knots(),
+                                     mbspc.Multiplicities(),
+                                     mbspc.Degree());
+             GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+             Check.FixTangent(Standard_True, Standard_True);
+             //        
+             IntTools_Curve aCurve;
+             aCurve.SetCurve(BS);
+
+             if(myApprox1) { 
+               Handle(Geom2d_BSplineCurve) BS1 = 
+                 new Geom2d_BSplineCurve(tpoles2d,
+                                         mbspc.Knots(),
+                                         mbspc.Multiplicities(),
+                                         mbspc.Degree());
+               GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
+               Check1.FixTangent(Standard_True,Standard_True);
+               //
+               // ############################################
+               if(!rejectSurface && !reApprox) {
+                 Standard_Boolean isValid = IsCurveValid(BS1);
+                 if(!isValid) {
+                   reApprox = Standard_True;
+                   goto reapprox;
+                 }
+               }
+               // ############################################
+               aCurve.SetFirstCurve2d(BS1);
+             }
+             else {
+               Handle(Geom2d_BSplineCurve) H1;
+               aCurve.SetFirstCurve2d(H1);
+             }
+
+             if(myApprox2) { 
+               mbspc.Curve(2, tpoles2d);
+               
+               Handle(Geom2d_BSplineCurve) BS2 = new Geom2d_BSplineCurve(tpoles2d,
+                                                                         mbspc.Knots(),
+                                                                         mbspc.Multiplicities(),
+                                                                         mbspc.Degree());
+               GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+               newCheck.FixTangent(Standard_True,Standard_True);
+               
+               // ###########################################
+               if(!rejectSurface && !reApprox) {
+                 Standard_Boolean isValid = IsCurveValid(BS2);
+                 if(!isValid) {
+                   reApprox = Standard_True;
+                   goto reapprox;
+                 }
+               }
+               // ###########################################
+               // 
+               aCurve.SetSecondCurve2d(BS2);
+             }
+             else { 
+               Handle(Geom2d_BSplineCurve) H2;
+               //              
+                 aCurve.SetSecondCurve2d(H2);
+             }
+             //
+             mySeqOfCurve.Append(aCurve);
             }//if(typs1 == GeomAbs_Plane) {
-
-            else if(typs2 == GeomAbs_Plane) { 
-              const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
-              nbpoles = mbspc.NbPoles();
-
-              TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
-              TColgp_Array1OfPnt   tpoles(1,nbpoles);
-              mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
-              const gp_Pln&  Pln = myHS2->Surface().Plane();
-              //
-              Standard_Integer ik; 
-              for(ik = 1; ik<= nbpoles; ik++) { 
-                tpoles.SetValue(ik,
-                  ElSLib::Value(tpoles2d.Value(ik).X(),
-                  tpoles2d.Value(ik).Y(),
-                  Pln));
-
-              }
-              //
-              Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
-                mbspc.Knots(),
-                mbspc.Multiplicities(),
-                mbspc.Degree());
-              GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
-              Check.FixTangent(Standard_True,Standard_True);
-              //         
-              IntTools_Curve aCurve;
-              aCurve.SetCurve(BS);
-
-              if(myApprox2) {
-                Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
-                  mbspc.Knots(),
-                  mbspc.Multiplicities(),
-                  mbspc.Degree());
-                GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
-                Check1.FixTangent(Standard_True,Standard_True);
-                //         
-                // ###########################################
-                if(!rejectSurface && !reApprox) {
-                  Standard_Boolean isValid = IsCurveValid(BS1);
-                  if(!isValid) {
-                    reApprox = Standard_True;
-                    goto reapprox;
-                  }
-                }
+           
+           else if(typs2 == GeomAbs_Plane) { 
+             const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+             nbpoles = mbspc.NbPoles();
+             
+             TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+             TColgp_Array1OfPnt   tpoles(1,nbpoles);
+             mbspc.Curve((myApprox1==Standard_True)? 2 : 1,tpoles2d);
+             const gp_Pln&  Pln = myHS2->Surface().Plane();
+             //
+             Standard_Integer ik; 
+             for(ik = 1; ik<= nbpoles; ik++) { 
+               tpoles.SetValue(ik,
+                               ElSLib::Value(tpoles2d.Value(ik).X(),
+                                             tpoles2d.Value(ik).Y(),
+                                             Pln));
+               
+             }
+             //
+             Handle(Geom_BSplineCurve) BS=new Geom_BSplineCurve(tpoles,
+                                                                mbspc.Knots(),
+                                                                mbspc.Multiplicities(),
+                                                                mbspc.Degree());
+             GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+             Check.FixTangent(Standard_True,Standard_True);
+             //        
+             IntTools_Curve aCurve;
+             aCurve.SetCurve(BS);
+
+             if(myApprox2) {
+               Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(tpoles2d,
+                                                                       mbspc.Knots(),
+                                                                       mbspc.Multiplicities(),
+                                                                       mbspc.Degree());
+               GeomLib_Check2dBSplineCurve Check1(BS1,TOLCHECK,TOLANGCHECK);
+               Check1.FixTangent(Standard_True,Standard_True);
+               //      
+               // ###########################################
+               if(!rejectSurface && !reApprox) {
+                 Standard_Boolean isValid = IsCurveValid(BS1);
+                 if(!isValid) {
+                   reApprox = Standard_True;
+                   goto reapprox;
+                 }
+               }
                 // ###########################################
                 bPCurvesOk = CheckPCurve(BS1, myFace2);
-                aCurve.SetSecondCurve2d(BS1);
-              }
-              else {
-                Handle(Geom2d_BSplineCurve) H2;
-                aCurve.SetSecondCurve2d(H2);
-              }
-
-              if(myApprox1) { 
-                mbspc.Curve(1,tpoles2d);
-                Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
-                  mbspc.Knots(),
-                  mbspc.Multiplicities(),
-                  mbspc.Degree());
-                GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
-                Check2.FixTangent(Standard_True,Standard_True);
-                //
-                // ###########################################
-                if(!rejectSurface && !reApprox) {
-                  Standard_Boolean isValid = IsCurveValid(BS2);
-                  if(!isValid) {
-                    reApprox = Standard_True;
-                    goto reapprox;
-                  }
-                }
+               aCurve.SetSecondCurve2d(BS1);
+             }
+             else {
+               Handle(Geom2d_BSplineCurve) H2;
+               aCurve.SetSecondCurve2d(H2);
+             }
+             
+             if(myApprox1) { 
+               mbspc.Curve(1,tpoles2d);
+               Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(tpoles2d,
+                                                                       mbspc.Knots(),
+                                                                       mbspc.Multiplicities(),
+                                                                       mbspc.Degree());
+               GeomLib_Check2dBSplineCurve Check2(BS2,TOLCHECK,TOLANGCHECK);
+               Check2.FixTangent(Standard_True,Standard_True);
+               //
+               // ###########################################
+               if(!rejectSurface && !reApprox) {
+                 Standard_Boolean isValid = IsCurveValid(BS2);
+                 if(!isValid) {
+                   reApprox = Standard_True;
+                   goto reapprox;
+                 }
+               }
                 // ###########################################
                 bPCurvesOk = bPCurvesOk && CheckPCurve(BS2, myFace1);
-                aCurve.SetFirstCurve2d(BS2);
-              }
-              else { 
-                Handle(Geom2d_BSplineCurve) H1;
-                //                 
-                aCurve.SetFirstCurve2d(H1);
-              }
-              //
+               aCurve.SetFirstCurve2d(BS2);
+             }
+             else { 
+               Handle(Geom2d_BSplineCurve) H1;
+               //              
+               aCurve.SetFirstCurve2d(H1);
+             }
+             //
               //if points of the pcurves are out of the faces bounds
               //create 3d and 2d curves without approximation
               if (!bPCurvesOk) {
                 Handle(Geom2d_BSplineCurve) H1, H2;
-                bPCurvesOk = Standard_True;
-                //           
+               bPCurvesOk = Standard_True;
+                //       
                 Handle(Geom_Curve) aBSp=MakeBSpline(WL,ifprm, ilprm);
-
+                
                 if(myApprox1) {
                   H1 = MakeBSpline2d(WL, ifprm, ilprm, Standard_True);
-                  bPCurvesOk = CheckPCurve(H1, myFace1);
+                 bPCurvesOk = CheckPCurve(H1, myFace1);
                 }
-
+                
                 if(myApprox2) {
                   H2 = MakeBSpline2d(WL, ifprm, ilprm, Standard_False);
-                  bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
+                 bPCurvesOk = bPCurvesOk && CheckPCurve(H2, myFace2);
                 }
                 //
-                //if pcurves created without approximation are out of the 
-                //faces bounds, use approximated 3d and 2d curves
-                if (bPCurvesOk) {
-                  IntTools_Curve aIC(aBSp, H1, H2);
-                  mySeqOfCurve.Append(aIC);
-                } else {
-                  mySeqOfCurve.Append(aCurve);
-                }
+               //if pcurves created without approximation are out of the 
+               //faces bounds, use approximated 3d and 2d curves
+               if (bPCurvesOk) {
+                 IntTools_Curve aIC(aBSp, H1, H2);
+                 mySeqOfCurve.Append(aIC);
+               } else {
+                 mySeqOfCurve.Append(aCurve);
+               }
               } else {
                 mySeqOfCurve.Append(aCurve);
               }
@@ -2224,98 +2224,98 @@ reapprox:;
               bIsValid1=Standard_True;
               bIsValid2=Standard_True;
               //
-              const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
-              nbpoles = mbspc.NbPoles();
-              TColgp_Array1OfPnt tpoles(1,nbpoles);
-              mbspc.Curve(1,tpoles);
+             const AppParCurves_MultiBSpCurve& mbspc = theapp3d.Value(j);
+             nbpoles = mbspc.NbPoles();
+             TColgp_Array1OfPnt tpoles(1,nbpoles);
+             mbspc.Curve(1,tpoles);
               BS=new Geom_BSplineCurve(tpoles,
-                                       mbspc.Knots(),
-                                       mbspc.Multiplicities(),
-                                       mbspc.Degree());
-              GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
-              Check.FixTangent(Standard_True,Standard_True);
-              //
-              aCurve.SetCurve(BS);
+                                                                mbspc.Knots(),
+                                                                mbspc.Multiplicities(),
+                                                                mbspc.Degree());
+             GeomLib_CheckBSplineCurve Check(BS,TOLCHECK,TOLANGCHECK);
+             Check.FixTangent(Standard_True,Standard_True);
+             //                
+             aCurve.SetCurve(BS);
               aCurve.SetFirstCurve2d(aH2D);
               aCurve.SetSecondCurve2d(aH2D);
               //
-              if(myApprox1) { 
-                if(anApprox1) {
+             if(myApprox1) { 
+               if(anApprox1) {
                   Handle(Geom2d_BSplineCurve) BS1;
-                  TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
-                  mbspc.Curve(2,tpoles2d);
+                 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+                 mbspc.Curve(2,tpoles2d);
                   //
                   BS1=new Geom2d_BSplineCurve(tpoles2d,
-                                              mbspc.Knots(),
-                                              mbspc.Multiplicities(),
-                                              mbspc.Degree());
-                  GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
-                  newCheck.FixTangent(Standard_True,Standard_True);
-                  // 
+                                                                       mbspc.Knots(),
+                                                                       mbspc.Multiplicities(),
+                                                                       mbspc.Degree());
+                 GeomLib_Check2dBSplineCurve newCheck(BS1,TOLCHECK,TOLANGCHECK);
+                 newCheck.FixTangent(Standard_True,Standard_True);
+                 //    
                   if (!reApprox) {
                     bIsValid1=CheckPCurve(BS1, myFace1);
                   }
                   //
-                  aCurve.SetFirstCurve2d(BS1);
-                }
-                else {
-                  Handle(Geom2d_BSplineCurve) BS1;
-                  fprm = BS->FirstParameter();
-                  lprm = BS->LastParameter();
-
-                  Handle(Geom2d_Curve) C2d;
-                  Standard_Real aTol = myTolApprox;
-                  BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
-                  BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
-                  aCurve.SetFirstCurve2d(BS1);
-                }
+                 aCurve.SetFirstCurve2d(BS1);
+               }
+               else {
+                 Handle(Geom2d_BSplineCurve) BS1;
+                 fprm = BS->FirstParameter();
+                 lprm = BS->LastParameter();
+
+                 Handle(Geom2d_Curve) C2d;
+                 Standard_Real aTol = myTolApprox;
+                 BuildPCurves(fprm, lprm, aTol, myHS1->ChangeSurface().Surface(), BS, C2d);
+                 BS1 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
+                 aCurve.SetFirstCurve2d(BS1);
+               }
               } // if(myApprox1) { 
-              //
-              if(myApprox2) { 
-                if(anApprox2) {
+               //              
+             if(myApprox2) { 
+               if(anApprox2) {
                   Handle(Geom2d_BSplineCurve) BS2;
-                  TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
-                  mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
+                 TColgp_Array1OfPnt2d tpoles2d(1,nbpoles);
+                 mbspc.Curve((myApprox1==Standard_True)? 3 : 2,tpoles2d);
                   BS2=new Geom2d_BSplineCurve(tpoles2d,
-                                              mbspc.Knots(),
-                                              mbspc.Multiplicities(),
-                                              mbspc.Degree());
-                  GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
-                  newCheck.FixTangent(Standard_True,Standard_True);
-                  // 
+                                                                       mbspc.Knots(),
+                                                                       mbspc.Multiplicities(),
+                                                                       mbspc.Degree());
+                 GeomLib_Check2dBSplineCurve newCheck(BS2,TOLCHECK,TOLANGCHECK);
+                 newCheck.FixTangent(Standard_True,Standard_True);
+               //              
                   if (!reApprox) {
                     bIsValid2=CheckPCurve(BS2, myFace2);        
                   }
-                  aCurve.SetSecondCurve2d(BS2);
-                }
-                else {
-                  Handle(Geom2d_BSplineCurve) BS2;
-                  fprm = BS->FirstParameter();
-                  lprm = BS->LastParameter();
-
-                  Handle(Geom2d_Curve) C2d;
-                  Standard_Real aTol = myTolApprox;
-                  BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
-                  BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
-                  aCurve.SetSecondCurve2d(BS2);
-                }
+                 aCurve.SetSecondCurve2d(BS2);
+               }
+               else {
+                 Handle(Geom2d_BSplineCurve) BS2;
+                 fprm = BS->FirstParameter();
+                 lprm = BS->LastParameter();
+
+                 Handle(Geom2d_Curve) C2d;
+                 Standard_Real aTol = myTolApprox;
+                 BuildPCurves(fprm, lprm, aTol, myHS2->ChangeSurface().Surface(), BS, C2d);
+                 BS2 = Handle(Geom2d_BSplineCurve)::DownCast(C2d);
+                 aCurve.SetSecondCurve2d(BS2);
+               }
               } //if(myApprox2) { 
               if (!bIsValid1 || !bIsValid2) {
                 myTolApprox=aTolApproxImp;//1.e-5;
                 tol2d = myTolApprox;
                 reApprox = Standard_True;
                 goto reapprox;
-              }
-              //
-              mySeqOfCurve.Append(aCurve);
-            }
-          }
-        }
+             }
+               //              
+             mySeqOfCurve.Append(aCurve);
+           }
+         }
+       }
       }
     }// else { // X
   }// case IntPatch_Walking:{
-  break;
-
+    break;
+    
   case IntPatch_Restriction: 
     break;
   default:
@@ -2329,30 +2329,33 @@ reapprox:;
 //purpose  : 
 //=======================================================================
  void BuildPCurves (Standard_Real f,
-                    Standard_Real l,
-                    Standard_Real& Tol,
-                    const Handle (Geom_Surface)& S,
-                    const Handle (Geom_Curve)&   C,
-                    Handle (Geom2d_Curve)& C2d)
+                   Standard_Real l,
+                   Standard_Real& Tol,
+                   const Handle (Geom_Surface)& S,
+                   const Handle (Geom_Curve)&   C,
+                   Handle (Geom2d_Curve)& C2d)
 {
 
   Standard_Real umin,umax,vmin,vmax;
   // 
 
-  if (C2d.IsNull()) {
-
+  if (C2d.IsNull())
+  {
     // in class ProjLib_Function the range of parameters is shrank by 1.e-09
-    if((l - f) > 2.e-09) {
+    if((l - f) > 2.e-09)
+    {
       C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
       //
       if (C2d.IsNull()) {
         // proj. a circle that goes through the pole on a sphere to the sphere     
-        Tol=Tol+1.e-7;
+        Tol += Precision::Confusion();
         C2d = GeomProjLib::Curve2d(C,f,l,S,Tol);
       }
     }
-    else {
-      if((l - f) > Epsilon(Abs(f))) {
+    else
+    {
+      if((l - f) > Epsilon(Abs(f)))
+      {
         GeomAPI_ProjectPointOnSurf aProjector1, aProjector2;
         gp_Pnt P1 = C->Value(f);
         gp_Pnt P2 = C->Value(l);
@@ -2398,10 +2401,11 @@ reapprox:;
     //
     S->Bounds(umin, umax, vmin, vmax);
 
-    if (S->IsUPeriodic() && !C2d.IsNull()) {
+    if (S->IsUPeriodic() && !C2d.IsNull())
+    {
       // Recadre dans le domaine UV de la face
       Standard_Real period, U0, du, aEps; 
-      
+
       du =0.0;
       aEps=Precision::PConfusion();
       period = S->UPeriod();
@@ -2409,9 +2413,9 @@ reapprox:;
       U0=Pf.X();
       //
       gp_Pnt2d Pl = C2d->Value(l);
-      
+
       U0 = Min(Pl.X(), U0);
-//       while(U0-umin<aEps) { 
+      //       while(U0-umin<aEps) { 
       while(U0-umin<-aEps) { 
         U0+=period;
         du+=period;
@@ -2434,12 +2438,12 @@ reapprox:;
 //purpose  : 
 //=======================================================================
  void Parameters(const Handle(GeomAdaptor_HSurface)& HS1,
-                 const Handle(GeomAdaptor_HSurface)& HS2,
-                 const gp_Pnt& Ptref,
-                 Standard_Real& U1,
-                 Standard_Real& V1,
-                 Standard_Real& U2,
-                 Standard_Real& V2)
+                const Handle(GeomAdaptor_HSurface)& HS2,
+                const gp_Pnt& Ptref,
+                Standard_Real& U1,
+                Standard_Real& V1,
+                Standard_Real& U2,
+                Standard_Real& V2)
 {
 
   IntSurf_Quadric quad1,quad2;
@@ -2495,8 +2499,8 @@ reapprox:;
 //purpose  : 
 //=======================================================================
 Handle(Geom_Curve) MakeBSpline  (const Handle(IntPatch_WLine)& WL,
-                                 const Standard_Integer ideb,
-                                 const Standard_Integer ifin)
+                                const Standard_Integer ideb,
+                                const Standard_Integer ifin)
 {
   Standard_Integer i,nbpnt = ifin-ideb+1;
   TColgp_Array1OfPnt poles(1,nbpnt);
@@ -2519,9 +2523,9 @@ Handle(Geom_Curve) MakeBSpline  (const Handle(IntPatch_WLine)& WL,
 //purpose  : 
 //=======================================================================
 Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine,
-                                          const Standard_Integer ideb,
-                                          const Standard_Integer ifin,
-                                          const Standard_Boolean onFirst)
+                                         const Standard_Integer ideb,
+                                         const Standard_Integer ifin,
+                                         const Standard_Boolean onFirst)
 {
   Standard_Integer i, nbpnt = ifin-ideb+1;
   TColgp_Array1OfPnt2d poles(1,nbpnt);
@@ -2532,9 +2536,9 @@ Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine
   for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) {
       Standard_Real U, V;
       if(onFirst)
-        theWLine->Point(ipidebm1).ParametersOnS1(U, V);
+       theWLine->Point(ipidebm1).ParametersOnS1(U, V);
       else
-        theWLine->Point(ipidebm1).ParametersOnS2(U, V);
+       theWLine->Point(ipidebm1).ParametersOnS2(U, V);
       poles(i).SetCoord(U, V);
       mults(i) = 1;
       knots(i) = i-1;
@@ -2564,13 +2568,13 @@ Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine
       //
       aNbC=IntTools_Tools::SplitCurve(aIC, aSeqCvs);
       if (aNbC) {
-        for (j=1; j<=aNbC; ++j) {
-          const IntTools_Curve& aICNew=aSeqCvs(j);
-          aNewCvs.Append(aICNew);
-        }
+       for (j=1; j<=aNbC; ++j) {
+         const IntTools_Curve& aICNew=aSeqCvs(j);
+         aNewCvs.Append(aICNew);
+       }
       }
       else {
-        aNewCvs.Append(aIC);
+       aNewCvs.Append(aIC);
       }
     }
     else {
@@ -2590,21 +2594,21 @@ Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine
       //
       aCType1=aNewCvs(1).Type();
       if (aCType1==GeomAbs_Line) {
-        IntTools_SequenceOfCurves aSeqIn, aSeqOut;
-        //
-        for (i=1; i<=aNbCurves; ++i) {
-          const IntTools_Curve& aIC=aNewCvs(i);
-          aSeqIn.Append(aIC);
-        }
-        //
-        IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
-        //
-        aNewCvs.Clear();
-        aNbCurves=aSeqOut.Length(); 
-        for (i=1; i<=aNbCurves; ++i) {
-          const IntTools_Curve& aIC=aSeqOut(i);
-          aNewCvs.Append(aIC);
-        }
+       IntTools_SequenceOfCurves aSeqIn, aSeqOut;
+       //
+       for (i=1; i<=aNbCurves; ++i) {
+         const IntTools_Curve& aIC=aNewCvs(i);
+         aSeqIn.Append(aIC);
+       }
+       //
+       IntTools_Tools::RejectLines(aSeqIn, aSeqOut);
+       //
+       aNewCvs.Clear();
+       aNbCurves=aSeqOut.Length(); 
+       for (i=1; i<=aNbCurves; ++i) {
+         const IntTools_Curve& aIC=aSeqOut(i);
+         aNewCvs.Append(aIC);
+       }
       }
     }
   }// if ((aType1==GeomAbs_Plane && aType2==GeomAbs_Cone)...
@@ -2621,7 +2625,7 @@ Handle(Geom2d_BSplineCurve) MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine
 //function : CorrectSurfaceBoundaries
 //purpose  : 
 //=======================================================================
-void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
+ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
                               const Standard_Real theTolerance,
                               Standard_Real&      theumin,
                               Standard_Real&      theumax, 
@@ -2711,22 +2715,22 @@ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
       aXP=anAdaptorSurface.UPeriod();
       dXfact=theumax-theumin;
       if (dXfact-aTolPA>aXP) {
-        aXmid=0.5*(theumax+theumin);
-        aNbP=RealToInt(aXmid/aXP);
-        if (aXmid<0.) {
-          aNbP=aNbP-1;
-        }
-        aX1=aNbP*aXP;
-        if (theumin>aTolPA) {
-          aX1=theumin+aNbP*aXP;
-        }
-        aX2=aX1+aXP;
-        if (theumin<aX1) {
-          theumin=aX1;
-        }
-        if (theumax>aX2) {
-          theumax=aX2;
-        }
+       aXmid=0.5*(theumax+theumin);
+       aNbP=RealToInt(aXmid/aXP);
+       if (aXmid<0.) {
+         aNbP=aNbP-1;
+       }
+       aX1=aNbP*aXP;
+       if (theumin>aTolPA) {
+         aX1=theumin+aNbP*aXP;
+       }
+       aX2=aX1+aXP;
+       if (theumin<aX1) {
+         theumin=aX1;
+       }
+       if (theumax>aX2) {
+         theumax=aX2;
+       }
       }
     }
     // V
@@ -2734,22 +2738,22 @@ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
       aXP=anAdaptorSurface.VPeriod();
       dXfact=thevmax-thevmin;
       if (dXfact-aTolPA>aXP) {
-        aXmid=0.5*(thevmax+thevmin);
-        aNbP=RealToInt(aXmid/aXP);
-        if (aXmid<0.) {
-          aNbP=aNbP-1;
-        }
-        aX1=aNbP*aXP;
-        if (thevmin>aTolPA) {
-          aX1=thevmin+aNbP*aXP;
-        }
-        aX2=aX1+aXP;
-        if (thevmin<aX1) {
-          thevmin=aX1;
-        }
-        if (thevmax>aX2) {
-          thevmax=aX2;
-        }
+       aXmid=0.5*(thevmax+thevmin);
+       aNbP=RealToInt(aXmid/aXP);
+       if (aXmid<0.) {
+         aNbP=aNbP-1;
+       }
+       aX1=aNbP*aXP;
+       if (thevmin>aTolPA) {
+         aX1=thevmin+aNbP*aXP;
+       }
+       aX2=aX1+aXP;
+       if (thevmin<aX1) {
+         thevmin=aX1;
+       }
+       if (thevmax>aX2) {
+         thevmax=aX2;
+       }
       }
     }
   }
@@ -2763,43 +2767,43 @@ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
 
     for(anExp.Init(theFace, TopAbs_EDGE); anExp.More(); anExp.Next()) {
       if(BRep_Tool::IsClosed(TopoDS::Edge(anExp.Current()), theFace)) {
-        correct = Standard_True;
-        Standard_Real f, l;
-        TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
-        
-        for(Standard_Integer i = 0; i < 2; i++) {
-          if(i==0) {
-            anEdge.Orientation(TopAbs_FORWARD);
-          }
-          else {
-            anEdge.Orientation(TopAbs_REVERSED);
-          }
-          Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
-          
-          if(aCurve.IsNull()) {
-            correct = Standard_False;
-            break;
-          }
-          Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
-
-          if(aLine.IsNull()) {
-            correct = Standard_False;
-            break;
-          }
-          gp_Dir2d anUDir(1., 0.);
-          gp_Dir2d aVDir(0., 1.);
-          Standard_Real anAngularTolerance = Precision::Angular();
-
-          correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
-          correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
-          
-          gp_Pnt2d pp1 = aCurve->Value(f);
-          aBox.Add(pp1);
-          gp_Pnt2d pp2 = aCurve->Value(l);
-          aBox.Add(pp2);
-        }
-        if(!correct)
-          break;
+       correct = Standard_True;
+       Standard_Real f, l;
+       TopoDS_Edge anEdge = TopoDS::Edge(anExp.Current());
+       
+       for(Standard_Integer i = 0; i < 2; i++) {
+         if(i==0) {
+           anEdge.Orientation(TopAbs_FORWARD);
+         }
+         else {
+           anEdge.Orientation(TopAbs_REVERSED);
+         }
+         Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(anEdge, theFace, f, l);
+         
+         if(aCurve.IsNull()) {
+           correct = Standard_False;
+           break;
+         }
+         Handle(Geom2d_Line) aLine = Handle(Geom2d_Line)::DownCast(aCurve);
+
+         if(aLine.IsNull()) {
+           correct = Standard_False;
+           break;
+         }
+         gp_Dir2d anUDir(1., 0.);
+         gp_Dir2d aVDir(0., 1.);
+         Standard_Real anAngularTolerance = Precision::Angular();
+
+         correctU = correctU || aLine->Position().Direction().IsParallel(aVDir, anAngularTolerance);
+         correctV = correctV || aLine->Position().Direction().IsParallel(anUDir, anAngularTolerance);
+         
+         gp_Pnt2d pp1 = aCurve->Value(f);
+         aBox.Add(pp1);
+         gp_Pnt2d pp2 = aCurve->Value(l);
+         aBox.Add(pp2);
+       }
+       if(!correct)
+         break;
       }
     }
 
@@ -2808,20 +2812,20 @@ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
       aBox.Get(umin, vmin, umax, vmax);
 
       if(isuperiodic && correctU) {
-        
-        if(theumin < umin)
-          theumin = umin;
-        
-        if(theumax > umax) {
-          theumax = umax;
-        }
+       
+       if(theumin < umin)
+         theumin = umin;
+       
+       if(theumax > umax) {
+         theumax = umax;
+       }
       }
       if(isvperiodic && correctV) {
-        
-        if(thevmin < vmin)
-          thevmin = vmin;
-        if(thevmax > vmax)
-          thevmax = vmax;
+       
+       if(thevmin < vmin)
+         thevmin = vmin;
+       if(thevmax > vmax)
+         thevmax = vmax;
       }
     }
   }
@@ -2839,21 +2843,21 @@ void CorrectSurfaceBoundaries(const TopoDS_Face&  theFace,
 
 static
   Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
-                                     const Handle(Geom_Surface)& aS,
-                                     const Standard_Integer iDir);
+                                    const Handle(Geom_Surface)& aS,
+                                    const Standard_Integer iDir);
 static
   Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
-                                            const TopoDS_Face& aF1,
-                                            const TopoDS_Face& aF2);
+                                           const TopoDS_Face& aF1,
+                                           const TopoDS_Face& aF2);
 //=======================================================================
 //function :  NotUseSurfacesForApprox
 //purpose  : 
 //=======================================================================
 Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
-                                         const TopoDS_Face& aF2,
-                                         const Handle(IntPatch_WLine)& WL,
-                                         const Standard_Integer ifprm,
-                                         const Standard_Integer ilprm)
+                                        const TopoDS_Face& aF2,
+                                        const Handle(IntPatch_WLine)& WL,
+                                        const Standard_Integer ifprm,
+                                        const Standard_Integer ilprm)
 {
   Standard_Boolean bPInDZ;
 
@@ -2875,9 +2879,9 @@ Standard_Boolean NotUseSurfacesForApprox(const TopoDS_Face& aF1,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
-                                          const TopoDS_Face& aF1,
-                                          const TopoDS_Face& aF2)
-                                          
+                                         const TopoDS_Face& aF1,
+                                         const TopoDS_Face& aF2)
+                                         
 {
   Standard_Boolean bFlag=Standard_True;
   Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22;
@@ -2960,8 +2964,8 @@ Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d,
-                                   const Handle(Geom_Surface)& aS,
-                                   const Standard_Integer iDir)
+                                  const Handle(Geom_Surface)& aS,
+                                  const Standard_Integer iDir)
 {
   Standard_Boolean bFlag=Standard_True;
   Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD;
@@ -3072,26 +3076,26 @@ Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine
     while(k <= anEndIndex) {
       
       if(i != k) {
-        IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
-        IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
-        
-        if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
-          aTmpWLine = aLocalWLine;
-          aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
-
-          for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
-            IntPatch_Point aVertex = aTmpWLine->Vertex(v);
-            Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
-
-            if(avertexindex >= k) {
-              aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
-            }
-            aLocalWLine->AddVertex(aVertex);
-          }
-          aLineOn2S->RemovePoint(k);
-          anEndIndex--;
-          continue;
-        }
+       IntSurf_PntOn2S p1 = aLineOn2S->Value(i);
+       IntSurf_PntOn2S p2 = aLineOn2S->Value(k);
+       
+       if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) {
+         aTmpWLine = aLocalWLine;
+         aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False);
+
+         for(v = 1; v <= aTmpWLine->NbVertex(); v++) {
+           IntPatch_Point aVertex = aTmpWLine->Vertex(v);
+           Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine();
+
+           if(avertexindex >= k) {
+             aVertex.SetParameter(aVertex.ParameterOnLine() - 1.);
+           }
+           aLocalWLine->AddVertex(aVertex);
+         }
+         aLineOn2S->RemovePoint(k);
+         anEndIndex--;
+         continue;
+       }
       }
       k++;
     }
@@ -3108,8 +3112,8 @@ Handle(IntPatch_WLine) ComputePurgedWLine(const Handle(IntPatch_WLine)& theWLine
 //purpose  : 
 //=======================================================================
 void TolR3d(const TopoDS_Face& aF1,
-            const TopoDS_Face& aF2,
-            Standard_Real& myTolReached3d)
+           const TopoDS_Face& aF2,
+           Standard_Real& myTolReached3d)
 {
   Standard_Real aTolF1, aTolF2, aTolFMax, aTolTresh;
       
@@ -3127,10 +3131,10 @@ void TolR3d(const TopoDS_Face& aF1,
 //purpose  : 
 //=======================================================================
 Standard_Real AdjustPeriodic(const Standard_Real theParameter,
-                             const Standard_Real parmin,
-                             const Standard_Real parmax,
-                             const Standard_Real thePeriod,
-                             Standard_Real&      theOffset) 
+                            const Standard_Real parmin,
+                            const Standard_Real parmax,
+                            const Standard_Real thePeriod,
+                            Standard_Real&      theOffset) 
 {
   Standard_Real aresult;
   //
@@ -3152,10 +3156,10 @@ Standard_Real AdjustPeriodic(const Standard_Real theParameter,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
-                                   const Standard_Real theFirstBoundary,
-                                   const Standard_Real theSecondBoundary,
-                                   const Standard_Real theResolution,
-                                   Standard_Boolean&   IsOnFirstBoundary) 
+                                  const Standard_Real theFirstBoundary,
+                                  const Standard_Real theSecondBoundary,
+                                  const Standard_Real theResolution,
+                                  Standard_Boolean&   IsOnFirstBoundary) 
 {
   Standard_Boolean bRet;
   Standard_Integer i;
@@ -3181,12 +3185,12 @@ Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter,
 // purpose:
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
-                           const gp_Pnt2d&     theLastPoint,
-                           const Standard_Real theUmin, 
-                           const Standard_Real theUmax,
-                           const Standard_Real theVmin,
-                           const Standard_Real theVmax,
-                           gp_Pnt2d&           theNewPoint) {
+                          const gp_Pnt2d&     theLastPoint,
+                          const Standard_Real theUmin, 
+                          const Standard_Real theUmax,
+                          const Standard_Real theVmin,
+                          const Standard_Real theVmax,
+                          gp_Pnt2d&           theNewPoint) {
   
   gp_Vec2d aVec(theFirstPoint, theLastPoint);
   Standard_Integer i = 0, j = 0;
@@ -3203,9 +3207,9 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
       anOtherVecNormal.SetY(0.);
 
       if(i < 2)
-        aprojpoint.SetX(theUmin);
+       aprojpoint.SetX(theUmin);
       else
-        aprojpoint.SetX(theUmax);
+       aprojpoint.SetX(theUmax);
     }
     else {
       anOtherVec.SetX(1.);
@@ -3214,9 +3218,9 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
       anOtherVecNormal.SetY(1.);
 
       if(i < 2)
-        aprojpoint.SetY(theVmin);
+       aprojpoint.SetY(theVmin);
       else
-        aprojpoint.SetY(theVmax);
+       aprojpoint.SetY(theVmax);
     }
     gp_Vec2d anormvec = aVec;
     anormvec.Normalize();
@@ -3243,7 +3247,7 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
       gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset));
       gp_Vec2d acurvec(theLastPoint, acurpoint);
       if ( bIsOut )
-        acurvec.Reverse();
+       acurvec.Reverse();
 
       Standard_Real aDotX, anAngleX;
       //
@@ -3251,20 +3255,20 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
       anAngleX = aVec.Angle(acurvec);
       //
       if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) {
-        if((i % 2) == 0) {
-          if((acurpoint.Y() >= theVmin) &&
-             (acurpoint.Y() <= theVmax)) {
-            theNewPoint = acurpoint;
-            return Standard_True;
-          }
-        }
-        else {
-          if((acurpoint.X() >= theUmin) &&
-             (acurpoint.X() <= theUmax)) {
-            theNewPoint = acurpoint;
-            return Standard_True;
-          }
-        }
+       if((i % 2) == 0) {
+         if((acurpoint.Y() >= theVmin) &&
+            (acurpoint.Y() <= theVmax)) {
+           theNewPoint = acurpoint;
+           return Standard_True;
+         }
+       }
+       else {
+         if((acurpoint.X() >= theUmin) &&
+            (acurpoint.X() <= theUmax)) {
+           theNewPoint = acurpoint;
+           return Standard_True;
+         }
+       }
       }
     }
   }
@@ -3277,15 +3281,15 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
 // purpose: Find point on the boundary of radial tangent zone
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
-                           const gp_Pnt2d&     theLastPoint,
-                           const Standard_Real theUmin, 
-                           const Standard_Real theUmax,
-                           const Standard_Real theVmin,
-                           const Standard_Real theVmax,
-                           const gp_Pnt2d&     theTanZoneCenter,
-                           const Standard_Real theZoneRadius,
-                           Handle(GeomAdaptor_HSurface) theGASurface,
-                           gp_Pnt2d&           theNewPoint) {
+                          const gp_Pnt2d&     theLastPoint,
+                          const Standard_Real theUmin, 
+                          const Standard_Real theUmax,
+                          const Standard_Real theVmin,
+                          const Standard_Real theVmax,
+                          const gp_Pnt2d&     theTanZoneCenter,
+                          const Standard_Real theZoneRadius,
+                          Handle(GeomAdaptor_HSurface) theGASurface,
+                          gp_Pnt2d&           theNewPoint) {
   theNewPoint = theLastPoint;
 
   if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) )
@@ -3326,9 +3330,9 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
     gp_Pnt2d aPInt = anIntersector.Point( i );
     if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) {
       if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) &&
-           ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
-        theNewPoint = aPInt;
-        aFound = Standard_True;
+          ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) {
+       theNewPoint = aPInt;
+       aFound = Standard_True;
       }
     }
   }
@@ -3341,9 +3345,9 @@ Standard_Boolean FindPoint(const gp_Pnt2d&     theFirstPoint,
 // purpose: Check if point is inside a radial tangent zone
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean IsInsideTanZone(const gp_Pnt2d&     thePoint,
-                                 const gp_Pnt2d&     theTanZoneCenter,
-                                 const Standard_Real theZoneRadius,
-                                 Handle(GeomAdaptor_HSurface) theGASurface) {
+                                const gp_Pnt2d&     theTanZoneCenter,
+                                const Standard_Real theZoneRadius,
+                                Handle(GeomAdaptor_HSurface) theGASurface) {
 
   Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius );
   Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius );
@@ -3359,7 +3363,7 @@ Standard_Boolean IsInsideTanZone(const gp_Pnt2d&     thePoint,
 // purpose: Check if tangent zone exists
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& theSurface1,
-                                        const Handle(GeomAdaptor_HSurface)&  theSurface2 ) 
+                                       const Handle(GeomAdaptor_HSurface)&  theSurface2 ) 
 {
   if ( ( theSurface1->GetType() != GeomAbs_Torus ) ||
       ( theSurface2->GetType() != GeomAbs_Torus ) )
@@ -3386,12 +3390,12 @@ Standard_Boolean CheckTangentZonesExist( const Handle(GeomAdaptor_HSurface)& the
 // purpose: 
 // ------------------------------------------------------------------------------------------------
 Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1,
-                                     const Handle(GeomAdaptor_HSurface)&  theSurface2,
-                                     const TopoDS_Face&                   theFace1,
-                                     const TopoDS_Face&                   theFace2,
-                                     Handle(TColgp_HArray1OfPnt2d)&       theResultOnS1,
-                                     Handle(TColgp_HArray1OfPnt2d)&       theResultOnS2,
-                                     Handle(TColStd_HArray1OfReal)&       theResultRadius,
+                                    const Handle(GeomAdaptor_HSurface)&  theSurface2,
+                                    const TopoDS_Face&                   theFace1,
+                                    const TopoDS_Face&                   theFace2,
+                                    Handle(TColgp_HArray1OfPnt2d)&       theResultOnS1,
+                                    Handle(TColgp_HArray1OfPnt2d)&       theResultOnS2,
+                                    Handle(TColStd_HArray1OfReal)&       theResultRadius,
                                      const Handle(BOPInt_Context)& aContext)
 {
   Standard_Integer aResult = 0;
@@ -3454,80 +3458,80 @@ Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSur
     GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) );
     GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) );
     Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI, 
-                            Precision::PConfusion(), Precision::PConfusion());
-            
+                           Precision::PConfusion(), Precision::PConfusion());
+       
     if ( anExtrema.IsDone() ) {
 
       Standard_Integer i = 0;
       for ( i = 1; i <= anExtrema.NbExt(); i++ ) {
-        if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
-          continue;
-
-        Extrema_POnCurv P1, P2;
-        anExtrema.Points( i, P1, P2 );
-
-        Standard_Boolean bFoundResult = Standard_True;
-        gp_Pnt2d pr1, pr2;
-
-        Standard_Integer surfit = 0;
-        for ( surfit = 0; surfit < 2; surfit++ ) {
-          GeomAPI_ProjectPointOnSurf& aProjector = 
-            (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
-
-          gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
-          aProjector.Perform(aP3d);
-
-          if(!aProjector.IsDone())
-            bFoundResult = Standard_False;
-          else {
-            if(aProjector.LowerDistance() > aCriteria) {
-              bFoundResult = Standard_False;
-            }
-            else {
-              Standard_Real foundU = 0, foundV = 0;
-              aProjector.LowerDistanceParameters(foundU, foundV);
-              if ( surfit == 0 )
-                pr1 = gp_Pnt2d( foundU, foundV );
-              else
-                pr2 = gp_Pnt2d( foundU, foundV );
-            }
-          }
-        }
-        if ( bFoundResult ) {
-          aSeqResultS1.Append( pr1 );
-          aSeqResultS2.Append( pr2 );
-          aSeqResultRad.Append( aCriteria );
-
-          // torus is u and v periodic
-          const Standard_Real twoPI = M_PI + M_PI;
-          Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
-          Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
-
-          // iteration on period bounds
-          for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
-            Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
-            Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
-
-            // iteration on surfaces
-            for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
-              Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
-              Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
-              TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2; 
-              TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2; 
-
-              if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
-                aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
-                aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
-                aSeqResultRad.Append( aCriteria );
-              }
-              if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
-                aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
-                aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
-                aSeqResultRad.Append( aCriteria );
-              }
-            }
-          } //
-        }
+       if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria )
+         continue;
+
+       Extrema_POnCurv P1, P2;
+       anExtrema.Points( i, P1, P2 );
+
+       Standard_Boolean bFoundResult = Standard_True;
+       gp_Pnt2d pr1, pr2;
+
+       Standard_Integer surfit = 0;
+       for ( surfit = 0; surfit < 2; surfit++ ) {
+         GeomAPI_ProjectPointOnSurf& aProjector = 
+           (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
+
+         gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value();
+         aProjector.Perform(aP3d);
+
+         if(!aProjector.IsDone())
+           bFoundResult = Standard_False;
+         else {
+           if(aProjector.LowerDistance() > aCriteria) {
+             bFoundResult = Standard_False;
+           }
+           else {
+             Standard_Real foundU = 0, foundV = 0;
+             aProjector.LowerDistanceParameters(foundU, foundV);
+             if ( surfit == 0 )
+               pr1 = gp_Pnt2d( foundU, foundV );
+             else
+               pr2 = gp_Pnt2d( foundU, foundV );
+           }
+         }
+       }
+       if ( bFoundResult ) {
+         aSeqResultS1.Append( pr1 );
+         aSeqResultS2.Append( pr2 );
+         aSeqResultRad.Append( aCriteria );
+
+         // torus is u and v periodic
+         const Standard_Real twoPI = M_PI + M_PI;
+         Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()};
+         Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()};
+
+         // iteration on period bounds
+         for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) {
+           Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI;
+           Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI;
+
+           // iteration on surfaces
+           for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) {
+             Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp;
+             Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp;
+             TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2; 
+             TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2; 
+
+             if (fabs(arr1[0] - aBound) < Precision::PConfusion()) {
+               aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) );
+               aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
+               aSeqResultRad.Append( aCriteria );
+             }
+             if (fabs(arr1[1] - aBound) < Precision::PConfusion()) {
+               aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) );
+               aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) );
+               aSeqResultRad.Append( aCriteria );
+             }
+           }
+         } //
+       }
       }
     }
   }
@@ -3552,8 +3556,8 @@ Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSur
 // purpose:
 // ------------------------------------------------------------------------------------------------
 gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d&     theaNeighbourPoint,
-                           const gp_Pnt2d&     theOriginalPoint,
-                           Handle(GeomAdaptor_HSurface) theGASurface) {
+                          const gp_Pnt2d&     theOriginalPoint,
+                          Handle(GeomAdaptor_HSurface) theGASurface) {
   
   gp_Pnt2d ap1 = theaNeighbourPoint;
   gp_Pnt2d ap2 = theOriginalPoint;
@@ -3568,8 +3572,8 @@ gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d&     theaNeighbourPoint,
       Standard_Real dd = ap1.SquareDistance( aPTest );
 
       if ( dd < aSqDistMin ) {
-        ap2 = aPTest;
-        aSqDistMin = dd;
+       ap2 = aPTest;
+       aSqDistMin = dd;
       }
     }
   }
@@ -3583,8 +3587,8 @@ gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d&     theaNeighbourPoint,
       Standard_Real dd = ap1.SquareDistance( aPTest );
 
       if ( dd < aSqDistMin ) {
-        ap2 = aPTest;
-        aSqDistMin = dd;
+       ap2 = aPTest;
+       aSqDistMin = dd;
       }
     }
   }
@@ -3596,14 +3600,14 @@ gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d&     theaNeighbourPoint,
 // purpose:
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
-                                      const Handle(GeomAdaptor_HSurface)&            theSurface1, 
-                                      const Handle(GeomAdaptor_HSurface)&            theSurface2,
-                                      const TopoDS_Face&                             theFace1,
-                                      const TopoDS_Face&                             theFace2,
-                                      const IntTools_LineConstructor&                theLConstructor,
-                                      const Standard_Boolean                         theAvoidLConstructor,
-                                      IntPatch_SequenceOfLine&                       theNewLines,
-                                      Standard_Real&                                 theReachedTol3d,
+                                     const Handle(GeomAdaptor_HSurface)&            theSurface1, 
+                                     const Handle(GeomAdaptor_HSurface)&            theSurface2,
+                                     const TopoDS_Face&                             theFace1,
+                                     const TopoDS_Face&                             theFace2,
+                                     const IntTools_LineConstructor&                theLConstructor,
+                                     const Standard_Boolean                         theAvoidLConstructor,
+                                     IntPatch_SequenceOfLine&                       theNewLines,
+                                     Standard_Real&                                 theReachedTol3d,
                                       const Handle(BOPInt_Context)& aContext) 
 {
 
@@ -3635,7 +3639,7 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
   Handle(TColgp_HArray1OfPnt2d) aTanZoneS2;
   Handle(TColStd_HArray1OfReal) aTanZoneRadius;
   Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2,
-                                                 aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
+                                                aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext);
   
   //
   nblines=0;
@@ -3661,83 +3665,83 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
       Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2;
       aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
       if(!i) {
-        aPoint.ParametersOnS1(U, V);
+       aPoint.ParametersOnS1(U, V);
       }
       else {
-        aPoint.ParametersOnS2(U, V);
+       aPoint.ParametersOnS2(U, V);
       }
       // U, V
       for(j = 0; j < 2; j++) {
-        isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
-        if(!isperiodic){
-          continue;
-        }
-        //
-        if (!j) {
-          aResolution=aGASurface->UResolution(aTol);
-          aPeriod=aGASurface->UPeriod();
-          alowerboundary=umin;
-          aupperboundary=umax;
-          aParameter=U;
-        }
-        else {
-          aResolution=aGASurface->VResolution(aTol);
-          aPeriod=aGASurface->VPeriod();
-          alowerboundary=vmin;
-          aupperboundary=vmax;
-          aParameter=V;
-        }
-        
-        anoffset = 0.;
-        anAdjustPar = AdjustPeriodic(aParameter, 
-                                     alowerboundary, 
-                                     aupperboundary, 
-                                     aPeriod, 
-                                     anoffset);
-        //
-        bIsOnFirstBoundary = Standard_True;// ?
-        bIsPointOnBoundary=
-          IsPointOnBoundary(anAdjustPar, 
-                            alowerboundary, 
-                            aupperboundary,
-                            aResolution, 
-                            bIsOnFirstBoundary);
-        //
-        if(bIsPointOnBoundary) {
-          bIsCurrentPointOnBoundary = Standard_True;
-          break;
-        }
-        else {
-          // check if a point belong to a tangent zone. Begin
-          Standard_Integer zIt = 0;
-          for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
-            gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
-            Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
-
-            if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
-              // set boundary flag to split the curve by a tangent zone
-              bIsPointOnBoundary = Standard_True;
-              bIsCurrentPointOnBoundary = Standard_True;
-              if ( theReachedTol3d < aZoneRadius ) {
-                theReachedTol3d = aZoneRadius;
-              }
-              break;
-            }
-          }
-        }
+       isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
+       if(!isperiodic){
+         continue;
+       }
+       //
+       if (!j) {
+         aResolution=aGASurface->UResolution(aTol);
+         aPeriod=aGASurface->UPeriod();
+         alowerboundary=umin;
+         aupperboundary=umax;
+         aParameter=U;
+       }
+       else {
+         aResolution=aGASurface->VResolution(aTol);
+         aPeriod=aGASurface->VPeriod();
+         alowerboundary=vmin;
+         aupperboundary=vmax;
+         aParameter=V;
+       }
+       
+       anoffset = 0.;
+       anAdjustPar = AdjustPeriodic(aParameter, 
+                                    alowerboundary, 
+                                    aupperboundary, 
+                                    aPeriod, 
+                                    anoffset);
+       //
+       bIsOnFirstBoundary = Standard_True;// ?
+       bIsPointOnBoundary=
+         IsPointOnBoundary(anAdjustPar, 
+                           alowerboundary, 
+                           aupperboundary,
+                           aResolution, 
+                           bIsOnFirstBoundary);
+       //
+       if(bIsPointOnBoundary) {
+         bIsCurrentPointOnBoundary = Standard_True;
+         break;
+       }
+       else {
+         // check if a point belong to a tangent zone. Begin
+         Standard_Integer zIt = 0;
+         for ( zIt = 1; zIt <= aNbZone; zIt++ ) {
+           gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
+           Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
+
+           if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) {
+             // set boundary flag to split the curve by a tangent zone
+             bIsPointOnBoundary = Standard_True;
+             bIsCurrentPointOnBoundary = Standard_True;
+             if ( theReachedTol3d < aZoneRadius ) {
+               theReachedTol3d = aZoneRadius;
+             }
+             break;
+           }
+         }
+       }
       }//for(j = 0; j < 2; j++) {
 
       if(bIsCurrentPointOnBoundary){
-        break;
+       break;
       }
     }//for(i = 0; i < 2; ++i) {
     //
     if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) {
       if(!aListOfPointIndex.IsEmpty()) {
-        nblines++;
-        anArrayOfLines.SetValue(nblines, aListOfPointIndex);
-        anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
-        aListOfPointIndex.Clear();
+       nblines++;
+       anArrayOfLines.SetValue(nblines, aListOfPointIndex);
+       anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary);
+       aListOfPointIndex.Clear();
       }
       bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary;
     }
@@ -3774,10 +3778,10 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
       Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1);
 
       if((aneighbourindex < 1) || (aneighbourindex > nblines))
-        continue;
+       continue;
 
       if(anArrayOfLineType.Value(aneighbourindex) == 0)
-        continue;
+       continue;
       const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex);
       Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First();
       const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex);
@@ -3786,355 +3790,355 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
       
       for(Standard_Integer surfit = 0; surfit < 2; surfit++) {
 
-        Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
-        Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
-        aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
-        Standard_Real U=0., V=0.;
+       Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2;
+       Standard_Real umin=0., umax=0., vmin=0., vmax=0.;
+       aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax);
+       Standard_Real U=0., V=0.;
 
-        if(surfit == 0)
-          aNewP.ParametersOnS1(U, V);
-        else
-          aNewP.ParametersOnS2(U, V);
-        Standard_Integer nbboundaries = 0;
+       if(surfit == 0)
+         aNewP.ParametersOnS1(U, V);
+       else
+         aNewP.ParametersOnS2(U, V);
+       Standard_Integer nbboundaries = 0;
 
-        Standard_Boolean bIsNearBoundary = Standard_False;
-        Standard_Integer aZoneIndex = 0;
-        Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
-        Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
-        
+       Standard_Boolean bIsNearBoundary = Standard_False;
+       Standard_Integer aZoneIndex = 0;
+       Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1
+       Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1
+       
 
-        for(Standard_Integer parit = 0; parit < 2; parit++) {
-          Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
+       for(Standard_Integer parit = 0; parit < 2; parit++) {
+         Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
 
-          Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
-          Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
-          Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
+         Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol);
+         Standard_Real alowerboundary = (parit == 0) ? umin : vmin;
+         Standard_Real aupperboundary = (parit == 0) ? umax : vmax;
 
-          Standard_Real aParameter = (parit == 0) ? U : V;
-          Standard_Boolean bIsOnFirstBoundary = Standard_True;
+         Standard_Real aParameter = (parit == 0) ? U : V;
+         Standard_Boolean bIsOnFirstBoundary = Standard_True;
   
-          if(!isperiodic) {
-            bIsPointOnBoundary=
-              IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
-            if(bIsPointOnBoundary) {
-              bIsUBoundary = (parit == 0);
-              bIsFirstBoundary = bIsOnFirstBoundary;
-              nbboundaries++;
-            }
-          }
-          else {
-            Standard_Real aPeriod     = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
-            Standard_Real anoffset = 0.;
-            Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
-
-            bIsPointOnBoundary=
-              IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
-            if(bIsPointOnBoundary) {
-              bIsUBoundary = (parit == 0);
-              bIsFirstBoundary = bIsOnFirstBoundary;
-              nbboundaries++;
-            }
-            else {
-              //check neighbourhood of boundary
-              Standard_Real anEpsilon = aResolution * 100.;
-              Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
-              anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
-                
-              bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, 
-                                                  anEpsilon, bIsOnFirstBoundary);
-
-            }
-          }
-        }
-
-        // check if a point belong to a tangent zone. Begin
-        for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
-          gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
-          Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
-
-          Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
-          const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
-          Standard_Real nU1, nV1;
-            
-          if(surfit == 0)
-            aNeighbourPoint.ParametersOnS1(nU1, nV1);
-          else
-            aNeighbourPoint.ParametersOnS2(nU1, nV1);
-          gp_Pnt2d ap1(nU1, nV1);
-          gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
-
-
-          if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
-            aZoneIndex = zIt;
-            bIsNearBoundary = Standard_True;
-            if ( theReachedTol3d < aZoneRadius ) {
-              theReachedTol3d = aZoneRadius;
-            }
-          }
-        }
-        // check if a point belong to a tangent zone. End
-        Standard_Boolean bComputeLineEnd = Standard_False;
-
-        if(nbboundaries == 2) {
-          //xf
-          bComputeLineEnd = Standard_True;
-          //xt
-        }
-        else if(nbboundaries == 1) {
-          Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
-
-          if(isperiodic) {
-            Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
-            Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
-            Standard_Real aPeriod     = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
-            Standard_Real aParameter = (bIsUBoundary) ? U : V;
-            Standard_Real anoffset = 0.;
-            Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
-
-            Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
-            Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
-            anotherPar += anoffset;
-            Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
-            const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
-            Standard_Real nU1, nV1;
-
-            if(surfit == 0)
-              aNeighbourPoint.ParametersOnS1(nU1, nV1);
-            else
-              aNeighbourPoint.ParametersOnS2(nU1, nV1);
-            
-            Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
-            Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
-            bComputeLineEnd = Standard_True;
-            Standard_Boolean bCheckAngle1 = Standard_False;
-            Standard_Boolean bCheckAngle2 = Standard_False;
-            gp_Vec2d aNewVec;
-            Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
-            Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
-
-            if(((adist1 - adist2) > Precision::PConfusion()) && 
-               (adist2 < (aPeriod / 4.))) {
-              bCheckAngle1 = Standard_True;
-              aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
-
-              if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
-                aNewP.SetValue((surfit == 0), anewU, anewV);
-                bCheckAngle1 = Standard_False;
-              }
-            }
-            else if(adist1 < (aPeriod / 4.)) {
-              bCheckAngle2 = Standard_True;
-              aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
-
-              if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
-                bCheckAngle2 = Standard_False;
-              }
-            }
-
-            if(bCheckAngle1 || bCheckAngle2) {
-              // assume there are at least two points in line (see "if" above)
-              Standard_Integer anindexother = aneighbourpointindex;
-
-              while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
-                anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
-                const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
-                Standard_Real nU2, nV2;
-                
-                if(surfit == 0)
-                  aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
-                else
-                  aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
-                gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
-
-                if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
-                  continue;
-                }
-                else {
-                  Standard_Real anAngle = aNewVec.Angle(aVecOld);
-
-                  if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
-
-                    if(bCheckAngle1) {
-                      Standard_Real U1, U2, V1, V2;
-                      IntSurf_PntOn2S atmppoint = aNewP;
-                      atmppoint.SetValue((surfit == 0), anewU, anewV);
-                      atmppoint.Parameters(U1, V1, U2, V2);
-                      gp_Pnt P1 = theSurface1->Value(U1, V1);
-                      gp_Pnt P2 = theSurface2->Value(U2, V2);
-                      gp_Pnt P0 = aPoint.Value();
-
-                      if(P0.IsEqual(P1, aTol) &&
-                         P0.IsEqual(P2, aTol) &&
-                         P1.IsEqual(P2, aTol)) {
-                        bComputeLineEnd = Standard_False;
-                        aNewP.SetValue((surfit == 0), anewU, anewV);
-                      }
-                    }
-
-                    if(bCheckAngle2) {
-                      bComputeLineEnd = Standard_False;
-                    }
-                  }
-                  break;
-                }
-              } // end while(anindexother...)
-            }
-          }
-        }
-        else if ( bIsNearBoundary ) {
-          bComputeLineEnd = Standard_True;
-        }
-
-        if(bComputeLineEnd) {
-
-          gp_Pnt2d anewpoint;
-          Standard_Boolean found = Standard_False;
-
-          if ( bIsNearBoundary ) {
-            // re-compute point near natural boundary or near tangent zone
-            Standard_Real u1, v1, u2, v2;
-            aNewP.Parameters( u1, v1, u2, v2 );
-            if(surfit == 0)
-              anewpoint = gp_Pnt2d( u1, v1 );
-            else
-              anewpoint = gp_Pnt2d( u2, v2 );
-            
-            Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
-            const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
-            Standard_Real nU1, nV1;
-            
-            if(surfit == 0)
-              aNeighbourPoint.ParametersOnS1(nU1, nV1);
-            else
-              aNeighbourPoint.ParametersOnS2(nU1, nV1);
-            gp_Pnt2d ap1(nU1, nV1);
-            gp_Pnt2d ap2;
-
-
-            if ( aZoneIndex ) {
-              // exclude point from a tangent zone
-              anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
-              gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
-              Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
-
-              if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax, 
-                             aPZone, aZoneRadius, aGASurface, ap2) ) {
-                anewpoint = ap2;
-                found = Standard_True;
-              }
-            }
-            else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
-              // re-compute point near boundary if shifted on a period
-              ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
-
-              if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
-                  ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
-                found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
-              }
-              else {
-                anewpoint = ap2;
-                aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
-              }
-            }
-          }
-          else {
-
-            Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
-            const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
-            Standard_Real nU1, nV1;
-
-            if(surfit == 0)
-              aNeighbourPoint.ParametersOnS1(nU1, nV1);
-            else
-              aNeighbourPoint.ParametersOnS2(nU1, nV1);
-            gp_Pnt2d ap1(nU1, nV1);
-            gp_Pnt2d ap2(nU1, nV1);
-            Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
-
-            while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
-              aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
-              const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
-              Standard_Real nU2, nV2;
-
-              if(surfit == 0)
-                aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
-              else
-                aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
-              ap2.SetX(nU2);
-              ap2.SetY(nV2);
-
-              if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
-                break;
-              }
-            }  
-            found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
-          }
-
-          if(found) {
-            // check point
-            Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
-            GeomAPI_ProjectPointOnSurf& aProjector = 
-              (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
-            Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
-
-            Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
-
-            gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
-            aProjector.Perform(aP3d);
-
-            if(aProjector.IsDone()) {
-              if(aProjector.LowerDistance() < aCriteria) {
-                Standard_Real foundU = U, foundV = V;
-                aProjector.LowerDistanceParameters(foundU, foundV);
-
-                //Correction of projected coordinates. Begin
-                //Note, it may be shifted on a period
-                Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
-                const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
-                Standard_Real nUn, nVn;
-                
-                if(surfit == 0)
-                  aNeighbourPoint.ParametersOnS2(nUn, nVn);
-                else
-                  aNeighbourPoint.ParametersOnS1(nUn, nVn);
-                gp_Pnt2d aNeighbour2d(nUn, nVn);
-                gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
-                foundU = anAdjustedPoint.X();
-                foundV = anAdjustedPoint.Y();
-
-                if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
-                    ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
-                  // attempt to roughly re-compute point
-                  foundU = ( foundU < umin ) ? umin : foundU;
-                  foundU = ( foundU > umax ) ? umax : foundU;
-                  foundV = ( foundV < vmin ) ? vmin : foundV;
-                  foundV = ( foundV > vmax ) ? vmax : foundV;
-
-                  GeomAPI_ProjectPointOnSurf& aProjector2 = 
-                    (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
-
-                  aP3d = aSurfaceOther->Value(foundU, foundV);
-                  aProjector2.Perform(aP3d);
-                  
-                  if(aProjector2.IsDone()) {
-                    if(aProjector2.LowerDistance() < aCriteria) {
-                      Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
-                      aProjector2.LowerDistanceParameters(foundU2, foundV2);
-                      anewpoint.SetX(foundU2);
-                      anewpoint.SetY(foundV2);
-                    }
-                  }
-                }
-                //Correction of projected coordinates. End
-
-                if(surfit == 0)
-                  aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
-                else
-                  aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
-              }
-            }
-          }
-        }
+         if(!isperiodic) {
+           bIsPointOnBoundary=
+             IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
+           if(bIsPointOnBoundary) {
+             bIsUBoundary = (parit == 0);
+             bIsFirstBoundary = bIsOnFirstBoundary;
+             nbboundaries++;
+           }
+         }
+         else {
+           Standard_Real aPeriod     = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod();
+           Standard_Real anoffset = 0.;
+           Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
+
+           bIsPointOnBoundary=
+             IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary);
+           if(bIsPointOnBoundary) {
+             bIsUBoundary = (parit == 0);
+             bIsFirstBoundary = bIsOnFirstBoundary;
+             nbboundaries++;
+           }
+           else {
+             //check neighbourhood of boundary
+             Standard_Real anEpsilon = aResolution * 100.;
+             Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1;
+             anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon;
+               
+             bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, 
+                                                 anEpsilon, bIsOnFirstBoundary);
+
+           }
+         }
+       }
+
+       // check if a point belong to a tangent zone. Begin
+       for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) {
+         gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt);
+         Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt);
+
+         Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+         const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+         Standard_Real nU1, nV1;
+           
+         if(surfit == 0)
+           aNeighbourPoint.ParametersOnS1(nU1, nV1);
+         else
+           aNeighbourPoint.ParametersOnS2(nU1, nV1);
+         gp_Pnt2d ap1(nU1, nV1);
+         gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface );
+
+
+         if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) {
+           aZoneIndex = zIt;
+           bIsNearBoundary = Standard_True;
+           if ( theReachedTol3d < aZoneRadius ) {
+             theReachedTol3d = aZoneRadius;
+           }
+         }
+       }
+       // check if a point belong to a tangent zone. End
+       Standard_Boolean bComputeLineEnd = Standard_False;
+
+       if(nbboundaries == 2) {
+         //xf
+         bComputeLineEnd = Standard_True;
+         //xt
+       }
+       else if(nbboundaries == 1) {
+         Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic();
+
+         if(isperiodic) {
+           Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin;
+           Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax;
+           Standard_Real aPeriod     = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod();
+           Standard_Real aParameter = (bIsUBoundary) ? U : V;
+           Standard_Real anoffset = 0.;
+           Standard_Real anAdjustPar = AdjustPeriodic(aParameter, alowerboundary, aupperboundary, aPeriod, anoffset);
+
+           Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary);
+           Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist);
+           anotherPar += anoffset;
+           Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+           const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex);
+           Standard_Real nU1, nV1;
+
+           if(surfit == 0)
+             aNeighbourPoint.ParametersOnS1(nU1, nV1);
+           else
+             aNeighbourPoint.ParametersOnS2(nU1, nV1);
+           
+           Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V);
+           Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar);
+           bComputeLineEnd = Standard_True;
+           Standard_Boolean bCheckAngle1 = Standard_False;
+           Standard_Boolean bCheckAngle2 = Standard_False;
+           gp_Vec2d aNewVec;
+           Standard_Real anewU = (bIsUBoundary) ? anotherPar : U;
+           Standard_Real anewV = (bIsUBoundary) ? V : anotherPar;
+
+           if(((adist1 - adist2) > Precision::PConfusion()) && 
+              (adist2 < (aPeriod / 4.))) {
+             bCheckAngle1 = Standard_True;
+             aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV));
+
+             if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
+               aNewP.SetValue((surfit == 0), anewU, anewV);
+               bCheckAngle1 = Standard_False;
+             }
+           }
+           else if(adist1 < (aPeriod / 4.)) {
+             bCheckAngle2 = Standard_True;
+             aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V));
+
+             if(aNewVec.SquareMagnitude() < (gp::Resolution() * gp::Resolution())) {
+               bCheckAngle2 = Standard_False;
+             }
+           }
+
+           if(bCheckAngle1 || bCheckAngle2) {
+             // assume there are at least two points in line (see "if" above)
+             Standard_Integer anindexother = aneighbourpointindex;
+
+             while((anindexother <= aListOfIndex.Last()) && (anindexother >= aListOfIndex.First())) {
+               anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1);
+               const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother);
+               Standard_Real nU2, nV2;
+               
+               if(surfit == 0)
+                 aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
+               else
+                 aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
+               gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1));
+
+               if(aVecOld.SquareMagnitude() <= (gp::Resolution() * gp::Resolution())) {
+                 continue;
+               }
+               else {
+                 Standard_Real anAngle = aNewVec.Angle(aVecOld);
+
+                 if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) {
+
+                   if(bCheckAngle1) {
+                     Standard_Real U1, U2, V1, V2;
+                     IntSurf_PntOn2S atmppoint = aNewP;
+                     atmppoint.SetValue((surfit == 0), anewU, anewV);
+                     atmppoint.Parameters(U1, V1, U2, V2);
+                     gp_Pnt P1 = theSurface1->Value(U1, V1);
+                     gp_Pnt P2 = theSurface2->Value(U2, V2);
+                     gp_Pnt P0 = aPoint.Value();
+
+                     if(P0.IsEqual(P1, aTol) &&
+                        P0.IsEqual(P2, aTol) &&
+                        P1.IsEqual(P2, aTol)) {
+                       bComputeLineEnd = Standard_False;
+                       aNewP.SetValue((surfit == 0), anewU, anewV);
+                     }
+                   }
+
+                   if(bCheckAngle2) {
+                     bComputeLineEnd = Standard_False;
+                   }
+                 }
+                 break;
+               }
+             } // end while(anindexother...)
+           }
+         }
+       }
+       else if ( bIsNearBoundary ) {
+         bComputeLineEnd = Standard_True;
+       }
+
+       if(bComputeLineEnd) {
+
+         gp_Pnt2d anewpoint;
+         Standard_Boolean found = Standard_False;
+
+         if ( bIsNearBoundary ) {
+           // re-compute point near natural boundary or near tangent zone
+           Standard_Real u1, v1, u2, v2;
+           aNewP.Parameters( u1, v1, u2, v2 );
+           if(surfit == 0)
+             anewpoint = gp_Pnt2d( u1, v1 );
+           else
+             anewpoint = gp_Pnt2d( u2, v2 );
+           
+           Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+           const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+           Standard_Real nU1, nV1;
+           
+           if(surfit == 0)
+             aNeighbourPoint.ParametersOnS1(nU1, nV1);
+           else
+             aNeighbourPoint.ParametersOnS2(nU1, nV1);
+           gp_Pnt2d ap1(nU1, nV1);
+           gp_Pnt2d ap2;
+
+
+           if ( aZoneIndex ) {
+             // exclude point from a tangent zone
+             anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface );
+             gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex);
+             Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex);
+
+             if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax, 
+                            aPZone, aZoneRadius, aGASurface, ap2) ) {
+               anewpoint = ap2;
+               found = Standard_True;
+             }
+           }
+           else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) {
+             // re-compute point near boundary if shifted on a period
+             ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface );
+
+             if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) ||
+                 ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) {
+               found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint);
+             }
+             else {
+               anewpoint = ap2;
+               aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() );
+             }
+           }
+         }
+         else {
+
+           Standard_Integer aneighbourpointindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+           const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1);
+           Standard_Real nU1, nV1;
+
+           if(surfit == 0)
+             aNeighbourPoint.ParametersOnS1(nU1, nV1);
+           else
+             aNeighbourPoint.ParametersOnS2(nU1, nV1);
+           gp_Pnt2d ap1(nU1, nV1);
+           gp_Pnt2d ap2(nU1, nV1);
+           Standard_Integer aneighbourpointindex2 = aneighbourpointindex1;
+
+           while((aneighbourpointindex2 <= aListOfIndex.Last()) && (aneighbourpointindex2 >= aListOfIndex.First())) {
+             aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1);
+             const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2);
+             Standard_Real nU2, nV2;
+
+             if(surfit == 0)
+               aPrevNeighbourPoint.ParametersOnS1(nU2, nV2);
+             else
+               aPrevNeighbourPoint.ParametersOnS2(nU2, nV2);
+             ap2.SetX(nU2);
+             ap2.SetY(nV2);
+
+             if(ap1.SquareDistance(ap2) > (gp::Resolution() * gp::Resolution())) {
+               break;
+             }
+           }  
+           found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint);
+         }
+
+         if(found) {
+           // check point
+           Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2);
+           GeomAPI_ProjectPointOnSurf& aProjector = 
+             (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1);
+           Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2;
+
+           Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1;
+
+           gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y());
+           aProjector.Perform(aP3d);
+
+           if(aProjector.IsDone()) {
+             if(aProjector.LowerDistance() < aCriteria) {
+               Standard_Real foundU = U, foundV = V;
+               aProjector.LowerDistanceParameters(foundU, foundV);
+
+               //Correction of projected coordinates. Begin
+               //Note, it may be shifted on a period
+               Standard_Integer aneindex1 = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last();
+               const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1);
+               Standard_Real nUn, nVn;
+               
+               if(surfit == 0)
+                 aNeighbourPoint.ParametersOnS2(nUn, nVn);
+               else
+                 aNeighbourPoint.ParametersOnS1(nUn, nVn);
+               gp_Pnt2d aNeighbour2d(nUn, nVn);
+               gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther );
+               foundU = anAdjustedPoint.X();
+               foundV = anAdjustedPoint.Y();
+
+               if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) &&
+                   ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) {
+                 // attempt to roughly re-compute point
+                 foundU = ( foundU < umin ) ? umin : foundU;
+                 foundU = ( foundU > umax ) ? umax : foundU;
+                 foundV = ( foundV < vmin ) ? vmin : foundV;
+                 foundV = ( foundV > vmax ) ? vmax : foundV;
+
+                 GeomAPI_ProjectPointOnSurf& aProjector2 = 
+                   (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2);
+
+                 aP3d = aSurfaceOther->Value(foundU, foundV);
+                 aProjector2.Perform(aP3d);
+                 
+                 if(aProjector2.IsDone()) {
+                   if(aProjector2.LowerDistance() < aCriteria) {
+                     Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y();
+                     aProjector2.LowerDistanceParameters(foundU2, foundV2);
+                     anewpoint.SetX(foundU2);
+                     anewpoint.SetY(foundV2);
+                   }
+                 }
+               }
+               //Correction of projected coordinates. End
+
+               if(surfit == 0)
+                 aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV);
+               else
+                 aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y());
+             }
+           }
+         }
+       }
       }
       aSeqOfPntOn2S->Add(aNewP);
       aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints());
@@ -4169,146 +4173,146 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
     //
     for(i = 1; i <= nblines; i++) {
       if(anArrayOfLineType.Value(i) != 0) {
-        continue;
+       continue;
       }
       const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i);
 
       if(aListOfIndex.Extent() < 2) {
-        continue;
+       continue;
       }
       const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i);
       Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2);
       Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2);
 
       if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) {
-        bhasfirstpoint = (i != 1);
+       bhasfirstpoint = (i != 1);
       }
 
       if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) {
-        bhaslastpoint = (i != nblines);
+       bhaslastpoint = (i != nblines);
       }
       Standard_Boolean bIsFirstInside = ((ifprm >= aListOfIndex.First()) && (ifprm <= aListOfIndex.Last()));
       Standard_Boolean bIsLastInside =  ((ilprm >= aListOfIndex.First()) && (ilprm <= aListOfIndex.Last()));
 
       if(!bIsFirstInside && !bIsLastInside) {
-        if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
-          // append whole line, and boundaries if neccesary
-          if(bhasfirstpoint) {
-            const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
-            aLineOn2S->Add(aP);
-          }
-          TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
-
-          for(; anIt.More(); anIt.Next()) {
-            const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
-            aLineOn2S->Add(aP);
-          }
-
-          if(bhaslastpoint) {
-            const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
-            aLineOn2S->Add(aP);
-          }
-
-          // check end of split line (end is almost always)
-          Standard_Integer aneighbour = i + 1;
-          Standard_Boolean bIsEndOfLine = Standard_True;
-
-          if(aneighbour <= nblines) {
-            const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
-
-            if((anArrayOfLineType.Value(aneighbour) != 0) &&
-               (aListOfNeighbourIndex.IsEmpty())) {
-              bIsEndOfLine = Standard_False;
-            }
-          }
-
-          if(bIsEndOfLine) {
-            if(aLineOn2S->NbPoints() > 1) {
-              Handle(IntPatch_WLine) aNewWLine = 
-                new IntPatch_WLine(aLineOn2S, Standard_False);
-              theNewLines.Append(aNewWLine);
-            }
-            aLineOn2S = new IntSurf_LineOn2S();
-          }
-        }
-        continue;
+       if((ifprm < aListOfIndex.First()) && (ilprm > aListOfIndex.Last())) {
+         // append whole line, and boundaries if neccesary
+         if(bhasfirstpoint) {
+           const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
+           aLineOn2S->Add(aP);
+         }
+         TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
+
+         for(; anIt.More(); anIt.Next()) {
+           const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
+           aLineOn2S->Add(aP);
+         }
+
+         if(bhaslastpoint) {
+           const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
+           aLineOn2S->Add(aP);
+         }
+
+         // check end of split line (end is almost always)
+         Standard_Integer aneighbour = i + 1;
+         Standard_Boolean bIsEndOfLine = Standard_True;
+
+         if(aneighbour <= nblines) {
+           const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
+
+           if((anArrayOfLineType.Value(aneighbour) != 0) &&
+              (aListOfNeighbourIndex.IsEmpty())) {
+             bIsEndOfLine = Standard_False;
+           }
+         }
+
+         if(bIsEndOfLine) {
+           if(aLineOn2S->NbPoints() > 1) {
+             Handle(IntPatch_WLine) aNewWLine = 
+               new IntPatch_WLine(aLineOn2S, Standard_False);
+             theNewLines.Append(aNewWLine);
+           }
+           aLineOn2S = new IntSurf_LineOn2S();
+         }
+       }
+       continue;
       }
       // end if(!bIsFirstInside && !bIsLastInside)
 
       if(bIsFirstInside && bIsLastInside) {
-        // append inside points between ifprm and ilprm
-        TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
-
-        for(; anIt.More(); anIt.Next()) {
-          if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
-            continue;
-          const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
-          aLineOn2S->Add(aP);
-        }
+       // append inside points between ifprm and ilprm
+       TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
+
+       for(; anIt.More(); anIt.Next()) {
+         if((anIt.Value() < ifprm) || (anIt.Value() > ilprm))
+           continue;
+         const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
+         aLineOn2S->Add(aP);
+       }
       }
       else {
 
-        if(bIsFirstInside) {
-          // append points from ifprm to last point + boundary point
-          TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
-
-          for(; anIt.More(); anIt.Next()) {
-            if(anIt.Value() < ifprm)
-              continue;
-            const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
-            aLineOn2S->Add(aP);
-          }
-
-          if(bhaslastpoint) {
-            const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
-            aLineOn2S->Add(aP);
-          }
-          // check end of split line (end is almost always)
-          Standard_Integer aneighbour = i + 1;
-          Standard_Boolean bIsEndOfLine = Standard_True;
-
-          if(aneighbour <= nblines) {
-            const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
-
-            if((anArrayOfLineType.Value(aneighbour) != 0) &&
-               (aListOfNeighbourIndex.IsEmpty())) {
-              bIsEndOfLine = Standard_False;
-            }
-          }
-
-          if(bIsEndOfLine) {
-            if(aLineOn2S->NbPoints() > 1) {
-              Handle(IntPatch_WLine) aNewWLine = 
-                new IntPatch_WLine(aLineOn2S, Standard_False);
-              theNewLines.Append(aNewWLine);
-            }
-            aLineOn2S = new IntSurf_LineOn2S();
-          }
-        }
-        // end if(bIsFirstInside)
-
-        if(bIsLastInside) {
-          // append points from first boundary point to ilprm
-          if(bhasfirstpoint) {
-            const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
-            aLineOn2S->Add(aP);
-          }
-          TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
-
-          for(; anIt.More(); anIt.Next()) {
-            if(anIt.Value() > ilprm)
-              continue;
-            const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
-            aLineOn2S->Add(aP);
-          }
-        }
-        //end if(bIsLastInside)
+       if(bIsFirstInside) {
+         // append points from ifprm to last point + boundary point
+         TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
+
+         for(; anIt.More(); anIt.Next()) {
+           if(anIt.Value() < ifprm)
+             continue;
+           const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
+           aLineOn2S->Add(aP);
+         }
+
+         if(bhaslastpoint) {
+           const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.Last());
+           aLineOn2S->Add(aP);
+         }
+         // check end of split line (end is almost always)
+         Standard_Integer aneighbour = i + 1;
+         Standard_Boolean bIsEndOfLine = Standard_True;
+
+         if(aneighbour <= nblines) {
+           const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour);
+
+           if((anArrayOfLineType.Value(aneighbour) != 0) &&
+              (aListOfNeighbourIndex.IsEmpty())) {
+             bIsEndOfLine = Standard_False;
+           }
+         }
+
+         if(bIsEndOfLine) {
+           if(aLineOn2S->NbPoints() > 1) {
+             Handle(IntPatch_WLine) aNewWLine = 
+               new IntPatch_WLine(aLineOn2S, Standard_False);
+             theNewLines.Append(aNewWLine);
+           }
+           aLineOn2S = new IntSurf_LineOn2S();
+         }
+       }
+       // end if(bIsFirstInside)
+
+       if(bIsLastInside) {
+         // append points from first boundary point to ilprm
+         if(bhasfirstpoint) {
+           const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(aListOfFLIndex.First());
+           aLineOn2S->Add(aP);
+         }
+         TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex);
+
+         for(; anIt.More(); anIt.Next()) {
+           if(anIt.Value() > ilprm)
+             continue;
+           const IntSurf_PntOn2S& aP = theWLine->Point(anIt.Value());
+           aLineOn2S->Add(aP);
+         }
+       }
+       //end if(bIsLastInside)
       }
     }
 
     if(aLineOn2S->NbPoints() > 1) {
       Handle(IntPatch_WLine) aNewWLine = 
-        new IntPatch_WLine(aLineOn2S, Standard_False);
+       new IntPatch_WLine(aLineOn2S, Standard_False);
       theNewLines.Append(aNewWLine);
     }
   }
@@ -4323,12 +4327,12 @@ Standard_Boolean DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine,
 //                  does not lay on any boundary of given faces
 // ------------------------------------------------------------------------------------------------
 Standard_Boolean ParameterOutOfBoundary(const Standard_Real       theParameter, 
-                                        const Handle(Geom_Curve)& theCurve, 
-                                        const TopoDS_Face&        theFace1, 
-                                        const TopoDS_Face&        theFace2,
-                                        const Standard_Real       theOtherParameter,
-                                        const Standard_Boolean    bIncreasePar,
-                                        Standard_Real&            theNewParameter,
+                                       const Handle(Geom_Curve)& theCurve, 
+                                       const TopoDS_Face&        theFace1, 
+                                       const TopoDS_Face&        theFace2,
+                                       const Standard_Real       theOtherParameter,
+                                       const Standard_Boolean    bIncreasePar,
+                                       Standard_Real&            theNewParameter,
                                         const Handle(BOPInt_Context)& aContext)
 {
   Standard_Boolean bIsComputed = Standard_False;
@@ -4369,10 +4373,10 @@ Standard_Boolean ParameterOutOfBoundary(const Standard_Real       theParameter,
 
     if(aState != TopAbs_ON) {
       aPrj2.Perform(aPCurrent);
-                
+               
       if(aPrj2.IsDone()) {
-        aPrj2.LowerDistanceParameters(U, V);
-        aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
+       aPrj2.LowerDistanceParameters(U, V);
+       aState = aContext->StatePointFace(theFace2, gp_Pnt2d(U, V));
       }
     }
 
@@ -4388,11 +4392,11 @@ Standard_Boolean ParameterOutOfBoundary(const Standard_Real       theParameter,
 
     if(bIncreasePar) {
       if(acurpar >= theOtherParameter)
-        theNewParameter = theOtherParameter;
+       theNewParameter = theOtherParameter;
     }
     else {
       if(acurpar <= theOtherParameter)
-        theNewParameter = theOtherParameter;
+       theNewParameter = theOtherParameter;
     }
   }
   return bIsComputed;
@@ -4441,13 +4445,42 @@ Standard_Boolean IsCurveValid(Handle(Geom2d_Curve)& thePCurve)
 //purpose  : for bug 20964 only
 //=======================================================================
 Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl, 
-                                   const gp_Sphere& theSph)
+                                  const gp_Sphere& theSph)
 {
   Standard_Boolean bRes = Standard_True;
   Standard_Real R1 = theCyl.Radius(), R2 = theSph.Radius();
-
-  if(R1 < 2.*R2) return bRes;
-
+  //
+  {
+    Standard_Real aD2, aRc2, aEps;
+    gp_Pnt aApexSph;
+    //
+    aEps=1.E-7;
+    aRc2=R1*R1;
+    //
+    const gp_Ax3& aAx3Sph=theSph.Position();
+    const gp_Pnt& aLocSph=aAx3Sph.Location();
+    const gp_Dir& aDirSph=aAx3Sph.Direction();
+    //
+    const gp_Ax1& aAx1Cyl=theCyl.Axis();
+    gp_Lin aLinCyl(aAx1Cyl);
+    //
+    aApexSph.SetXYZ(aLocSph.XYZ()+R2*aDirSph.XYZ());
+    aD2=aLinCyl.SquareDistance(aApexSph);
+    if (fabs(aD2-aRc2)<aEps) {
+      return !bRes;
+    }
+    //
+    aApexSph.SetXYZ(aLocSph.XYZ()-R2*aDirSph.XYZ());
+    aD2=aLinCyl.SquareDistance(aApexSph);
+    if (fabs(aD2-aRc2)<aEps) {
+      return !bRes;
+    }
+  }
+  //
+    
+  if(R1 < 2.*R2) {
+    return bRes;
+  }
   gp_Lin anCylAx(theCyl.Axis());
 
   Standard_Real aDist = anCylAx.Distance(theSph.Location());
@@ -4472,13 +4505,13 @@ Standard_Boolean ApproxWithPCurves(const gp_Cylinder& theCyl,
 //purpose  : 
 //=======================================================================
 void  PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1, 
-                    const Handle(GeomAdaptor_HSurface)& theS2, 
-                    const Standard_Real TolAng, 
-                    const Standard_Real TolTang, 
-                    const Standard_Boolean theApprox1,
-                    const Standard_Boolean theApprox2,
-                    IntTools_SequenceOfCurves& theSeqOfCurve, 
-                    Standard_Boolean& theTangentFaces)
+                   const Handle(GeomAdaptor_HSurface)& theS2, 
+                   const Standard_Real TolAng, 
+                   const Standard_Real TolTang, 
+                   const Standard_Boolean theApprox1,
+                   const Standard_Boolean theApprox2,
+                   IntTools_SequenceOfCurves& theSeqOfCurve, 
+                   Standard_Boolean& theTangentFaces)
 {
 
   gp_Pln aPln1 = theS1->Surface().Plane();
@@ -4569,8 +4602,8 @@ void  PerformPlanes(const Handle(GeomAdaptor_HSurface)& theS1,
 //purpose  : 
 //=======================================================================
 static inline Standard_Boolean INTER(const Standard_Real d1, 
-                                     const Standard_Real d2, 
-                                     const Standard_Real tol) 
+                                    const Standard_Real d2, 
+                                    const Standard_Real tol) 
 {
   return (d1 > tol && d2 < -tol) || 
          (d1 < -tol && d2 > tol) ||
@@ -4578,16 +4611,16 @@ static inline Standard_Boolean INTER(const Standard_Real d1,
          ((d2 <= tol && d2 >= -tol) && (d1 > tol || d1 < -tol));
 }
 static inline Standard_Boolean COINC(const Standard_Real d1, 
-                                     const Standard_Real d2, 
-                                     const Standard_Real tol) 
+                                    const Standard_Real d2, 
+                                    const Standard_Real tol) 
 {
   return (d1 <= tol && d1 >= -tol) && (d2 <= tol && d2 >= -tol);
 }
 Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS, 
-                               const gp_Lin2d& theLin2d, 
-                               const Standard_Real theTol,
-                               Standard_Real& theP1, 
-                               Standard_Real& theP2)
+                              const gp_Lin2d& theLin2d, 
+                              const Standard_Real theTol,
+                              Standard_Real& theP1, 
+                              Standard_Real& theP2)
 
 {
   Standard_Real xmin, xmax, ymin, ymax, d1, d2, A, B, C;
@@ -4719,10 +4752,10 @@ Standard_Boolean ClassifyLin2d(const Handle(GeomAdaptor_HSurface)& theS,
 //purpose  : 
 //=======================================================================
 void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
-                      const Handle(GeomAdaptor_HSurface)& aHS2,
-                      Standard_Integer& iDegMin,
-                      Standard_Integer& iDegMax,
-                      Standard_Integer& iNbIter)
+                     const Handle(GeomAdaptor_HSurface)& aHS2,
+                     Standard_Integer& iDegMin,
+                     Standard_Integer& iDegMax,
+                     Standard_Integer& iNbIter)
 
 {
   GeomAbs_SurfaceType aTS1, aTS2;
@@ -4767,7 +4800,7 @@ void ApproxParameters(const Handle(GeomAdaptor_HSurface)& aHS1,
 //purpose  : 
 //=======================================================================
 void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
-                const Handle(GeomAdaptor_HSurface)& aHS2,
+               const Handle(GeomAdaptor_HSurface)& aHS2,
                 Standard_Real& aTolTang)
 {
   GeomAbs_SurfaceType aTS1, aTS2;
@@ -4804,7 +4837,7 @@ void Tolerances(const Handle(GeomAdaptor_HSurface)& aHS1,
 //purpose  : 
 //=======================================================================
 Standard_Boolean SortTypes(const GeomAbs_SurfaceType aType1,
-                           const GeomAbs_SurfaceType aType2)
+                          const GeomAbs_SurfaceType aType2)
 {
   Standard_Boolean bRet;
   Standard_Integer aI1, aI2;
@@ -4883,7 +4916,7 @@ void DumpWLine(const Handle(IntPatch_WLine)& aWLine)
     //
     printf("point p_%d %lf %lf %lf\n", i, aX, aY, aZ);
     //printf("point p_%d %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf %20.15lf\n",
-        //   i, aX, aY, aZ, aU1, aV1, aU2, aV2);
+       //   i, aX, aY, aZ, aU1, aV1, aU2, aV2);
   }
 }
 #endif
@@ -4907,10 +4940,10 @@ void RefineVector(gp_Vec2d& aV2D)
     aNum=fabs(aC[k]);
     if (aNum>aR1 && aNum<aR2) {
       if (aC[k]<0.) {
-        aC[k]=-1.;
-      }          
+       aC[k]=-1.;
+      }          
       else {
-        aC[k]=1.;
+       aC[k]=1.;
       }
       aC[m]=0.;
       break;
@@ -4923,15 +4956,15 @@ void RefineVector(gp_Vec2d& aV2D)
 //purpose  : 
 //=======================================================================
 Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
-                                     const Standard_Real aT2,
-                                     const Standard_Real aEps,
-                                     const Handle(Geom_Curve)& aC3D,
-                                     const Handle(Geom2d_Curve)& aC2D1,
-                                     const Handle(Geom2d_Curve)& aC2D2,
-                                     const Handle(GeomAdaptor_HSurface)& myHS1,
-                                     const Handle(GeomAdaptor_HSurface)& myHS2,
-                                     const TopoDS_Face& myFace1,
-                                     const TopoDS_Face& myFace2,
+                                    const Standard_Real aT2,
+                                    const Standard_Real aEps,
+                                    const Handle(Geom_Curve)& aC3D,
+                                    const Handle(Geom2d_Curve)& aC2D1,
+                                    const Handle(Geom2d_Curve)& aC2D2,
+                                    const Handle(GeomAdaptor_HSurface)& myHS1,
+                                    const Handle(GeomAdaptor_HSurface)& myHS2,
+                                    const TopoDS_Face& myFace1,
+                                    const TopoDS_Face& myFace2,
                                      const Handle(BOPInt_Context)& myContext)
 {
   Standard_Real aA, aB, aCf, aX1, aX2, aF1, aF2, aX, aF;
@@ -4941,17 +4974,17 @@ Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
   aB=aT2;
   aX1=aB-(aB-aA)/aCf;  
   aF1=MaxSquareDistance(aX1, 
-                        aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
+                       aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
   aX2=aA+(aB-aA)/aCf;
   aF2=MaxSquareDistance(aX2, 
-                        aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
+                       aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
   //
   for(;;) {
     //
     if (fabs(aA-aB)<aEps) {
       aX=0.5*(aA+aB);
       aF=MaxSquareDistance(aX, 
-                        aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
+                       aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
       break;
     }
     if (aF1<aF2){
@@ -4960,7 +4993,7 @@ Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
       aF1=aF2;
       aX2=aA+(aB-aA)/aCf;
       aF2=MaxSquareDistance(aX2, 
-                            aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
+                           aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
       
     }
     else {
@@ -4969,7 +5002,7 @@ Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
       aF2=aF1;
       aX1=aB-(aB-aA)/aCf; 
       aF1=MaxSquareDistance(aX1, 
-                            aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
+                           aC3D, aC2D1, aC2D2, myHS1, myHS2, myFace1, myFace2, myContext);
     }
   }
   return aF;
@@ -4979,13 +5012,13 @@ Standard_Real FindMaxSquareDistance (const Standard_Real aT1,
 //purpose  : 
 //=======================================================================
 Standard_Real MaxSquareDistance (const Standard_Real aT,
-                                 const Handle(Geom_Curve)& aC3D,
-                                 const Handle(Geom2d_Curve)& aC2D1,
-                                 const Handle(Geom2d_Curve)& aC2D2,
-                                 const Handle(GeomAdaptor_HSurface) myHS1,
-                                 const Handle(GeomAdaptor_HSurface) myHS2,
-                                 const TopoDS_Face& aF1,
-                                 const TopoDS_Face& aF2,
+                                const Handle(Geom_Curve)& aC3D,
+                                const Handle(Geom2d_Curve)& aC2D1,
+                                const Handle(Geom2d_Curve)& aC2D2,
+                                const Handle(GeomAdaptor_HSurface) myHS1,
+                                const Handle(GeomAdaptor_HSurface) myHS2,
+                                const TopoDS_Face& aF1,
+                                const TopoDS_Face& aF2,
                                  const Handle(BOPInt_Context)& aCtx)
 {
   Standard_Boolean bIsDone;
@@ -5012,7 +5045,7 @@ Standard_Real MaxSquareDistance (const Standard_Real aT,
       aGHS->D0(aU, aV, aPS);
       aD2=aP.SquareDistance(aPS);
       if (aD2>aD2Max) {
-        aD2Max=aD2;
+       aD2Max=aD2;
       }
     }
     //
@@ -5025,7 +5058,7 @@ Standard_Real MaxSquareDistance (const Standard_Real aT,
       aGHS->D0(aU, aV, aPS);
       aD2=aP.SquareDistance(aPS);
       if (aD2>aD2Max) {
-        aD2Max=aD2;
+       aD2Max=aD2;
       }
     }
   }
@@ -5037,8 +5070,8 @@ Standard_Real MaxSquareDistance (const Standard_Real aT,
 //function : CheckPCurve
 //purpose  : Checks if points of the pcurve are out of the face bounds.
 //=======================================================================
-Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC, 
-                             const TopoDS_Face& aFace) 
+  Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC, 
+                               const TopoDS_Face& aFace) 
 {
   const Standard_Integer NPoints = 23;
   Standard_Integer i;
@@ -5049,7 +5082,7 @@ Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
   Standard_Real tolV = Max ((vmax-vmin)*0.01, Precision::Confusion());
   Standard_Real fp = aPC->FirstParameter();
   Standard_Real lp = aPC->LastParameter();
-  
+
 
   // adjust domain for periodic surfaces
   TopLoc_Location aLoc;
@@ -5098,11 +5131,11 @@ Standard_Boolean CheckPCurve(const Handle(Geom2d_Curve)& aPC,
       aT=aT+dT;
       aGAC.D0(aT, aP2D);
       aP2D.Coord(u,v);
-      if (umin-u > tolU || u-umax > tolU ||
+    if (umin-u > tolU || u-umax > tolU ||
           vmin-v > tolV || v-vmax > tolV) {
         return bRet;
-      }
-    }
+  }
+}
   }
   return !bRet;
 }
index 1317b09..e709a08 100644 (file)
@@ -138,7 +138,7 @@ void  ProjLib_Sphere::Project(const gp_Circ& C)
   Zs = mySphere.Position().Direction();
   
   Standard_Boolean isIsoU, isIsoV;
-  Standard_Real Tol = 1.e-8;
+  Standard_Real Tol = Precision::Confusion();
 
   isIsoU = Zc.IsNormal(Zs,Tol) && O.IsEqual(C.Location(),Tol);
   isIsoV = Xc.IsNormal(Zs,Tol) && Yc.IsNormal(Zs,Tol); 
index 50617e1..2807a62 100644 (file)
@@ -460,67 +460,74 @@ void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) con
   seqw.Clear();
   
   // Init seqw by initial set of wires (with corresponding orientation)
-  for ( TopoDS_Iterator iw(myFace,Standard_False); iw.More(); iw.Next() ) {
-//smh#8
+  for ( TopoDS_Iterator iw(myFace,Standard_False); iw.More(); iw.Next() )
+  {
     TopoDS_Shape tmpW = Context()->Apply ( iw.Value() ) ;
-    if(tmpW.ShapeType() != TopAbs_WIRE) {
-      if(tmpW.ShapeType() == TopAbs_VERTEX) {
+    if(tmpW.ShapeType() != TopAbs_WIRE)
+    {
+      if(tmpW.ShapeType() == TopAbs_VERTEX)
+      {
         ShapeFix_WireSegment seg; //(( isOuter ? TopAbs_REVERSED : TopAbs_FORWARD ) );
         seg.SetVertex(TopoDS::Vertex(tmpW));
         seg.Orientation(tmpW.Orientation());
         seqw.Append ( seg );
       }
+
       continue;
     }
+
     TopoDS_Wire wire = TopoDS::Wire ( tmpW );
 
     Standard_Boolean isNonManifold = ( wire.Orientation() != TopAbs_REVERSED &&
                                       wire.Orientation() != TopAbs_FORWARD );
 
-    
-
     // protect against INTERNAL/EXTERNAL wires
-//    if ( wire.Orientation() != TopAbs_REVERSED &&
-//      wire.Orientation() != TopAbs_FORWARD ) continue;
+    //    if ( wire.Orientation() != TopAbs_REVERSED &&
+    //  wire.Orientation() != TopAbs_FORWARD ) continue;
     
     // determine orientation of the wire
-//    TopoDS_Face face = TopoDS::Face ( myFace.EmptyCopied() );
-//    B.Add ( face, wire );
-//    Standard_Boolean isOuter = ShapeAnalysis::IsOuterBound ( face );
+    //    TopoDS_Face face = TopoDS::Face ( myFace.EmptyCopied() );
+    //    B.Add ( face, wire );
+    //    Standard_Boolean isOuter = ShapeAnalysis::IsOuterBound ( face );
 
-    if(isNonManifold) {
-    
+    if(isNonManifold)
+    {
       Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData ( wire ,Standard_True,Standard_False);
       //pdn protection againts of wires w/o edges
       Standard_Integer nbEdges =  sbwd->NbEdges();
-      if(nbEdges) {
-
+      if(nbEdges)
+      {
         //wire segments for non-manifold topology should have INTERNAL orientation
         ShapeFix_WireSegment seg ( sbwd, TopAbs_INTERNAL); 
         seqw.Append ( seg );
       }
     }
-    else {
+    else
+    {
       //splitting wires containing manifold and non-manifold parts on a separate
-       //wire segment
-    
+      //wire segment    
       Handle(ShapeExtend_WireData) sbwdM = new ShapeExtend_WireData();
       Handle(ShapeExtend_WireData) sbwdNM = new ShapeExtend_WireData();
       sbwdNM->ManifoldMode() = Standard_False;
       TopoDS_Iterator aIt(wire);
-      for( ; aIt.More(); aIt.Next()) {
+      for( ; aIt.More(); aIt.Next())
+      {
         TopoDS_Edge E = TopoDS::Edge ( aIt.Value() );
         if(E.Orientation() == TopAbs_FORWARD || E.Orientation() == TopAbs_REVERSED)
           sbwdM->Add(E);
         else
           sbwdNM->Add(E);
       }
+
       Standard_Integer nbMEdges =  sbwdM->NbEdges();
       Standard_Integer nbNMEdges =  sbwdNM->NbEdges();
-      if(nbNMEdges) {
+      
+      if(nbNMEdges)
+      {
         ShapeFix_WireSegment seg ( sbwdNM, TopAbs_INTERNAL); //(( isOuter ? TopAbs_REVERSED : TopAbs_FORWARD ) );
         seqw.Append ( seg );
       }
+      
       if(nbMEdges) {
         // Orientation is set so as to allow the segment to be traversed in only one direction
         // skl 01.04.2002
@@ -528,7 +535,8 @@ void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) con
         sfw->Load ( sbwdM );
         Standard_Integer stat=0;
         Handle(Geom_Surface) gs = BRep_Tool::Surface(myFace);
-        if( gs->IsUPeriodic() && gs->IsVPeriodic() ) {
+        if( gs->IsUPeriodic() && gs->IsVPeriodic() )
+        {
           // For torus-like shapes, first reorder in 2d since reorder is indifferent in 3d
           ShapeAnalysis_WireOrder sawo(Standard_False, 0);
           ShapeAnalysis_Edge sae;
@@ -541,6 +549,7 @@ void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) con
               continue;
             sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY());
           }
+          
           sawo.Perform();
           stat = (sawo.Status() < 0 ? -1 : 1);
           sfw->FixReorder(sawo);
@@ -550,7 +559,8 @@ void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) con
         if (sfw->StatusReorder(ShapeExtend_DONE3))
           stat=-1;
       
-        if( stat < 0 ) {
+        if(stat < 0)
+        {
           BRep_Builder B;
           TopoDS_Shape dummy = myFace.EmptyCopied();
           TopoDS_Face face = TopoDS::Face ( dummy );
@@ -569,7 +579,6 @@ void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) con
         seqw.Append ( seg );
       }
     }
-    
   }
 }
   
index 6207fdf..40467ab 100644 (file)
@@ -1417,6 +1417,8 @@ static Standard_Boolean CheckWire (const TopoDS_Wire &wire,
   vec.SetX(0);
   vec.SetY(0);
   ShapeAnalysis_Edge sae;
+
+  isuopen = isvopen = 0;
   isDeg = Standard_True;
   for ( TopoDS_Iterator ed(wire); ed.More(); ed.Next() ) {
     TopoDS_Edge edge = TopoDS::Edge ( ed.Value() );
@@ -1427,17 +1429,48 @@ static Standard_Boolean CheckWire (const TopoDS_Wire &wire,
       return Standard_False;
     vec += c2d->Value(l).XY() - c2d->Value(f).XY();
   }
-  isuopen = ( Abs ( Abs ( vec.X() ) - dU ) < 0.1 * dU ? ( vec.X() >0 ? 1 : -1 ) : 0 );
-  isvopen = ( Abs ( Abs ( vec.Y() ) - dV ) < 0.1 * dV ? ( vec.Y() >0 ? 1 : -1 ) : 0 );
+
+  Standard_Real aDelta = Abs(vec.X())-dU;
+  if(Abs(aDelta) < 0.1*dU)
+  {
+    if(vec.X() > 0.0)
+    {
+      isuopen = 1;
+    }
+    else
+    {
+      isuopen = -1;
+    }
+  }
+  else
+  {
+    isuopen = 0;
+  }
+
+  aDelta = Abs(vec.Y())-dV;
+  if(Abs(aDelta) < 0.1*dV)
+  {
+    if(vec.Y() > 0.0)
+    {
+      isvopen = 1;
+    }
+    else
+    {
+      isvopen = -1;
+    }
+  }
+  else
+  {
+    isvopen = 0;
+  }
+
   return isuopen || isvopen;
 }
 
-
 //=======================================================================
 //function : FixMissingSeam
 //purpose  : 
 //=======================================================================
-
 Standard_Boolean ShapeFix_Face::FixMissingSeam() 
 {
   Standard_Boolean uclosed = mySurf->IsUClosed();
@@ -1480,8 +1513,8 @@ Standard_Boolean ShapeFix_Face::FixMissingSeam()
     }
   }
     
-  URange = Abs ( SUL - SUF );
-  VRange = Abs ( SVL - SVF );
+  URange = Min(Abs (SUL - SUF), Precision::Infinite());
+  VRange = Min(Abs(SVL - SVF), Precision::Infinite());
 //  Standard_Real UTol = 0.2 * URange, VTol = 0.2 * VRange;
   Standard_Integer ismodeu = 0, ismodev = 0; //szv#4:S4163:12Mar99 was Boolean
   Standard_Integer isdeg1=0, isdeg2=0;
index 2b084db..dcec1a8 100644 (file)
@@ -1,5 +1,4 @@
 ## cts20461
-puts "TODO #22911 ALL: Error : The area of the resulting shape is"
 
 restore [locate_data_file cts20461.rle] a
 nexplode a f
@@ -43,4 +42,4 @@ bcut r4 r3 p4
 bcut r5 r4 p5
 bcut result r5 p6
 
-set square 0
+set square 55910.6
index e5be92d..9358305 100644 (file)
@@ -5,4 +5,4 @@ restore [locate_data_file Plan.rle] b
 
 bsection result a b
 
-set length 1686.09
+set length 1908.63
index eee1c97..144e2fb 100755 (executable)
@@ -66,5 +66,5 @@ if { $MaxFaceTolerance > 1 || $MaxEdgeTolerance > 1 || $MaxVertexTolerance > 1 }
 } else {
     puts "Tolerance of shape is less then 1.0"
 }
-set square 2.22138e+07
+set square 2.34799e+007
 set 2dviewer 0
index b74c12a..cc01ffd 100755 (executable)
@@ -40,7 +40,7 @@ set CPU_user_time [expr ${CPU_user_time} / ${NbTests}]
 puts "CPU_user_time=${CPU_user_time}"
 
 #CR24317 set square 782201
-set square 766474
+set square 784833
 
 # Analysis of "nbshapes res"
 set nb_v_good 53
index aae753c..01e486c 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {} $calcul $type }
 
 
-set square 236.013
+set square 253.552
 
 set nb_v_good 2
 set nb_e_good 3
index 25171df..9ea1cba 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {s_3} $calcul $type }
 
 
-set square 484.846
+set square 502.411
 
 set nb_v_good 3
 set nb_e_good 5
index 93d858d..87ca0f3 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {s_2} $calcul $type }
 
 
-set square 484.846
+set square 502.411
 
 set nb_v_good 3
 set nb_e_good 5
index 7cd02e9..11542cb 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {s_3 s_2} $calcul $type }
 
 
-set square 472.222
+set square 489.812
 
 set nb_v_good 3
 set nb_e_good 5
index e85305a..3151258 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {} $calcul $type }
 
 
-set square 754.039
+set square 767.63
 
 set nb_v_good 2
 set nb_e_good 3
index de23a88..1081bd5 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {s_2} $calcul $type }
 
 
-set square 1511.4
+set square 1530.96
 
 set nb_v_good 4
 set nb_e_good 6
index 886259e..9fbd1d3 100755 (executable)
@@ -30,7 +30,7 @@ set distance -0.1
 catch { OFFSETSHAPE $distance {s_3 s_2} $calcul $type }
 
 
-set square 1451.05
+set square 1471.48
 
 set nb_v_good 4
 set nb_e_good 6
index 08c4ec0..2512662 100755 (executable)
@@ -15,6 +15,6 @@ fit
 
 reflectlines result a 0 1 0
 
-set length 3877.8
+set length 3730.32
 
 set only_screen_axo 1
index 454c9b2..48f553b 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 77849.3
+set square 80532.3
 
 # Analysis of "nbshapes result"
 set nb_v_good 54
index 58e9f83..e7d1c91 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 82726.4
+set square 81730.6
 
 # Analysis of "nbshapes result"
 set nb_v_good 121
index 90ef34f..6e6c793 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 117639
+set square 126161
 
 # Analysis of "nbshapes result"
 set nb_v_good 16
index 22c798b..b304a2e 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 77849.3
+set square 80532.3
 
 # Analysis of "nbshapes result"
 set nb_v_good 54
index 7617c10..c274756 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 82726.4
+set square 81730.6
 
 # Analysis of "nbshapes result"
 set nb_v_good 121
index e96e15b..e82a780 100644 (file)
@@ -21,7 +21,7 @@ for {set i 0} {$i < $nbObjs} {incr i} {
 bfillds
 bbuild result
 
-set square 117639
+set square 126161
 
 # Analysis of "nbshapes result"
 set nb_v_good 16
index 214185d..591701b 100755 (executable)
@@ -1,11 +1,11 @@
-puts "TODO OCC12345 ALL: Error : Volume of OCC76-1.brep is calculated wrongly becuase 3020.94 value must be but 3050.41 is"
-puts "TODO OCC12345 ALL: Error : Volume of OCC76-2.brep is calculated wrongly because 9871.39 value must be but 10153.6 is"
-
 puts "================"
 puts "OCC76"
 puts "================"
 puts ""
 
+set vol1_exp 3050.42
+set vol2_exp 10195.3
+
 restore [locate_data_file shading_177.brep] sh1 
 checkshape sh1
 regexp {Mass +: +([-0-9.+eE]+)} [vprops sh1] full l1
@@ -14,14 +14,14 @@ restore [locate_data_file OCC76-2.brep] sh2
 checkshape sh2
 regexp {Mass +: +([-0-9.+eE]+)} [vprops sh2] full l2
 
-if { [expr abs([expr $l1 - 3020.94])] > 0.00999} {     
-   puts "Error : Volume of OCC76-1.brep is calculated wrongly becuase 3020.94 value must be but $l1 is"
+if { [expr abs([expr $l1 - $vol1_exp])] > 0.00999} {   
+   puts "Error : Volume of OCC76-1.brep is calculated wrongly becuase $vol1_exp value must be but $l1 is"
 } else {
   puts " Volume of OCC76-1.brep is right calculated"
 }
 
-if { [expr abs([expr $l2 - 9871.39 ])] > 0.00999} {
-   puts "Error : Volume of OCC76-2.brep is calculated wrongly because 9871.39 value must be but $l2 is"
+if { [expr abs([expr $l2 - $vol2_exp])] > 0.00999} {
+   puts "Error : Volume of OCC76-2.brep is calculated wrongly because $vol2_exp value must be but $l2 is"
 } else {
   puts " Volume of OCC76-2.brep is right calculated"
 }
index 0ea374a..9b156d9 100755 (executable)
@@ -11,10 +11,10 @@ puts ""
 ## strings of code. BRepTools.cxx line 213 (in dev version)
 ############################################################
 
-set good_u1 -0.157166
-set good_u2 4.88216
-set good_v1 -1.65583
-set good_v2 7.93778
+set good_u1 -0.14353846357954067
+set good_u2 4.8658600889104724
+set good_v1 -1.386764846506505
+set good_v2 7.6699722758333735
 
 set percent_max 0.1
 
diff --git a/tests/bugs/moddata_3/bug23511 b/tests/bugs/moddata_3/bug23511
new file mode 100644 (file)
index 0000000..80c282a
--- /dev/null
@@ -0,0 +1,21 @@
+puts "================"
+puts "OCC23511"
+puts "================"
+puts ""
+#########################################################################
+# The function BRepTools::UVBounds provides incorrect result for a face
+#########################################################################
+
+restore [locate_data_file bug23511_f1] result
+
+set info [xbounds result]
+
+set 2PI [expr 2 * 3.142]
+foreach bound ${info} {
+  puts "bound = ${bound}"
+  if { ${bound} < 0 || ${bound} > ${2PI} } {
+    puts "Error : bad bound ${bound}"
+  }
+}
+
+set 2dviewer 1
index 3ff8684..33c68b3 100644 (file)
@@ -8,8 +8,8 @@ set ref_data {
 DATA        : Faulties = 0  ( 0 )  Warnings = 0  ( 1 )  Summary  = 0  ( 1 )
 TPSTAT      : Faulties = 0  ( 28 )  Warnings = 115  ( 7 )  Summary  = 115  ( 35 )
 CHECKSHAPE  : Wires    = 0  ( 0 )  Faces    = 0  ( 0 )  Shells   = 0  ( 1 )   Solids   = 0 ( 1 )
-NBSHAPES    : Solid    = 0  ( 18 )  Shell    = 0  ( 18 )  Face     = 1190  ( 1190 )   Summary  = 15073  ( 7693 )
-STATSHAPE   : Solid    = 0  ( 18 )  Shell    = 0  ( 18 )  Face     = 1190  ( 1190 )   FreeWire = 0  ( 0 )   FreeEdge  = 0 ( 0 )   SharedEdge = 6283  ( 3134 )
+NBSHAPES    : Solid    = 0  ( 18 )  Shell    = 0  ( 18 )  Face     = 1190  ( 1190 )   Summary  = 15075  ( 7693 )
+STATSHAPE   : Solid    = 0  ( 18 )  Shell    = 0  ( 18 )  Face     = 1190  ( 1190 )   FreeWire = 0  ( 0 )   FreeEdge  = 0 ( 0 )   SharedEdge = 6284  ( 3134 )
 TOLERANCE   : MaxTol   =   0.2496383637  (   0.2496258832 )  AvgTol   =  0.002193043247  (  0.004111699336 )
 LABELS      : N0Labels = 27  ( 27 )  N1Labels = 0  ( 0 )  N2Labels = 0  ( 0 )   TotalLabels = 27  ( 27 )   NameLabels = 27  ( 27 )   ColorLabels = 0  ( 0 )   LayerLabels = 0  ( 0 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
index ef0edcf..5f80d0d 100644 (file)
@@ -10,4 +10,4 @@ bfuse f pt pr
 nexplode f f
 depouille result f 0 0 1 f_4 5 0 0 40 0 0 1
 
-set square 11348.9
+set square 10850.6
index 6e31aa1..1497bd2 100644 (file)
@@ -2,6 +2,7 @@
 # Date : 02 Dec 98
 
 puts "TODO OCC22803 All:Error: The tolerance of the resulting shape is too big"
+puts "TODO OCC23511 Debian60-64: The area of the resulting shape is 186543"
 
 restore [locate_data_file CFE903_pro12ggx.rle] base
 
@@ -11,4 +12,4 @@ depouille result base 0 -1 0 base_13 3 110 0 96.5000000000001  0 -1 0 base_24 3
 
 fsameparameter result
 
-set square 186544
+set square 200050