... i want to add the control where it goes in the direction of the line.
there wouldnt be point to the right of the line
the points wouldnt be random.
If there are no points on the right, then sorting by X is enough, maybe just changing "<" to ">", you first code should do it.
Sorry, but for me, "control where it goes in the direction of the line" has no meaning.
Better draw some points, draw a line, label the points in the order you want them. Repeat for other situations. Post a screenshot.