This will be used in the 3D prism engine to provide true depth sorting. The algorithm used here is very efficient. This snippet of code returns whether, from the perspective of P, AB is behind CD or vice versa. Line segments cannot intersect. P is essentially the camera.
How it works: Given segment AB, segment CD and a point P, we can determine which segment is front of the other by focusing on one segment and checking which side the other segment is on, vs the point. 1. Segment CD on both sides of AB => inconclusive repeat test on CD. 2. Segment CD and P on same side of AB => AB is behind CD. 3. Segment CD and P on different sides of AB => CD is behind AB