bilayerCrossCount algorithm