Salome HOME
The algorithm to split any curve by any point was fixed to rightly split the curve...
authorabk <abk@opencascade.com>
Tue, 30 Jun 2015 17:16:09 +0000 (20:16 +0300)
committerabk <abk@opencascade.com>
Tue, 30 Jun 2015 17:16:09 +0000 (20:16 +0300)
src/HYDROData/HYDROData_PolylineOperator.cxx

index 92c766c3e423b2c92495afa949a2699899d42c56..acec03bc92e29fc11ce8ba12797f2a41b99bdb54 100644 (file)
@@ -49,6 +49,25 @@ template<class T> void append( std::vector<T>& theList, const std::vector<T>& th
     theList[i] = theList2[j];
 }
 
+static TopoDS_Edge ReplaceVertex(
+  const TopoDS_Edge& theEdge, Standard_Integer theVertexIndex)
+{
+  TopoDS_Vertex aVertices[] =
+    {TopExp::FirstVertex(theEdge), TopExp::LastVertex(theEdge)};
+  const TopAbs_Orientation aOrient = theEdge.Orientation();
+  if (aOrient == TopAbs_REVERSED)
+  {
+    theVertexIndex ^= 1;
+  }
+  aVertices[theVertexIndex].EmptyCopy();
+  aVertices[0].Orientation(TopAbs_FORWARD);
+  aVertices[1].Orientation(TopAbs_REVERSED);
+  TopoDS_Edge aFE = TopoDS::Edge(theEdge.Oriented(TopAbs_FORWARD));
+  TopoDS_Edge aNewEdge =
+    ShapeBuild_Edge().CopyReplaceVertices(aFE, aVertices[0], aVertices[1]);
+  return TopoDS::Edge(aNewEdge.Oriented(aOrient));
+}
+
 static Standard_Boolean WireToCurve(
   const TopoDS_Wire& theWire,
   NCollection_Vector<TopoDS_Edge>& theEdges,
@@ -253,22 +272,16 @@ static void SplitCurveByPoint(
     aParamI ^= 1;
   }
 
+  NCollection_Vector<TopoDS_Edge>* aEdges = &theEdges2;
   const Standard_Integer aECount = theEdges.Size();
   if (aParamI == 0)
   {
-    NCollection_Vector<TopoDS_Edge>* aEdges = (theEdgeIndex != 0) ? &theEdges1 : &theEdges2;
-    for (Standard_Integer aEI = theEdgeIndex; aEI < aECount; ++aEI)
-    {
-      aEdges->Append(theEdges(aEI));
-    }
+    aEdges = (theEdgeIndex == 0) ? &theEdges1 : &theEdges2;
+    aEdges->Append(ReplaceVertex(aEdge, 0));
   }
   else if (aParamI == 1)
   {
-    theEdges1.Append(aEdge);
-    for (Standard_Integer aEI = theEdgeIndex; aEI < aECount; ++aEI)
-    {
-      theEdges2.Append(theEdges(aEI));
-    }
+    theEdges1.Append(ReplaceVertex(aEdge, 1));
   }
   else
   {
@@ -280,7 +293,6 @@ static void SplitCurveByPoint(
       aSplitV1, aCurve.Value(theParameter), Precision::Confusion());
     BRep_Builder().MakeVertex(
       aSplitV2, aCurve.Value(theParameter), Precision::Confusion());
-
     TopoDS_Edge aEParts[] = {
       ShapeBuild_Edge().CopyReplaceVertices(aFE, TopoDS_Vertex(),
         TopoDS::Vertex(aSplitV1.Oriented(TopAbs_REVERSED))),
@@ -301,11 +313,10 @@ static void SplitCurveByPoint(
     const Standard_Integer aFirstPI = (aOrient != TopAbs_REVERSED) ? 0 : 1;
     theEdges1.Append(aEParts[aFirstPI]);
     theEdges2.Append(aEParts[1 - aFirstPI]);
-
-    for (Standard_Integer aEI = theEdgeIndex + 1; aEI < aECount; ++aEI)
-    {
-      theEdges2.Append(theEdges(aEI));
-    }
+  }
+  for (Standard_Integer aEI = theEdgeIndex + 1; aEI < aECount; ++aEI)
+  {
+    aEdges->Append(theEdges(aEI));
   }
 }