Brute force self intersection algorithm. Refactoring.