How Overlapping Segments Participate in the Sweep
When a sweep line encounters two overlapping segments, they stay at the same height over a range. Which one goes above the other? If a third line crosses the overlap, which input pairs should be reported?
This is Chapter 5 of the segment-intersection series. We remove the restriction against nonzero-length overlaps while continuing to allow the same-point events and point inputs from Chapter 4, "Handle Everything at the Same Point Together". We retain two teaching conditions: nonzero inputs are not vertical, and different event positions have different horizontal coordinates. Several endpoints may share one position. Here event positions are input endpoints and actual intersections on different supporting lines; not every point of an overlap interval is an event.
This article adds only the mechanisms needed for overlap. Original identities and complete intersections follow Chapter 1; exact collinearity tests and closed-interval calculations follow Chapter 3. We now need to decide when to use these results and how to maintain the active order and future events.
Section 1: One position in the order, with every input identity retained inside the group
Start with three nonzero inputs, all on the line :
| Input | Left endpoint | Right endpoint |
|---|---|---|
When , all three inputs are active, and the sweep line meets them at the same point. No permutation of their three identifiers makes one geometrically higher than another. Treating them as three distinct height positions would introduce an internal order with no geometric meaning into the notion of "two neighbors."
We place nonzero inputs with the same supporting line in one collinear group. Each nonempty group occupies one position in the active order; within it we separately store the original identities of its currently active inputs. The three inputs above belong to group , whose fixed line is .
All figures in this article are teaching diagrams, not actual execution traces. Read the panels in their displayed order; they wrap when space is insufficient, and each retains its original 320 × 260 size. Overlapping members in separate panels have not been shifted to different heights. Both axes use equal units, and marks the origin. The text gives the detailed coordinates and processing rules.
Grouping uses the exact relationship between lines, not merely equal slopes, and certainly not visual closeness. The parallel-versus-collinear classification from Chapter 3 identifies the same line; distinct parallel lines belong to different groups.
A group's line does not change with its members, but which members currently belong to it does change. For example, belongs to , but has not started when and cannot count as a currently active member. Nor does grouping merge all collinear inputs into a new input: reporting results still requires the original identifiers and endpoints.
Point inputs keep their separate role from Chapter 4. A point does not determine a unique line, so we assign it no invented collinear group and do not retain it in the active order on the right.
Section 2: Report the complete intersection when a new member joins
In the three-input example, starts first. At , starts while has not yet ended. They are collinear and both contain the current position, so they can be paired now.
The complete-interval result from Chapter 3 gives the intersection of as the interval from to . Although the sweep has not reached , the two original right endpoints are already known, so all information needed for reporting is available. Sweep progress limits who belongs to the current active set, not access to the complete endpoints of a known input.
Use this order: each new member first reports its complete intersection with every member then in the same group, and only then joins the member set itself. Retain old members ending at the current point until closed-endpoint pairing is complete, then remove them.
| Event horizontal coordinate | Collinear pairing and new results | Members of after the event |
|---|---|---|
| starts; no old member to pair with | ||
| with : from to | ||
| with , and with : each pair intersects from to | ||
| ends; do not enumerate old member pairs again | ||
| ends; do not report again | ||
| ends | Empty |
These three results are the complete intersections for all three unordered input pairs in this example. overlap partially, while is nested inside both. The same joining rule handles all of them; nesting does not need a separate sweep procedure.
Several inputs starting at the same point
Take a separate example: all occupy the segment from to , but has its endpoints written in reverse order, . After normalizing left and right endpoints, all three start at and still have three separate original identities.
Within the same event, process the starters in original-identifier order. joins first. pairs with the already joined , then joins. pairs separately with the already joined , then joins. Each of the three pairs retains one complete interval from to .
The procedure is unchanged if more inputs start at the same point. For any two of them, the earlier joiner becomes a pairing partner of the later joiner. Treating every starter as "not yet in the group" while checking only older members would miss pairs between new members.
Why ending members must stay until pairing finishes
Take another two-input example containing only and a new input , where runs from to . At , first pair the starting with , which has not yet been removed. Their complete intersection is the closed endpoint . Only then remove .
This reuses the closed-endpoint processing order from Chapter 4. The new point is that it also applies when members hand over within a group. Collinear pairing may report a point or a nonzero-length interval; it cannot always be described as "outputting an overlap."
Why every intersecting collinear input pair is reported exactly once
Take any two distinct collinear nonzero inputs . Let be the horizontal coordinates of the left and right endpoints of , and those of the other input. Being nonzero and nonvertical ensures and .
First suppose . If the inputs intersect, the closed-range result of Chapter 3 guarantees ; otherwise the first would end before the second starts, leaving no shared range. At the event where the second starts, the first has already joined and has not yet left: if it still passes through, and if it is retained as an ending member until reporting finishes. This pair is therefore processed when joins.
If , exchange the earlier and later roles; the same reasoning ensures processing when joins. If , equal horizontal coordinates on the same nonvertical line mean the same position, so the two are same-point starters. The sequential joining rule above pairs them when the later-processed one joins.
These cases cover every possible start order. Each input starts only once, and later endings or external crossings do not enumerate old collinear member pairs again, so each pair is reported only once. Conversely, an old member paired at joining time shares the new member's line and contains the current point, so their intersection really is nonempty; its complete range is determined by the original endpoints. Thus no result is missed or invented. Disjoint collinear inputs cannot appear together in such a pairing list.
There is no need to build another list of "already output input pairs" to prove uniqueness. This section directly restricts when a pair is generated, instead of generating duplicates first and deleting them later.
Section 3: Expand only cross-group pairs at an external crossing
Return to and add the nonzero input , from to , on the line . Also add the point input , whose endpoints are both . This section uses only these five inputs.
At , has height , and . Both contain too. ended at and must not participate merely because it belongs to . belongs to another collinear group , which currently contains only .
The two panels show collinear separately. In both panels, refer to the same respective inputs; displaying them twice creates no extra identities. The diamond identifies the point input, and the dashed line locates ; neither is a new segment input.
The method for finding the full meeting block from Chapter 4 now applies first to groups. Use exact height at the current position to find the groups in the old order that pass through , combine them with the groups of nonzero inputs starting here, and add the point inputs here. Every old member of an active group covers the current horizontal coordinate; if the group line passes through , all those members contain . Ending members are still retained, new starters must participate too, and identities that have not started or have already ended must stay out.
However, we cannot copy Chapter 4's rule of "pair every participant with every other participant." That would report again as the point , both duplicating the pair and incorrectly replacing its complete interval. Only the following new results are added now:
| Pairing category | New unordered input pairs | Complete intersection |
|---|---|---|
| Between different nonzero groups | ; | Point for each pair |
| Point input with nonzero participants | ; ; | Point for each pair |
| Between old collinear members | None; was reported at | Its original complete interval stays unchanged |
Together with the three intervals already reported in Section 2, the five-input example has eight results. The other two pairs and have empty intersections because the horizontal coordinate of lies beyond the right endpoint of .
For any number of groups, take each pair of distinct groups once, and pair every current participating member of one group with every current participating member of the other. Taking each group pair once and storing each identity once within its group prevents duplicates at this event. Different groups have different supporting lines but already share the current point, so their complete intersection can only be that point; no longer interval is missed.
Point inputs follow Chapter 4's rules: pair each with every nonzero participant, and pair distinct point inputs at the same position once with each other. The point-with-point branch still runs even when no nonzero group is present. A pair containing a point input cannot have a second intersection point.
This separates nonempty results into three distinct categories: collinear nonzero pairs are reported at joining time; nonzero pairs from different groups at their unique intersection; and pairs containing point inputs at that point. Processing each position once, together with the within-group joining rule, prevents all three categories from repeating across events. Keeping an original overlap interval complete when a third line crosses it follows directly from this choice of reporting times.
Section 4: Why the current farthest right endpoint is enough
Member identities must be retained, but must we pair every member of two groups to discover a future intersection? First consider how far one nonempty group covers at the current horizontal coordinate .
Use the active members after the current event's updates: they have started and their right endpoints lie strictly to the right of . Call the chosen nonempty group . For each member , continue to write for the horizontal coordinates of its left and right endpoints. Then
Let be the maximum of these in group , the horizontal coordinate of its current farthest right endpoint. It is a number, not a new endpoint identity. The member set is finite and nonempty, so some member satisfies .
Every horizontal coordinate from through lies within : its left endpoint is no later than , and . This whole portion of the group's line is therefore continuously covered, with no internal gap. Conversely, if , it exceeds every current member's right endpoint, so no current member covers it.
Thus for strictly future , at least one current member covers it if and only if . This does not mean every member reaches that far. At reporting time we must still expand the actual members present then.
Now take a nonempty group neighboring , and write for its current farthest right endpoint's horizontal coordinate. Neighboring means that no other group lies between them in the active group order. Distinct parallel lines have no candidate intersection. Otherwise use Chapter 3's exact test to obtain the unique candidate , and schedule only when
all hold. The second and third conditions each guarantee that at least one current member of that group really contains ; checking only one group is insufficient. The scheduled point is therefore an intersection of two actual inputs, not a false position on extended lines. Equality with a group's farthest right endpoint is allowed because endpoints are closed; equality with the current horizontal coordinate is not strictly in the future.
This explains the division between "discovering a position" and "reporting all member pairs": discovery uses the fixed lines and current farthest right endpoints of two groups, while reporting expands members on arrival. A confirmed real future position remains on the existing pending list and is not canceled when neighbors change.
This reasoning requires every included member to cover already. A collinear input that has not started cannot increase the current farthest right endpoint, however far its right endpoint lies. Without shared coverage of , doing so could incorrectly fill a gap.
Section 5: Recheck extended coverage even when neighbors stay the same
Take a new three-input example, independent of all earlier examples:
| Input | Left endpoint | Right endpoint | Supporting line |
|---|---|---|---|
Here are input names; their group is , and the group containing is . Do not confuse input with a group name. The candidate intersection of the two fixed lines is .
At , starts and becomes a neighbor of . At this time contains only , whose farthest right endpoint is . The candidate's horizontal coordinate , so it cannot be scheduled.
At , starts and reports its complete intersection with , from to . After it joins, the farthest right endpoint of extends from to . The two groups remain the same neighbors, but now and also . We must therefore recheck and schedule now.
Read the two panels as "before extension, after extension." The second draws alone to make the extension clear; it does not mean that has already left at . The hollow circle marks only the candidate position on the fixed lines. Whether it has been scheduled depends on the coverage checks in the text.
Copying Chapter 4's conclusion that unchanged adjacencies need no recheck would miss here. In Chapter 4, each position in the order represented one input with fixed endpoints. Now it represents a group whose line is fixed but whose current coverage can grow. This is the new condition missing from the old conclusion.
In general, a group's coverage can extend rightward only when a new member joins. Whenever its farthest right endpoint increases, recheck it against its updated neighbors above and below. If its neighbors change too, also check the new adjacencies. If the joiner does not extend the farthest right endpoint and adjacency stays unchanged, neither the candidate lines nor the two groups' coverage limits gain any usable range. Thus no candidate previously excluded by range can newly pass for this reason.
A short member ending need not end the group
Continue this example. At , ends but remains, and the farthest right endpoint is still , so does not leave. At , the current participants are , and their point result is reported. is not reported because has already ended.
This example has only two results: has the complete interval from to , and has the point . At , ends. At , ends, and only then does become empty.
This is not limited to the numerical example. If a group member ends at but the group remains nonempty after the update, at least one other member has a right endpoint greater than . The member that just ended reaches only , so it cannot extend farther than that continuing member. Removing ending members therefore cannot shorten the farthest right endpoint of a group that remains nonempty. A group leaves only if all members have ended and no new member joins; then check the outer neighbors newly joined across its former position.
Section 6: An empty group cannot keep covering across a gap
Take another independent example:
| Input | Two endpoints |
|---|---|
| Point input | Both endpoints are |
lie on the same line , but have a gap between them. satisfies and intersects that line at . Neither of contains .
At , the horizontal group contains only , with farthest right endpoint , so the candidate at horizontal coordinate cannot be scheduled. At , ends, the group becomes empty, and it leaves the active order. Knowing that the collinear will start later does not allow us to extend coverage to in advance.
At , point input supplies its own endpoint information, so this position is still visited. Only are paired here, with intersection ; the horizontal group does not participate. At , starts and its group reenters the active order with as its only current member. Its supporting-line intersection with is already to the left and does not lie on ; reactivation cannot turn it into a new result. The only unordered input pair with a nonempty intersection in this example is ; the other five pairs have empty intersections.
The same holds for any gap. When a group has no members, no original input can justify coverage of that range, so the group must leave. When its first new member later starts, reinsert the group at that start event and check adjacency. The group record may remember "this is the same line," but cannot claim that an active input has continuously occupied it.
Section 7: Extend the reasons for ordering and event discovery to groups
One key question remains: are these rechecks enough to discover cross-group intersections without endpoint reminders? We cannot arbitrarily choose two "neighbors" among overlapping members: members of the same group share a line, so there is no unique line intersection to schedule. We must reason about groups instead and check when their coverage meets the required conditions.
A contiguous meeting block and the order on either side
Within an event-free gap, every nonempty group has members covering that gap, and its height is determined by its fixed line. If different groups have equal height, they actually intersect there; distinct parallel groups never have equal height. Thus Chapter 2's conclusion that order cannot change without an event applies between distinct groups. Member starts and ends are already endpoint events and cannot occur unnoticed inside the gap.
At an event point, the old groups passing through it still form a contiguous block. Take the lowest and highest participating groups. A group between them has an active member immediately to the left, and that member cannot end in the event-free gap. Even if it ends at the current point, its closed endpoint is still retained. The height-sandwich result cited in Chapter 4 then applies to these different group lines, forcing the middle group through the current point too. With zero or one old participating group, contiguity holds directly.
First find all these groups, then combine same-point starters and point inputs, and report according to the three categories above. After reporting, remove ending members and empty groups, retain continuing groups, and add newly activated groups. Point inputs do not participate in the right-side order.
Different groups passing through the current point must have different slopes. If their slopes agreed and they passed through the same point, their lines would coincide and they would belong to one group. We no longer use "overlap is forbidden" to exclude equal-slope inputs; we have already placed them in one group. We can therefore directly use Chapter 3's slope relationship on either side to arrange nonempty groups on the right in increasing slope order.
Chapter 4's reason the order outside the block stays correct still applies. Groups outside the block do not pass through the current point and are strictly higher or lower there. Different positions have distinct horizontal coordinates, so those groups do not start or end separately here either. Place the new group block between the same outer groups above and below; all other positions retain their order.
Two kinds of change must be checked after updating
The first is new adjacency. Chapter 4's classification into the new block's interior, upper and lower boundaries, and the connection across an empty block now applies to groups. Distinct groups inside the block have already intersected at the current point; their fixed lines cannot have a second intersection, so there is no strictly future internal candidate. Check new adjacencies at the boundaries and across an empty block using the two-group coverage conditions from Section 4.
The second is unchanged adjacency with extended coverage in a group. As Section 5 showed, its current neighbors must be rechecked. Outside the groups affected by endpoints or intersections, both members and adjacency remain unchanged, so no third kind of change requires rechecking. A group still nonempty after endings does not shorten its farthest right endpoint; adjacency changes caused by an empty group leaving already belong to the first kind.
Why an intersection without endpoint reminders is scheduled in time
Take an actual cross-group intersection with no input endpoint at it. For now, assume only that the events to its left have been processed correctly.
There are finitely many inputs and endpoints, and each pair of fixed lines from different groups has at most one intersection. Thus the event positions requiring stops are still finite, even though an overlap interval contains infinitely many points. We can therefore choose a gap immediately to the left of containing no other events. Every nonzero input containing has already started and has not yet ended there.
The groups containing these inputs form a contiguous block in the old order, with at least two distinct groups. Choose neighboring groups in this block and call them . The unique intersection of their two fixed lines is .
Look back along the finitely many events on the left to when this adjacency formed and then persisted up to the left side of . It was checked when it formed, but we cannot immediately assert that coverage already reached then. This may be exactly the case from Section 5 where the candidate was initially excluded by range.
There are therefore two cases:
- If both groups' current farthest right endpoints were at least when the adjacency formed, that check scheduled .
- If at least one group then had insufficient coverage, but immediately to the left of both have members containing , the insufficient coverage must have changed during this uninterrupted adjacency. A fixed member's right endpoint cannot move on its own; both groups remained nonempty, and removing ending members cannot extend coverage either. Thus a new member must have joined and extended a farthest right endpoint. Consider the joining event at which both groups' coverage first simultaneously reached . The recheck rule checks these still-neighboring groups and schedules .
Both checks occur strictly to the left of : the adjacency already exists on the left, and has no endpoint that could delay the needed start event until this position. The candidate is an actual intersection, strictly in the future and covered by both groups, so the scheduling conditions do not reject it. If already recorded, it remains recorded. Chapter 2's proof of retaining positions and taking them in order ensures that it will subsequently be visited.
Overlap within one group does not need this cross-group discovery proof. Each intersecting pair is reported at its later start event, with same-point starters handled by the internal event order, and all start endpoints are registered in advance. Results involving point inputs also have those points' own endpoint reminders. This covers how all three result categories above are reached.
Finally, reuse Chapter 4's earliest missed position argument. If there were an earliest missed position, it could not be an already registered endpoint. Events to its left would have been processed correctly under this chapter's group-update rules, so the cross-group discovery reasoning above would apply, proving that it was scheduled and would be visited. The contradiction is resolved by this chapter's added step: "also recheck when coverage becomes sufficient during a continuing adjacency." It does not assume in advance that the target intersection has already been processed.
This chapter thus connects reporting and discovery for overlaps separately. Collinear pairs generate their complete results only at joining time; cross-group events expand actual members. Group ordering avoids meaningless sorting within one line, the current farthest right endpoint supports candidate checks, and both coverage extension and gaps are handled by event rules. We neither turn every event into another enumeration of all old collinear member pairs nor expand every pair of members of two groups just to discover a position.
These are local mechanisms and their justifications under this chapter's conditions. The next article, Chapter 6, "Equal Horizontal Coordinates Do Not Mean a Shared Reordering", handles different positions with the same horizontal coordinate, and Chapter 7 introduces shear. The full mixed sweep, combined correctness argument, and total-work analysis remain for Chapters 8 through 10 respectively.