Use nearest-neighbor search for internal perimeters too. #1025