refactor pruneSelfIntersections