Basic cube intersection algorithm