Neighbors when one of the segments is added, and the first check will catch the intersection
Neighbors when another segment is deleted, and the second check will catch the intersection
The intersecting lines will eventually intersect the sweep line.
No false positives
Sweep line: RB tree contains 1 Sweep line: RB tree contains 2, 1, no intersect Sweep line: RB tree contains 2, 1, 3, no intersect Sweep line: RB tree contains 2, 3, intersect Sweep line: RB tree contains 2, 4, 3, no intersect Sweep line: RB tree contains 2, 4, 3, 5, no intersect Sweep line: RB tree contains 2, 4, 3, no intersect Sweep line: RB tree contains 2, 3, intersect Sweep line: RB tree is empty
For n segments: sort segments n lg n n RB-Inserts n lg n n RB-Deletes n lg n O(1) comparison
Scanline Algorithm Applet