int getHalfEdgeConnector ( int clusterFrom , int clusterTo ) { int first_edge = getClusterHalfEdge ( clusterFrom ) ; if ( first_edge == - 1 ) return - 1 ; int edge = first_edge ; int firstEdgeTo = - 1 ; int eTo = - 1 ; // Doing two loops in parallel - one on the half-edges attached to the // clusterFrom, another - attached to clusterTo. do { if ( getHalfEdgeTo ( edge ) == clusterTo ) return edge ; if ( firstEdgeTo == - 1 ) { firstEdgeTo = getClusterHalfEdge ( clusterTo ) ; if ( firstEdgeTo == - 1 ) return - 1 ; eTo = firstEdgeTo ; } if ( getHalfEdgeTo ( eTo ) == clusterFrom ) { edge = getHalfEdgeTwin ( eTo ) ; assert ( getHalfEdgeTo ( edge ) == clusterTo && getHalfEdgeOrigin ( edge ) == clusterFrom ) ; return edge ; } edge = getHalfEdgeNext ( getHalfEdgeTwin ( edge ) ) ; eTo = getHalfEdgeNext ( getHalfEdgeTwin ( eTo ) ) ; } while ( edge != first_edge && eTo != firstEdgeTo ) ; return - 1 ; }
Could be a slow operation when valency of each cluster is high .