0023125: Wrong results done by classifier algorithm for a point and a solid.
[occt.git] / src / BRepClass3d / BRepClass3d_SolidExplorer.cxx
index 477787d..b2e4cca 100755 (executable)
@@ -1,17 +1,33 @@
-// File:       BRepClass3d_SolidExplorer.cxx
-// Created:    Thu Mar 10 14:52:22 1994
-// Author:     Laurent BUCHARD
-//             <lbr@fuegox>
-// Modifed:     Portage NT 7-5-97 DPF (stdio.h)
+// Created on: 1994-03-10
+// Created by: Laurent BUCHARD
+// Copyright (c) 1994-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
+// Modifed:     Porting NT 7-5-97 DPF (stdio.h)
 //              Apr 16 2002 eap, classification against infinite solid (occ299)
 
 
 //  Modified by skv - Thu Sep  4 12:29:30 2003 OCC578
 
-//-- Traiter le cas d un trou !!
+//-- Process the case of a hole!!
 #define REJECTION 1
 
-//-- Pour printf sur NT
+//-- To printf on NT
 #include <stdio.h>
 
 #include <BRepClass3d_SolidExplorer.ixx>
 #include <BRep_Tool.hxx> 
 #include <BRepClass_FaceClassifier.hxx>
 //<-OCC454(apo)
-static Standard_Integer numedg=0;
-static gp_Vec staticd1u_gp_vec;
-static gp_Vec staticd1v_gp_vec;
 
 //=======================================================================
 //function : FindAPointInTheFace
-//purpose  : compute a point P in the face  F. Param is a Real in
+//purpose  : Compute a point P in the face  F. Param is a Real in
 //           ]0,1[ and   is  used to  initialise  the algorithm. For
 //           different values , different points are returned.
 //=======================================================================
@@ -56,8 +69,8 @@ static gp_Vec staticd1v_gp_vec;
 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
 (const TopoDS_Face& _face,
  gp_Pnt& APoint_,
- Standard_Real& param_) 
-{ 
+ Standard_Real& param_)
+{
   Standard_Real u,v;
   Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u,v,param_);
   return r;
