Line segment intersection
Check whether segments AB and CD have any point in common. Move their endpoints on the grid.
If the projections overlap, test both pairs of turns. For each line the other segment’s endpoints must be on opposite sides or on the line itself.
A shared endpoint and an overlapping stretch on one line both count as intersections.
Two projection checks and four turns suffice. Time and extra space are O(1).