This question evaluates computational geometry and algorithmic skills, specifically collinearity detection, geometric segment intersection, merging of overlapping segments, sorting of points along a line, and deduplication of vertices.
You are given a list of 2D line segments. Each segment is represented as a list of 2D points [(x1,y1), (x2,y2), ...] that all lie on the same straight line.
When merging multiple segments, the result for that merged group should contain all distinct points that appear in any of the original segments in the group, sorted along the line.
Return a list of merged segments (each as a sorted list of points). The order of merged segments in the output does not matter.
Input
[
[(1, 1), (2, 2), (4, 4)],
[(2, 1), (4, 2)],
[(3, 3), (6, 6)],
[(7, 7), (8, 8)]
]
Output (one valid ordering)
[
[(1, 1), (2, 2), (3, 3), (4, 4), (6, 6)],
[(7, 7), (8, 8)],
[(2, 1), (4, 2)]
]