Salome HOME
Fix valgrind error: Mismatched free() / delete / delete []
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_GetInPlace_1.cxx
index 25f418db438c730c2b98be6b174b984475aa6c23..7beb5d1a949a9803e16af116f95fe534bc5054b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,8 +20,8 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-// File:       GEOMAlgo_GetInPlace_1.cxx
-// Author:     Peter KURNEV
+// File:        GEOMAlgo_GetInPlace_1.cxx
+// Author:      Peter KURNEV
 
 #include <GEOMAlgo_GetInPlace.hxx>
 
 
 #include <IntTools_Tools.hxx>
 
-#include <BOPTools_Tools3D.hxx>
-#include <BOPTools_Tools2D.hxx>
+#include <GEOMAlgo_AlgoTools.hxx>
 
 
 
 static
   Standard_Integer PntInEdge(const TopoDS_Edge& aF,
-                            gp_Pnt& aP);
+                             gp_Pnt& aP);
 static
   Standard_Integer PntInEdge(const TopoDS_Edge& aF,
-                            gp_Pnt& aP,
-                            Standard_Real& aT);
+                             gp_Pnt& aP,
+                             Standard_Real& aT);
 static
   Standard_Integer PntInFace(const TopoDS_Face& aF,
-                            gp_Pnt& aP);
+                             gp_Pnt& aP);
 static
   Standard_Integer PntInFace(const TopoDS_Face& aF,
-                            gp_Pnt& aP,
-                            gp_Pnt2d& theP2D);
+                             gp_Pnt& aP,
+                             gp_Pnt2d& theP2D);
 static
   Standard_Integer PntInSolid(const TopoDS_Solid& aZ,
-                             const Standard_Real aTol,
-                             gp_Pnt& aP);
+                              const Standard_Real aTol,
+                              gp_Pnt& aP);
 
 
 //=======================================================================
@@ -89,7 +88,7 @@ static
 //purpose  :
 //=======================================================================
 Standard_Boolean GEOMAlgo_GetInPlace::CheckCoincidence(const TopoDS_Shape& aS1,
-                                                      const TopoDS_Shape& aS2)
+                                                       const TopoDS_Shape& aS2)
 {
   Standard_Boolean bOk;
   Standard_Integer iErr;
@@ -157,11 +156,11 @@ Standard_Boolean GEOMAlgo_GetInPlace::CheckCoincidence(const TopoDS_Shape& aS1,
       aDmin=aPPC.LowerDistance();
       aT=aPPC.LowerDistanceParameter();
       if (aDmin < myTolerance) {
-       dT=1.e-12;
-       BRep_Tool::Curve(aE1, aT1, aT2);
+        dT=1.e-12;
+        BRep_Tool::Curve(aE1, aT1, aT2);
         if(aT > (aT1-dT) && aT < (aT2+dT)) {
-         bOk=Standard_True;
-       }
+          bOk=Standard_True;
+        }
       }
     }
     //else {
