+
+//=======================================================================
+//function : MakeChain
+//purpose :
+//=======================================================================
+static void MakeChain(const TopoDS_Shape& theV,
+ const TopTools_IndexedDataMapOfShapeListOfShape& theDMVV,
+ TopTools_MapOfShape& theMDone,
+ BOPCol_ListOfShape& theChain)
+{
+ if (theMDone.Add(theV)) {
+ theChain.Append(theV);
+ const TopTools_ListOfShape* pLV = theDMVV.Seek(theV);
+ if (pLV) {
+ TopTools_ListIteratorOfListOfShape aIt(*pLV);
+ for (; aIt.More(); aIt.Next()) {
+ MakeChain(aIt.Value(), theDMVV, theMDone, theChain);
+ }
+ }
+ }
+}
+
+//=======================================================================
+//function : FuseVertices
+//purpose :
+//=======================================================================
+void BRepOffset_Inter2d::FuseVertices(const TopTools_IndexedDataMapOfShapeListOfShape& theDMVV,
+ const Handle(BRepAlgo_AsDes)& theAsDes)
+{
+ BRep_Builder aBB;
+ TopTools_MapOfShape aMVDone;
+ Standard_Integer i, aNb = theDMVV.Extent();
+ for (i = 1; i <= aNb; ++i) {
+ const TopoDS_Vertex& aV = TopoDS::Vertex(theDMVV.FindKey(i));
+ //
+ // find chain of vertices
+ BOPCol_ListOfShape aLVChain;
+ MakeChain(aV, theDMVV, aMVDone, aLVChain);
+ //
+ if (aLVChain.Extent() < 2) {
+ continue;
+ }
+ //
+ // make new vertex
+ TopoDS_Vertex aVNew;
+ BOPTools_AlgoTools::MakeVertex(aLVChain, aVNew);
+ //
+ TopoDS_Vertex aVNewInt = TopoDS::Vertex(aVNew.Oriented(TopAbs_INTERNAL));
+ //
+ BOPCol_ListIteratorOfListOfShape aIt(aLVChain);
+ for (; aIt.More(); aIt.Next()) {
+ const TopoDS_Shape& aVOld = aIt.Value();
+ // update the parameters on edges
+ TopoDS_Vertex aVOldInt = TopoDS::Vertex(aVOld.Oriented(TopAbs_INTERNAL));
+ const TopTools_ListOfShape& aLE = theAsDes->Ascendant(aVOld);
+ //
+ TopTools_ListIteratorOfListOfShape aItLE(aLE);
+ for (; aItLE.More(); aItLE.Next()) {
+ const TopoDS_Edge& aE = TopoDS::Edge(aItLE.Value());
+ Standard_Real aTolE = BRep_Tool::Tolerance(aE);
+ Standard_Real aT = BRep_Tool::Parameter(aVOldInt, aE);
+ aBB.UpdateVertex(aVNewInt, aT, aE, aTolE);
+ }
+ // and replace the vertex
+ theAsDes->Replace(aVOld, aVNew);
+ }
+ }
+}