Salome HOME
Remove unnecessary includes
[modules/geom.git] / src / GEOMImpl / GEOMImpl_Fillet1d.cxx
index 041090e7708de98fd4e957f1dfdaa652e838ed71..085c57d408fdb54559759a4fe3e304717e49631c 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // 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
 #include <Precision.hxx>
 #include <TColStd_ListIteratorOfListOfReal.hxx>
 #include <IntRes2d_IntersectionSegment.hxx>
+#include <TopExp.hxx>
+
+#include <Standard_NotImplemented.hxx>
+
+
+/**
+ * This function returns Standard_True if it is possible to divide edge, i.e.
+ * if one parameter either start or end one is inside the edge. This function
+ * is used in the method GEOMImpl_Fillet1d::Result.
+ *
+ * \param theEdge the edge
+ * \param theStart the start parameter
+ * \param theEnd the end parameter
+ * \return Standard_True if it is possible to split edge;
+ *         Standard_False otherwise.
+ */
+static Standard_Boolean IsDivideEdge(const TopoDS_Edge   &theEdge,
+                                     const Standard_Real  theStart,
+                                     const Standard_Real  theEnd)
+{
+  Standard_Real      aFirst;
+  Standard_Real      aLast;
+  Handle(Geom_Curve) aCurve    = BRep_Tool::Curve(theEdge, aFirst, aLast);
+  gp_Pnt             aPStart   = aCurve->Value(theStart);
+  gp_Pnt             aPEnd     = aCurve->Value(theEnd);
+  TopoDS_Vertex      aVFirst   = TopExp::FirstVertex(theEdge);
+  TopoDS_Vertex      aVLast    = TopExp::LastVertex(theEdge);
+  Standard_Real      aTolFirst = BRep_Tool::Tolerance(aVFirst);
+  Standard_Real      aTolLast  = BRep_Tool::Tolerance(aVLast);
+  Standard_Real      aTolConf  = Precision::Confusion();
+  gp_Pnt             aPFirst   = BRep_Tool::Pnt(aVFirst);
+  gp_Pnt             aPLast    = BRep_Tool::Pnt(aVLast);
+  Standard_Real      aDistSF   = aPStart.Distance(aPFirst);
+  Standard_Real      aDistSL   = aPStart.Distance(aPLast);
+  Standard_Real      aDistEF   = aPEnd.Distance(aPFirst);
+  Standard_Real      aDistEL   = aPEnd.Distance(aPLast);
+  Standard_Boolean   isSplit   = Standard_True;
+
+  if (aDistSF <= aTolFirst + aTolConf ||
+      aDistSL <= aTolLast  + aTolConf) {
+    if (aDistEF <= aTolFirst + aTolConf ||
+        aDistEL <= aTolLast  + aTolConf) {
+
+      isSplit = Standard_False;
+      // in this case the original edge is thrown, and distance (gap) from new arc end
+      // to a vertex of original wire can reach (aVertexTolerance + Precision::Confusion()).
+      // Resulting wire is fixed (Mantis issue 0023411) in GEOMImpl_Fillet1dDriver::MakeFillet()
+    }
+  }
+
+  return isSplit;
+}
 
 /**
  * class GEOMImpl_Fillet1d
@@ -110,8 +162,8 @@ static Standard_Boolean isRadiusIntersected(const Handle(Geom2d_Curve)& theCurve
 {
   const Standard_Real aTol = Precision::Confusion();
   const Standard_Real anAngTol = Precision::Angular();
-  Geom2dAPI_InterCurveCurve anInter(theCurve, new Geom2d_Line(theStart,
-    gp_Dir2d(gp_Vec2d(theStart, theEnd))), aTol);
+  Handle(Geom2d_Line) aRadiusLine = new Geom2d_Line (theStart, gp_Dir2d(gp_Vec2d(theStart, theEnd)));
+  Geom2dAPI_InterCurveCurve anInter (theCurve, aRadiusLine, aTol);
   Standard_Integer a;
   gp_Pnt2d aPoint;
   for(a = anInter.NbPoints(); a > 0; a--)
@@ -127,23 +179,9 @@ static Standard_Boolean isRadiusIntersected(const Handle(Geom2d_Curve)& theCurve
   Handle(Geom2d_Curve) aCurve;
   for(a = anInter.NbSegments(); a > 0; a--)
   {
-    anInter.Segment(a, aCurve);
-    aPoint = aCurve->Value(aCurve->FirstParameter());
-    if (aPoint.Distance(theStart) < aTol)
-      if (!theStartConnected)
-        return Standard_True;
-    if (aPoint.Distance(theEnd) < aTol)
-      return Standard_True;
-    if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), anAngTol))
-      return Standard_True;
-    aPoint = aCurve->Value(aCurve->LastParameter());
-    if (aPoint.Distance(theStart) < aTol)
-      if (!theStartConnected)
-        return Standard_True;
-    if (aPoint.Distance(theEnd) < aTol)
-      return Standard_True;
-    if (gp_Vec2d(aPoint, theStart).IsOpposite(gp_Vec2d(aPoint, theEnd), anAngTol))
-      return Standard_True;
+    // Porting to DEV version of OCCT 10.02.2017 BEGIN
+    Standard_NotImplemented::Raise("The treatment of tangential intersection is not implemented");
+    // Porting to DEV version of OCCT 10.02.2017 END
   }
   return Standard_False;
 }
@@ -305,7 +343,7 @@ Standard_Boolean GEOMImpl_Fillet1d::Perform(const Standard_Real theRadius)
           aParam2 > myStart1 + aTol && aParam2 < myEnd1 - aTol) {
         // Add the point in the list in increasing order.
         const Standard_Real aParam = 0.5*(aParam1 + aParam2);
-  
+
         for(anIter.Initialize(aParams); anIter.More(); anIter.Next()) {
           if (anIter.Value() > aParam) {
             aParams.InsertBefore(aParam, anIter);
@@ -540,7 +578,7 @@ TopoDS_Edge GEOMImpl_Fillet1d::Result(const gp_Pnt& thePoint,
   aTargetPoint2d.SetCoord(aX, aY);
 
   // choose the nearest circle
-  Standard_Real aDistance, aP;
+  Standard_Real aDistance = 0., aP; // todo: aDistance must be explicitly initialized to avoid warning (see below)
   GEOMImpl_Fillet1dPoint *aNearest;
   Standard_Integer a;
   TColStd_ListIteratorOfListOfReal anIter(myResultParams);
@@ -552,7 +590,7 @@ TopoDS_Edge GEOMImpl_Fillet1d::Result(const gp_Pnt& thePoint,
     if (!aPoint->HasSolution(myRadius))
       continue;
     aP = fabs(aPoint->GetCenter().Distance(aTargetPoint2d) - myRadius);
-    if (!aNearest || aP < aDistance)
+    if (!aNearest || aP < aDistance) // todo: aDistance must be explicitly initialized to avoid warning (see above)
     {
       aNearest = aPoint;
       aDistance = aP;
@@ -617,7 +655,7 @@ TopoDS_Edge GEOMImpl_Fillet1d::Result(const gp_Pnt& thePoint,
   else
     anEnd = aNearest->GetParam();
 
-  if (fabs(aStart - anEnd) > Precision::Confusion())
+  if (IsDivideEdge(myEdge1, aStart, anEnd))
   {
       //Divide edge
       BRepBuilderAPI_MakeEdge aDivider1(aCurve, aStart, anEnd);
@@ -636,7 +674,7 @@ TopoDS_Edge GEOMImpl_Fillet1d::Result(const gp_Pnt& thePoint,
   else
     anEnd = aNearest->GetParam2();
 
-  if (fabs(aStart - anEnd) > Precision::Confusion())
+  if (IsDivideEdge(myEdge2, aStart, anEnd))
   {
       BRepBuilderAPI_MakeEdge aDivider2(aCurve, aStart, anEnd);
       if (myEdgesExchnged)
@@ -677,7 +715,7 @@ Standard_Boolean GEOMImpl_Fillet1dPoint::ComputeDifference(GEOMImpl_Fillet1dPoin
 {
   Standard_Integer a;
   Standard_Boolean aDiffsSet = (myD.Length() != 0);
-  Standard_Real aDX = thePoint->GetParam() - myParam, aDY;
+  Standard_Real aDX = thePoint->GetParam() - myParam, aDY = 0.; // todo: aDY must be explicitly initialized to avoid warning (see below)
   if (thePoint->myV.Length() == myV.Length())
   { // absolutely the same points
     for(a = 1; a <= myV.Length(); a++)
@@ -708,7 +746,7 @@ Standard_Boolean GEOMImpl_Fillet1dPoint::ComputeDifference(GEOMImpl_Fillet1dPoin
     }
     else
     {
-      myD.Append( fabs(aDX) > gp::Resolution() ? aDY/aDX : 0);
+      myD.Append( fabs(aDX) > gp::Resolution() ? aDY/aDX : 0); // todo: aDY must be explicitly initialized to avoid warning (see above)
     }
   }