@@ -197,7 +196,7 @@ Standard_Boolean GEOMAlgo_GetInPlace::CheckCoincidence(const TopoDS_Shape& aS1,
 //purpose  :
 //=======================================================================
 Standard_Integer PntInEdge(const TopoDS_Edge& aE,
-                          gp_Pnt& aP)
+                           gp_Pnt& aP)
 
 {
   Standard_Integer iErr;
@@ -212,8 +211,8 @@ Standard_Integer PntInEdge(const TopoDS_Edge& aE,
 //purpose  :
 //=======================================================================
 Standard_Integer PntInEdge(const TopoDS_Edge& aE,
-                          gp_Pnt& aP,
-                          Standard_Real& aT)
+                           gp_Pnt& aP,
+                           Standard_Real& aT)
 {
   Standard_Integer iErr;
   Standard_Real aT1, aT2;
@@ -232,15 +231,14 @@ Standard_Integer PntInEdge(const TopoDS_Edge& aE,
 //purpose  :
 //=======================================================================
 Standard_Integer PntInSolid(const TopoDS_Solid& aZ,
-                           const Standard_Real aTol,
-                           gp_Pnt& aP)
+                            const Standard_Real aTol,
+                            gp_Pnt& aP)
 {
   Standard_Integer iErr;
   Standard_Real aUx, aVx, aCoef;
   gp_Pnt aPx;
   gp_Pnt2d aP2Dx;
   gp_Vec aDNx;
-
   TopoDS_Face aF;
   TopExp_Explorer aExp;
   //
@@ -248,9 +246,8 @@ Standard_Integer PntInSolid(const TopoDS_Solid& aZ,
   aCoef=10.;
   //
   aExp.Init (aZ, TopAbs_FACE);
-  for (; aExp.More() ; aExp.Next()) {
+  if (aExp.More()) {
     aF=*((TopoDS_Face*)&aExp.Current());
-    break;
   }
   //
   iErr=PntInFace(aF, aPx, aP2Dx);
@@ -259,7 +256,7 @@ Standard_Integer PntInSolid(const TopoDS_Solid& aZ,
   }
   //
   aP2Dx.Coord(aUx, aVx);
-  BOPTools_Tools2D::FaceNormal(aF, aUx, aVx, aDNx);
+  GEOMAlgo_AlgoTools::FaceNormal(aF, aUx, aVx, aDNx);
   aDNx.Reverse();
   //
   aP.SetXYZ(aPx.XYZ()+aCoef*aTol*aDNx.XYZ());
@@ -271,7 +268,7 @@ Standard_Integer PntInSolid(const TopoDS_Solid& aZ,
 //purpose  :
 //=======================================================================
 Standard_Integer PntInFace(const TopoDS_Face& aF,
-                          gp_Pnt& aP)
+                           gp_Pnt& aP)
 {
   Standard_Integer iErr;
   //
@@ -286,8 +283,8 @@ Standard_Integer PntInFace(const TopoDS_Face& aF,
 //purpose  :
 //=======================================================================
 Standard_Integer PntInFace(const TopoDS_Face& aF,
-                          gp_Pnt& theP,
-                          gp_Pnt2d& theP2D)
+                           gp_Pnt& theP,
+                           gp_Pnt2d& theP2D)
 {
   Standard_Boolean bIsDone, bHasFirstPoint, bHasSecondPoint;
   Standard_Integer iErr, aIx, aNbDomains, i;
@@ -312,8 +309,8 @@ Standard_Integer PntInFace(const TopoDS_Face& aF,
   //
   Geom2dHatch_Intersector aIntr(aTotArcIntr, aTolTangfIntr);
   Geom2dHatch_Hatcher aHatcher(aIntr,
-                              aTolHatch2D, aTolHatch3D,
-                              Standard_True, Standard_False);
+                               aTolHatch2D, aTolHatch3D,
+                               Standard_True, Standard_False);
   //
   iErr=0;
   aEpsT=1.e-12;
@@ -369,29 +366,31 @@ Standard_Integer PntInFace(const TopoDS_Face& aF,
   //
   // 4.
   aNbDomains=aHatcher.NbDomains(aIx);
-  for (i=1; i<=aNbDomains; ++i) {
-    const HatchGen_Domain& aDomain=aHatcher.Domain (aIx, i) ;
-    bHasFirstPoint=aDomain.HasFirstPoint();
-    if (!bHasFirstPoint) {
-      iErr=5;
-      return iErr;
-    }
-    //
-    aV1=aDomain.FirstPoint().Parameter();
-    //
-    bHasSecondPoint=aDomain.HasSecondPoint();
-    if (!bHasSecondPoint) {
-      iErr=6;
-      return iErr;
-    }
-    //
-    aV2=aDomain.SecondPoint().Parameter();
-    //
-    aVx=IntTools_Tools::IntermediatePoint(aV1, aV2);
-    //
-    break;
+  if (!aNbDomains) {
+    iErr=5;
+    return iErr;
+  }
+  //
+  i=1;
+  const HatchGen_Domain& aDomain=aHatcher.Domain (aIx, i) ;
+  bHasFirstPoint=aDomain.HasFirstPoint();
+  if (!bHasFirstPoint) {
+    iErr=5;
+    return iErr;
+  }
+  //
+  aV1=aDomain.FirstPoint().Parameter();
+  //
+  bHasSecondPoint=aDomain.HasSecondPoint();
+  if (!bHasSecondPoint) {
+    iErr=6;
+    return iErr;
   }
   //
+  aV2=aDomain.SecondPoint().Parameter();
+  //
+  aVx=IntTools_Tools::IntermediatePoint(aV1, aV2);
+  //
   aS->D0(aUx, aVx, aPx);
   //
   theP2D.SetCoord(aUx, aVx);