I have a list of line segments on a plane (It's a class with 2 instances for the initial and final vertex). In my code, I detect which segments intersect with a previously inserted line and all those segments are then inserted into a list.
The segment class also has a function that can return a number based on it's position compared to other segment (the value itself doesn't matter, only the sign), which tells me if this segment being compared is to the left or to the right of the other segment.
I'd like to know if it is possible to sort a list using that kind of comparison function, since, so far, I've been able to find only sorting based on functions that return "meaningful" numbers (e.g., x
is less than y
, so x
comes first)
Simply put, I have some line segments in a list, and I'd like to sort them out with a function that only tells me if a certain segment, say, S1
is to the right or to the left of another segment S2
and nothing else.