Rewrite avoid_crossing_perimeters() to fix a regression and get better performance by choosing regular points along contours. #1531