@@ -72,97 +85,131 @@ Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
 (const TopoDS_Face& _face,
  gp_Pnt& APoint_,
  Standard_Real& u_, Standard_Real& v_,
- Standard_Real& param_) 
-{   
-  TopoDS_Face face=_face;
-  face.Orientation(TopAbs_FORWARD);
-  
-  TopExp_Explorer     faceexplorer;
+ Standard_Real& param_)
+{
+  gp_Vec aVecD1U, aVecD1V;
+  return FindAPointInTheFace (_face, APoint_, u_, v_, param_, aVecD1U, aVecD1V);
+}
+
+//=======================================================================
+//function : FindAPointInTheFace
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
+(const TopoDS_Face& _face,
+ gp_Pnt& APoint_,
+ Standard_Real& u_, Standard_Real& v_,
+ Standard_Real& param_,
+ gp_Vec& theVecD1U,
+ gp_Vec& theVecD1V)
+{
+  TopoDS_Face face = _face;
+  face.Orientation (TopAbs_FORWARD);
+
+  TopExp_Explorer faceexplorer;
   BRepAdaptor_Curve2d c;
   gp_Vec2d T;
   gp_Pnt2d P;
-  //Standard_Boolean Ok = Standard_False;
-  Standard_Integer nedg=1;
+
   for (faceexplorer.Init(face,TopAbs_EDGE); 
        faceexplorer.More(); 
-       faceexplorer.Next()) {
-    if(numedg==0 || nedg++==numedg) { 
-      TopoDS_Edge Edge = TopoDS::Edge(faceexplorer.Current());
-      c.Initialize(Edge,face);
-#ifdef DEB
-      Standard_Integer nbinterval = 
-#endif
-       c.NbIntervals(GeomAbs_C1); 
-      c.D1((c.LastParameter() - c.FirstParameter()) * param_ + c.FirstParameter(),P,T);
-      
-      Standard_Real x=T.X();
-      Standard_Real y=T.Y();
-      if(Edge.Orientation() == TopAbs_FORWARD) { 
-       T.SetCoord(-y,x);
-      }
-      else { 
-       T.SetCoord(y,-x);
-      }
-      Standard_Real ParamInit = RealLast();
-      Standard_Real TolInit   = 0.00001;
-      Standard_Boolean APointExist = Standard_False;
-      
-      BRepClass_FacePassiveClassifier FClassifier;
-      
-      T.Normalize();
-      P.SetCoord(P.X()+TolInit*T.X(),P.Y()+TolInit*T.Y());
-      FClassifier.Reset(gp_Lin2d(P,T),ParamInit,RealEpsilon());   //-- Longueur et Tolerance #######
-      
-      TopExp_Explorer otherfaceexplorer;
-//  Modified by Sergey KHROMOV - Tue Apr  1 11:32:51 2003 Begin
-      Standard_Integer aNbEdges = 0;
-      for (otherfaceexplorer.Init(face,TopAbs_EDGE); 
-          otherfaceexplorer.More(); 
-          otherfaceexplorer.Next(), aNbEdges++) {
-//       for (otherfaceexplorer.Init(face,TopAbs_EDGE); 
-//        otherfaceexplorer.More(); 
-//        otherfaceexplorer.Next()) {
-//  Modified by Sergey KHROMOV - Tue Apr  1 11:32:52 2003 End
-       TopoDS_Edge OtherEdge = TopoDS::Edge(otherfaceexplorer.Current());
-       if((OtherEdge.Orientation() == TopAbs_EXTERNAL ||
-           OtherEdge == Edge)) { 
-       }
-       else { 
-         BRepClass_Edge AEdge(OtherEdge,face);
-         FClassifier.Compare(AEdge,OtherEdge.Orientation());
-         if(FClassifier.ClosestIntersection()) { 
-           //-- cout<<" ---> Edge : "<<FClassifier.Parameter()<<endl;
-           if(ParamInit > FClassifier.Parameter()) { 
-             ParamInit = FClassifier.Parameter();
-             APointExist = Standard_True;
-           }
-         }
-       }
-      }
-//  Modified by Sergey KHROMOV - Tue Apr  1 11:34:36 2003 Begin
-      if (aNbEdges == 1) {
-       BRepClass_Edge AEdge(Edge,face);
-       FClassifier.Compare(AEdge,Edge.Orientation());
-       if(FClassifier.ClosestIntersection()) { 
-         if(ParamInit > FClassifier.Parameter()) { 
-           ParamInit = FClassifier.Parameter();
-           APointExist = Standard_True;
-         }
-       }
+       faceexplorer.Next())
+  {
+    TopoDS_Edge Edge = TopoDS::Edge (faceexplorer.Current());
+    c.Initialize (Edge, face);
+    c.D1((c.LastParameter() - c.FirstParameter()) * param_ + c.FirstParameter(),P,T);
+
+    Standard_Real x = T.X();
+    Standard_Real y = T.Y();
+    if (Edge.Orientation() == TopAbs_FORWARD)
+    {
+      T.SetCoord (-y,  x);
+    }
+    else
+    {
+      T.SetCoord ( y, -x);
+    }
+    Standard_Real ParamInit = RealLast();
+    Standard_Real TolInit   = 0.00001;
+    Standard_Boolean APointExist = Standard_False;
+
+    BRepClass_FacePassiveClassifier FClassifier;
+
+    T.Normalize();
+    P.SetCoord (P.X() + TolInit * T.X(), P.Y() + TolInit * T.Y());
+    FClassifier.Reset (gp_Lin2d (P, T), ParamInit, RealEpsilon()); //-- Length and Tolerance #######
+
+    TopExp_Explorer otherfaceexplorer;
+    Standard_Integer aNbEdges = 0;
+    for (otherfaceexplorer.Init (face, TopAbs_EDGE);
+         otherfaceexplorer.More(); 
+         otherfaceexplorer.Next(), ++aNbEdges)
+    {
+      TopoDS_Edge OtherEdge = TopoDS::Edge (otherfaceexplorer.Current());
+      if (OtherEdge.Orientation() != TopAbs_EXTERNAL && OtherEdge != Edge)
+      {
+        BRepClass_Edge AEdge (OtherEdge, face);
+        FClassifier.Compare (AEdge, OtherEdge.Orientation());
+        if (FClassifier.ClosestIntersection())
+        {
+          if(ParamInit > FClassifier.Parameter())
+          {
+            ParamInit = FClassifier.Parameter();
+            APointExist = Standard_True;
+          }
+        }
       }
-//  Modified by Sergey KHROMOV - Tue Apr  1 11:34:36 2003 End
-      if(APointExist) { 
-       ParamInit*=0.41234;
-       u_ = P.X() + ParamInit* T.X();
-       v_ = P.Y() + ParamInit* T.Y();
-       BRepAdaptor_Surface  s;
-       s.Initialize(face,Standard_False);
-       s.D1(u_,v_,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
-       return(Standard_True);
+    }
+
+    if (aNbEdges == 1)
+    {
+      BRepClass_Edge AEdge (Edge, face);
+      FClassifier.Compare (AEdge, Edge.Orientation());
+      if (FClassifier.ClosestIntersection())
+      {
+        if (ParamInit > FClassifier.Parameter())
+        {
+          ParamInit = FClassifier.Parameter();
+          APointExist = Standard_True;
+        }
       }
     }
+
+    if (APointExist)
+    { 
+      ParamInit *= 0.41234;
+      u_ = P.X() + ParamInit* T.X();
+      v_ = P.Y() + ParamInit* T.Y();
+      BRepAdaptor_Surface s;
+      s.Initialize (face, Standard_False);
+      s.D1 (u_, v_, APoint_, theVecD1U, theVecD1V);
+      return Standard_True;
+    }
   }
-  return(Standard_False);
+  return Standard_False;
+}
+
+//=======================================================================
+//function : PointInTheFace
+//purpose  : 
+//=======================================================================
+
+Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
+(const TopoDS_Face& Face,
+ gp_Pnt& APoint_,
+ Standard_Real& u_, Standard_Real& v_,
+ Standard_Real& param_,
+ Standard_Integer& IndexPoint,
+ const Handle(BRepAdaptor_HSurface)& surf,
+ const Standard_Real U1,
+ const Standard_Real V1,
+ const Standard_Real U2,
+ const Standard_Real V2) const
+{
+  gp_Vec aVecD1U, aVecD1V;
+  return PointInTheFace (Face, APoint_, u_, v_, param_, IndexPoint, surf,
+                         U1, V1, U2, V2, aVecD1U, aVecD1V);
 }
 
 //=======================================================================
@@ -180,8 +227,10 @@ Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
  const Standard_Real U1,
  const Standard_Real V1,
  const Standard_Real U2,
- const Standard_Real V2 ) const  
-{  
+ const Standard_Real V2,
+ gp_Vec& theVecD1U,
+ gp_Vec& theVecD1V) const
+{
   Standard_Real u,du = (U2-U1)/6.0;
   Standard_Real v,dv = (V2-V1)/6.0;
   if(du<1e-12) du=1e-12;
@@ -191,62 +240,62 @@ Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
     void *ptr = (void*)(myMapOfInter.Find(Face));
     if(ptr) { 
       const IntCurvesFace_Intersector& TheIntersector = (*((IntCurvesFace_Intersector *)ptr));
-      //-- On prend les 4 points dans chaque Quart de surface
+      //-- Take 4 points in each Quarter of surface
       //-- -> Index : 1 -> 16
       //-- 
       //--
-      //-- Puis on prend une matrice de points sur une grille serree
+      //--  Then take a matrix of points on a tight grid
       //--
-      for(u=du+(U1+U2)*0.5; u<U2; u+=du) {          //--  0  X    u croit
-        for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) {        //--  0  0    v croit
+      for(u=du+(U1+U2)*0.5; u<U2; u+=du) {          //--  0  X    u increases
+        for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) {        //--  0  0    v increases
           if(++NbPntCalc>=IndexPoint) { 
             if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
               u_=u; v_=v;
-              surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
-             IndexPoint = NbPntCalc;
+              surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
+              IndexPoint = NbPntCalc;
               return(Standard_True);
             }
           }
         }
       }
          
-      for(u=-du+(U1+U2)*0.5; u>U1; u-=du) {         //--  0  0    u decroit
-       for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) {       //--  X  0    v decroit
+      for(u=-du+(U1+U2)*0.5; u>U1; u-=du) {         //--  0  0    u decreases
+       for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) {       //--  X  0    v decreases
          if(++NbPntCalc>=IndexPoint) {
            if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
              u_=u; v_=v;
-             surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
+             surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
              IndexPoint = NbPntCalc;
              return(Standard_True);
            }
          }
        }
       }
-      for(u=-du+(U1+U2)*0.5; u>U1; u-=du) {         //--  X  0    u decroit
-       for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) {        //--  0  0    v croit
+      for(u=-du+(U1+U2)*0.5; u>U1; u-=du) {         //--  X  0    u decreases
+       for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) {        //--  0  0    v increases
          if(++NbPntCalc>=IndexPoint) { 
            if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
              u_=u; v_=v;
-             surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
+             surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
              IndexPoint = NbPntCalc;
              return(Standard_True);
            }
          }
        }
       }
-      for(u=du+(U1+U2)*0.5; u<U2; u+=du) {         //--  0  0     u croit
-       for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) {      //--  0  X     v decroit
+      for(u=du+(U1+U2)*0.5; u<U2; u+=du) {         //--  0  0     u increases
+       for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) {      //--  0  X     v decreases
          if(++NbPntCalc>=IndexPoint) {
            if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
              u_=u; v_=v;
-             surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
+             surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
              IndexPoint = NbPntCalc;
              return(Standard_True);
            }
          }
        }
       }
-      //-- le reste
+      //-- the remainder
       du = (U2-U1)/37.0;
       dv = (V2-V1)/37.0;
       if(du<1e-12) du=1e-12;
@@ -257,7 +306,7 @@ Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
          if(++NbPntCalc>=IndexPoint) {
            if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
              u_=u; v_=v;
-             surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
+             surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
              IndexPoint = NbPntCalc;
              return(Standard_True);
            }
@@ -269,7 +318,7 @@ Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
       if(++NbPntCalc>=IndexPoint) {
        if(TheIntersector.ClassifyUVPoint(gp_Pnt2d(u,v))==TopAbs_IN) { 
          u_=u; v_=v;
-         surf->D1(u,v,APoint_,staticd1u_gp_vec,staticd1v_gp_vec);
+         surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
          IndexPoint = NbPntCalc;
          return(Standard_True);
        }
@@ -278,17 +327,17 @@ Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
     IndexPoint = NbPntCalc;
   }
   else { 
-    //printf("BRepClass3d_SolidExplorer Face non trouvee ds la map \n");
+    //printf("BRepClass3d_SolidExplorer Face not found ds the map \n");
   }
-  return(BRepClass3d_SolidExplorer::FindAPointInTheFace(Face,APoint_,u_,v_,param_));
-  
+
+  return BRepClass3d_SolidExplorer
+    ::FindAPointInTheFace (Face,APoint_, u_, v_, param_, theVecD1U, theVecD1V);
 }
 
 //=======================================================================
 //function : LimitInfiniteUV
 //purpose  : Limit infinite parameters
 //=======================================================================
