+ //================================================================================
+ /*!
+ * \brief Checks if all border parts include the whole closed border, and if so
+ * returns \c true and choose starting BEdge's with most coincident nodes
+ */
+ //================================================================================
+
+ bool chooseStartOfClosedBorders( std::vector< BEdge* >& ranges ) // PAL23078#c21002
+ {
+ bool allClosed = true;
+ for ( size_t iR = 1; iR < ranges.size() && allClosed; iR += 2 )
+ allClosed = ( ranges[ iR-1 ]->myPrev == ranges[ iR ] );
+ if ( !allClosed )
+ return allClosed;
+
+ double u, minDiff = Precision::Infinite();
+ std::vector< BEdge* > start( ranges.size() / 2 );
+ BEdge* range0 = start[0] = ranges[0];
+ do
+ {
+ double maxDiffU = 0;
+ double maxDiff = 0;
+ for ( size_t iR = 3; iR < ranges.size(); iR += 2 )
+ {
+ int borderID = ranges[iR]->myBorderID;
+ if ( BEdge* e = start[0]->myBNode1->GetCloseEdgeOfBorder( borderID, & u ))
+ {
+ start[ iR / 2 ] = e;
+ double diffU = Min( Abs( u ), Abs( 1.-u ));
+ double diff = e->myBNode1->SquareDistance( *e->myBNode2 ) * diffU * diffU;
+ maxDiffU = Max( diffU, maxDiffU );
+ maxDiff = Max( diff, maxDiff );
+ }
+ }
+ if ( maxDiff < minDiff )
+ {
+ minDiff = maxDiff;
+ for ( size_t iR = 1; iR < ranges.size(); iR += 2 )
+ {
+ ranges[ iR-1 ] = start[ iR/2 ];
+ ranges[ iR ] = ranges[ iR-1]->myPrev;
+ }
+ }
+ if ( maxDiffU < 1e-6 )
+ break;
+ start[0] = start[0]->myNext;
+ }
+ while ( start[0] != range0 );
+
+ return allClosed;
+ }
+
+ //================================================================================
+ /*!
+ * \brief Tries to include neighbor BEdge's into a border part
+ */
+ //================================================================================
+