
I have a list of segments and I need to sort them on the y axis.
Now I don't know if it really is possible with a simple solution because there are many situations in which the segments can be placed.
The image illustrates it but basically, if two walls are intersecting on the y axis, I want to know which one is the lowest between the two.
I've tried thinking of the different positions and thinking about how it would work in terms of one of the points being bigger or smaller. However, I feel that there are way too many possibilities and I would easily miss some use cases. Would there be some kind of way to compare two segments and tell which one is lower? Maybe with vector calculation? I'm out of ideas.
I'm using JavaScript and it's array.sort() function with a custom compare function but my question is more of a geometry/math problem.