-
 static void LimitInfiniteUV (Standard_Real& U1,
                             Standard_Real& V1,
                             Standard_Real& U2,
@@ -305,14 +354,15 @@ static void LimitInfiniteUV (Standard_Real& U1,
   if (infU2) U2 =  1e10;
   if (infV2) V2 =  1e10;
 }
-//  Modified by skv - Tue Sep 16 13:50:38 2003 OCC578 Begin
-//OCC454(apo)->
-// static Standard_Boolean IsInfiniteUV (Standard_Real& U1, Standard_Real& V1, Standard_Real& U2, Standard_Real& V2) {
-//   return (Precision::IsNegativeInfinite(U1) || Precision::IsNegativeInfinite(V1) || 
-//       Precision::IsNegativeInfinite(U2) || Precision::IsNegativeInfinite(V2)); 
-// }
-static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
-                                     Standard_Real& U2, Standard_Real& V2) {
+//=======================================================================
+//function : IsInfiniteUV
+//purpose  : 
+//=======================================================================
+static Standard_Integer IsInfiniteUV (Standard_Real& U1, 
+                                     Standard_Real& V1,
+                                     Standard_Real& U2, 
+                                     Standard_Real& V2) 
+{
   Standard_Integer aVal = 0;
 
   if (Precision::IsInfinite(U1))
@@ -341,23 +391,20 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
 //           The Second Call provide a line to the second face
 //           and so on. 
 //=======================================================================
-//modified by NIZNHY-PKV Thu Nov 14 14:34:05 2002 f
-//void  BRepClass3d_SolidExplorer::OtherSegment(const gp_Pnt& P, 
-//                                           gp_Lin& L, 
-//                                           Standard_Real& _Par)  
-  Standard_Integer BRepClass3d_SolidExplorer::OtherSegment(const gp_Pnt& P, 
-                                                          gp_Lin& L, 
-                                                          Standard_Real& _Par) 
-//modified by NIZNHY-PKV Thu Nov 14 14:34:10 2002 t
+Standard_Integer BRepClass3d_SolidExplorer::OtherSegment(const gp_Pnt& P, 
+                                                        gp_Lin& L, 
+                                                        Standard_Real& _Par) 
 {
+  const Standard_Real TolU = Precision::PConfusion();
+  const Standard_Real TolV = TolU;
+
   TopoDS_Face         face;
   TopExp_Explorer     faceexplorer;
-  //TopExp_Explorer     edgeexplorer;
   gp_Pnt APoint;
+  gp_Vec aVecD1U, aVecD1V;
   Standard_Real maxscal=0;
   Standard_Boolean ptfound=Standard_False;
   Standard_Real Par;
-  //Standard_Integer i=1;
   Standard_Real _u,_v;
   Standard_Integer IndexPoint=0;
   Standard_Integer NbPointsOK=0;
@@ -386,43 +433,44 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
       //
       //avoid process faces from uncorrected shells
       if( Abs (U2 - U1) < 1.e-12 || Abs(V2 - V1) < 1.e-12) {
-       //modified by NIZNHY-PKV Thu Nov 14 15:03:18 2002 f
-       //gp_Vec avoidV(gp_Pnt(0.,0.,0.),gp_Pnt(0.,0.,1.));
-       //gp_Lin avoidL(gp_Pnt(0.,0.,0.),avoidV);
-       //_Par = RealLast();
-       //L = avoidL;
        return 2;
-       //return ;
-       //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t
       }
       //
       Standard_Real svmyparam=myParamOnEdge;
       //
-      //  Modified by skv - Tue Sep 16 13:55:27 2003 OCC578 Begin
       // Check if the point is on the face or the face is infinite.
       Standard_Integer anInfFlag = IsInfiniteUV(U1,V1,U2,V2);
 
-//       if(IsInfiniteUV(U1,V1,U2,V2)){//OCC454(apo)->
       GeomAdaptor_Surface GA(BRep_Tool::Surface(face));
-      static Standard_Real TolU = Precision::PConfusion(), TolV = TolU;
-      Extrema_ExtPS Ext(P,GA,TolU,TolV);
+      Extrema_ExtPS Ext(P, GA, TolU, TolV);
+      //
       if (Ext.IsDone() && Ext.NbExt() > 0) {
-       // evaluate the lower distance and its index;
-       Standard_Real  Dist2, Dist2Min = Ext.SquareDistance(1);
-       Standard_Integer  iNear = 1, i = 2, iEnd = Ext.NbExt();
+       Standard_Integer i, iNear,  iEnd;
+       Standard_Real  aUx, aVx, Dist2, Dist2Min;
+       Extrema_POnSurf aPx;
+       //
+       iNear = 1;
+       Dist2Min = Ext.SquareDistance(1);
+       iEnd = Ext.NbExt();
        for (i = 2; i <= iEnd; i++) {
-         Dist2 = Ext.SquareDistance(i);
-         if (Dist2 < Dist2Min) {
-           Dist2Min = Dist2; iNear = i;
+         aPx=Ext.Point(i);
+         aPx.Parameter(aUx, aVx);
+         if (aUx>=U1 && aUx<=U2 && aVx>=V1 && aVx<=V2) {
+           Dist2 = Ext.SquareDistance(i);
+           if (Dist2 < Dist2Min) {
+             Dist2Min = Dist2; 
+             iNear = i;
+           }
          }
        }
-       //modified by NIZNHY-PKV Thu Nov 14 12:31:01 2002 f
+       //
        Standard_Real aDist2Tresh=1.e-24;
-
+       //
        if (Dist2Min<aDist2Tresh) {
          if (anInfFlag) {
            return 1;
-         } else {
+         } 
+         else {
            BRepClass_FaceClassifier classifier2d;
            Standard_Real            aU;
            Standard_Real            aV;
@@ -435,67 +483,58 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
 
            TopAbs_State aState = classifier2d.State();
 
-           if (aState == TopAbs_IN || aState == TopAbs_ON)
+           if (aState == TopAbs_IN || aState == TopAbs_ON) {
              return 1;
-           else
+           }
+           else {
              return 3; // skv - the point is on surface but outside face.
+           }
          }
        }
-       //modified by NIZNHY-PKV Thu Nov 14 12:31:03 2002 t
        if (anInfFlag) {
          APoint = (Ext.Point(iNear)).Value();
          gp_Vec V(P,APoint);
          _Par = V.Magnitude(); 
          L = gp_Lin(P,V);
          ptfound=Standard_True;
-         numedg=0;
-         //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-         //return ;
          return 0;
-         //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t
        }
-       //<-OCC454(apo)
-//       }else{
       }
       //The point is not ON the face or surface. The face is restricted.
       // find point in a face not too far from a projection of P on face
-      //  Modified by skv - Tue Sep 16 15:25:00 2003 OCC578 End
-
-      do { 
-       if(PointInTheFace(face,APoint,_u,_v,myParamOnEdge,++IndexPoint,surf,U1,V1,U2,V2)) { 
-         NbPointsOK++;
-         gp_Vec V(P,APoint);
-         Par = V.Magnitude(); 
-         if(Par > gp::Resolution()) {
-           gp_Vec Norm=staticd1u_gp_vec.Crossed(staticd1v_gp_vec);
-           Standard_Real tt = Norm.Magnitude();
-           tt=Abs(Norm.Dot(V))/(tt*Par);
-           if(tt>maxscal) { 
-             maxscal=tt;
-             L = gp_Lin(P,V);
-             _Par=Par;
-             ptfound=Standard_True;
-             if(maxscal>0.2) { 
-               myParamOnEdge=svmyparam;
-               numedg=0;
-               //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-               //return ;
-               return 0;
-               //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t
-             }
-           }
-         }
-       }
+      do {
+        if (PointInTheFace (face, APoint, _u, _v, myParamOnEdge, ++IndexPoint, surf,
+                            U1, V1, U2, V2,
+                            aVecD1U, aVecD1V))
+        {
+          ++NbPointsOK;
+          gp_Vec V (P, APoint);
+          Par = V.Magnitude();
+          if (Par > gp::Resolution())
+          {
+            gp_Vec Norm = aVecD1U.Crossed (aVecD1V);
+            Standard_Real tt = Norm.Magnitude();
+            tt = Abs (Norm.Dot (V)) / (tt * Par);
+            if (tt > maxscal)
+            {
+              maxscal = tt;
+              L = gp_Lin (P, V);
+              _Par = Par;
+              ptfound = Standard_True;
+              if (maxscal>0.2)
+              {
+                myParamOnEdge=svmyparam;
+                return 0;
+              }
+            }
+          }
+        }
       }
       while(IndexPoint<200 && NbPointsOK<16);
 
       myParamOnEdge=svmyparam;
-      numedg=0;
       if(maxscal>0.2) {                  
-       //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-       //return ;
        return 0;
-       //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t
       }
 
 
@@ -508,18 +547,14 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
       Standard_Boolean encoreuneface = faceexplorer.More();
       if(ptfound==Standard_False && encoreuneface==Standard_False) { 
        if(myParamOnEdge < 0.0001) { 
-         //-- Ce cas se produit lorsque le point est sur le solide
-         //-- et ce solide est reduit a une face 
+         //-- This case takes place when the point is on the solid
+         //-- and this solid is reduced to a face 
          gp_Pnt PBidon(P.X()+1.0,P.Y(),P.Z());
          gp_Vec V(P,PBidon);
          Par= 1.0;
          _Par=Par;
          L  = gp_Lin(P,V);
-         //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-         //return ;
          return 0;
-         //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t
-         //-- cout<<" FindAPoint **** Pas OK "<<endl;
        }
       }
     } //-- Exploration of the faces   
@@ -528,19 +563,13 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
       _Par=0.0;
       myReject=Standard_True;
 #if DEB
-      cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx  (Solid sans face)"<<endl;
+      cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx  (Solid without face)"<<endl;
 #endif  
-      //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-      //return ;
       return 0;
-      //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t    
     }
 
     if(ptfound) {
-      //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-      //return ;
       return 0;
-      //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t     
     }
     myFirstFace = 0;
     if(myParamOnEdge==0.512345)  myParamOnEdge = 0.4;
@@ -556,10 +585,7 @@ static Standard_Integer IsInfiniteUV (Standard_Real& U1, Standard_Real& V1,
     
   } //-- do { ...  } 
   while(1); 
-  //modified by NIZNHY-PKV Thu Nov 14 12:25:28 2002 f
-  //return ;
   return 0;
-  //modified by NIZNHY-PKV Thu Nov 14 12:25:33 2002 t 
 }
 
 //  Modified by skv - Thu Sep  4 12:30:14 2003 OCC578 Begin
@@ -708,7 +734,7 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
   myShape = S;
   myFirstFace = 0;
   myParamOnEdge = 0.512345;
-  //-- Exploration de la Map et delete sur les objets alloues
+  //-- Exploring of the Map and removal of allocated objects
   
   
   BRepClass3d_DataMapIteratorOfMapOfInter iter(myMapOfInter);
@@ -722,7 +748,7 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
   
   myMapOfInter.Clear();
   
-  myReject = Standard_True; //-- cas de solide infini (sans aucune face)
+  myReject = Standard_True; //-- case of infinite solid (without any face)
 
   TopExp_Explorer Expl;
   for(Expl.Init(S,TopAbs_FACE);
@@ -731,12 +757,12 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
     const TopoDS_Face Face = TopoDS::Face(Expl.Current());
     void *ptr = (void *)(new IntCurvesFace_Intersector(Face,Precision::Confusion()));
     myMapOfInter.Bind(Face,ptr);
-    myReject=Standard_False;  //-- au moins une face dans le solide 
+    myReject=Standard_False;  //-- at least one face in the solid 
   }
   
 #if DEB
   if(myReject) { 
-    cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx  (Solid sans face)"<<endl;
+    cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx  (Solid without face)"<<endl;
   }
 #endif      
 
@@ -753,7 +779,7 @@ void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
 //Standard_Boolean  BRepClass3d_SolidExplorer::Reject(const gp_Pnt& P) const 
 Standard_Boolean  BRepClass3d_SolidExplorer::Reject(const gp_Pnt& ) const 
 {
-  return(myReject);  // cas de solide sans face 
+  return(myReject);  // case of solid without face 
 }
 
 //=======================================================================
@@ -866,23 +892,15 @@ Standard_Boolean BRepClass3d_SolidExplorer::RejectFace(const gp_Lin& ) const
 //           one  intersection  with  the  shape  boundary  to
 //           compute  intersections. 
 //=======================================================================
-//modified by NIZNHY-PKV Thu Nov 14 14:40:35 2002 f
-//void  BRepClass3d_SolidExplorer::Segment(const gp_Pnt& P, 
-//                                      gp_Lin& L, 
-//                                      Standard_Real& Par)  {  
-//  myFirstFace = 0;
-//  OtherSegment(P,L,Par);
-//}
-  Standard_Integer  BRepClass3d_SolidExplorer::Segment(const gp_Pnt& P, 
-                                                      gp_Lin& L, 
-                                                      Standard_Real& Par)  
+Standard_Integer  BRepClass3d_SolidExplorer::Segment(const gp_Pnt& P, 
+                                                    gp_Lin& L, 
+                                                    Standard_Real& Par)  
 {
   Standard_Integer bRetFlag;
   myFirstFace = 0;
   bRetFlag=OtherSegment(P,L,Par);
   return bRetFlag;
 }
-//modified by NIZNHY-PKV Thu Nov 14 14:41:48 2002 t
 
 //=======================================================================
 //function : Intersector
@@ -919,6 +937,6 @@ void BRepClass3d_SolidExplorer::DumpSegment(const gp_Pnt&,
                                            const TopAbs_State) const
 {
 #ifdef DEB
-  // rien pour le moment.
 #endif
 }