Refactors triangle intersection to make it faster and clear