+ // remove branches ending at BE_ON_VERTEX
+
+ vector<bool> isBranchRemoved( branchEdges.size(), false );
+
+ if ( ignoreCorners && branchEdges.size() > 2 && !branchEdges[2].empty() )
+ {
+ // find branches to remove
+ map< const TVDVertex*, SMESH_MAT2d::BranchEndType >::iterator v2et;
+ for ( size_t iB = 1; iB < branchEdges.size(); ++iB )
+ {
+ if ( branchEdges[iB].empty() )
+ continue;
+ const TVDVertex* v0 = branchEdges[iB][0]->vertex1();
+ const TVDVertex* v1 = branchEdges[iB].back()->vertex0();
+ v2et = endType.find( v0 );
+ if ( v2et != endType.end() && v2et->second == SMESH_MAT2d::BE_ON_VERTEX )
+ isBranchRemoved[ iB ] = true;
+ v2et = endType.find( v1 );
+ if ( v2et != endType.end() && v2et->second == SMESH_MAT2d::BE_ON_VERTEX )
+ isBranchRemoved[ iB ] = true;
+ }
+ // try to join not removed branches into one
+ for ( size_t iB = 1; iB < branchEdges.size(); ++iB )
+ {
+ if ( branchEdges[iB].empty() || isBranchRemoved[iB] )
+ continue;
+ const TVDVertex* v0 = branchEdges[iB][0]->vertex1();
+ const TVDVertex* v1 = branchEdges[iB].back()->vertex0();
+ v2et = endType.find( v0 );
+ if ( v2et == endType.end() || v2et->second != SMESH_MAT2d::BE_BRANCH_POINT )
+ v0 = 0;
+ v2et = endType.find( v1 );
+ if ( v2et == endType.end() || v2et->second != SMESH_MAT2d::BE_BRANCH_POINT )
+ v1 = 0;
+ if ( !v0 && !v1 )
+ continue;
+
+ size_t iBrToJoin = 0;
+ for ( size_t iB2 = 1; iB2 < branchEdges.size(); ++iB2 )
+ {
+ if ( branchEdges[iB2].empty() || isBranchRemoved[iB2] || iB == iB2 )
+ continue;
+ const TVDVertex* v02 = branchEdges[iB2][0]->vertex1();
+ const TVDVertex* v12 = branchEdges[iB2].back()->vertex0();
+ if ( v0 == v02 || v0 == v12 || v1 == v02 || v1 == v12 )
+ {
+ if ( iBrToJoin > 0 )
+ {
+ iBrToJoin = 0;
+ break; // more than 2 not removed branches meat at a TVDVertex
+ }
+ iBrToJoin = iB2;
+ }
+ }
+ if ( iBrToJoin > 0 )
+ {
+ vector<const TVDEdge*>& branch = branchEdges[ iBrToJoin ];
+ const TVDVertex* v02 = branch[0]->vertex1();
+ const TVDVertex* v12 = branch.back()->vertex0();
+ updateJoinedBranch( branch, iB, bndSegs, /*reverse=*/(v0 == v02 || v1 == v12 ));
+ if ( v0 == v02 || v0 == v12 )
+ branchEdges[iB].insert( branchEdges[iB].begin(), branch.begin(), branch.end() );
+ else
+ branchEdges[iB].insert( branchEdges[iB].end(), branch.begin(), branch.end() );
+ branch.clear();
+ }
+ } // loop on branchEdges
+ } // if ( ignoreCorners )
+