Redesigned the sorted_separatrix function.

Now it can handle the more general cases, when sorting has to be from
right to left or the starting point is on the bottom side, not the top one.