Skip to main content

Equal horizontal coordinates do not mean a simultaneous swap

On one vertical line, two segments intersect low down and two others intersect higher up. After processing the low intersection, should we also swap the high pair immediately?

This is Chapter 6 of the segment-intersection series. We remove Chapter 5's restriction that distinct event positions have distinct horizontal coordinates. Nonzero inputs must still be nonvertical, while multiple participants at one point, starts and ends, point inputs, and positive-length overlaps remain allowed. The title's prohibition applies to the point-by-point mechanism used here: process one exact position at a time without prematurely changing other positions' states. It does not rule out separately defined and proved algorithms that process a whole column as a batch.

Section 1: Left first, then bottom to top within a column​

Reuse Chapter 3's requirement that both coordinates must respectively agree for points to be identical. Equal horizontal coordinates mean only the same column. Different vertical coordinates still describe different positions.

Remove events from the list in this order: compare horizontal coordinates first, smaller first; if equal, compare vertical coordinates, lower first. If both coordinates agree, merge them into one event and process it using Chapter 4's rule for collecting every same-point participant.

Take these four closed segments. Their identifiers stay fixed as their vertical order changes, and each color always denotes the same input.

InputLeft endpointRight endpointSupporting lineClosed range
S0\teachBlue{S_0}(−1,−3)(-1,-3)(3,1)(3,1)y=x−2y=x-2−1≤x≤3-1\le x\le3
S1\teachOrange{S_1}(−1,−1)(-1,-1)(3,−5)(3,-5)y=−x−2y=-x-2−1≤x≤3-1\le x\le3
S2\teachViolet{S_2}(−1,1)(-1,1)(3,5)(3,5)y=x+2y=x+2−1≤x≤3-1\le x\le3
S3\teachEmerald{S_3}(−1,3)(-1,3)(3,−1)(3,-1)y=−x+2y=-x+2−1≤x≤3-1\le x\le3
Four inputs and three real intersections: low P=(0,-2), high Q=(0,2), and R=(2,0) to the right.Four inputs and three real intersections: low P=(0,-2), high Q=(0,2), and R=(2,0) to the right.

The figures are teaching diagrams, not screenshots of algorithm execution. Each retains its original 320 × 260 size; if necessary they wrap onto new rows. Read them in increasing figure-number order. Geometric plots use equal horizontal and vertical units, with OO as the origin. Stage diagrams show only short portions near the meeting points. The adjacent vertical list shows the maintained order; it does not mean the segments have moved to new coordinates.

The four left endpoints also share horizontal coordinate −1-1, but are not a single event. They start at heights −3,−1,1,3-3,-1,1,3 in turn, so inputs join one by one. They do not touch each other at these endpoints. After all four starts, the bottom-to-top order is S0,S1,S2,S3S_0,S_1,S_2,S_3.

First check all six unordered input pairs using Chapter 3's line intersection and closed-range checks, without deriving the formulas again:

Input pairLine relationship or candidateComplete segment intersection
S0,S1S_0,S_1P=(0,−2)P=(0,-2): substituting x=0x=0 into both equations gives −2-20∈[−1,3]0\in[-1,3]; intersection is PP
S2,S3S_2,S_3Q=(0,2)Q=(0,2): substituting x=0x=0 into both equations gives 220∈[−1,3]0\in[-1,3]; intersection is QQ
S0,S3S_0,S_3R=(2,0)R=(2,0): 2−2=02-2=0, −2+2=0-2+2=02∈[−1,3]2\in[-1,3]; intersection is RR
S1,S2S_1,S_2(−2,0)(-2,0): −(−2)−2=0-(-2)-2=0, −2+2=0-2+2=0−2<−1-2<-1; only the extended lines intersect
S0,S2S_0,S_2Both slopes are 11, with different constant termsDistinct parallel lines; no intersection
S1,S3S_1,S_3Both slopes are −1-1, with different constant termsDistinct parallel lines; no intersection

Two nonparallel lines have at most one intersection, so each candidate confirmed by substitution is the unique candidate. The endpoints also satisfy their listed equations: substitution at the left gives −1−2=−3-1-2=-3, 1−2=−11-2=-1, −1+2=1-1+2=1, 1+2=31+2=3 respectively; at the right it gives 3−2=13-2=1, −3−2=−5-3-2=-5, 3+2=53+2=5, −3+2=−1-3+2=-1.

Thus there is no intersection or endpoint strictly between x=−1x=-1 and x=0x=0. By Chapter 2's no-event, no-order-change result, the order persists immediately to the left of x=0x=0. This establishes the entry state for the local process below; it is not an arrangement guessed from the picture. Adjacencies formed at the starts have already discovered and registered P,QP,Q, while the S1,S2S_1,S_2 candidate was excluded by the closed ranges. Other members still separate S0,S3S_0,S_3, so adjacency has not yet discovered RR.

Section 2: After the low event, the high event still waits​

Take PP before QQ: their horizontal coordinates agree and −2<2-2<2. At PP, collect only participants at height −2-2, namely S0,S1S_0,S_1. The higher pair S2,S3S_2,S_3 is at height 22, not at this point.

First report the complete intersection PP for pair S0,S1S_0,S_1. Both pass strictly through the point and continue afterward. Reuse Chapter 3's slope relation on the two sides of a meeting point: on the right, order by increasing slope. S1S_1 has slope −1-1 and S0S_0 slope 11, so the current block becomes S1,S0S_1,S_0 from bottom to top.

Figure 1: Before P. Both low and high positions show local left-side branches; the bottom-to-top order is S0, S1, S2, S3.Figure 1: Before P. Both low and high positions show local left-side branches; the bottom-to-top order is S0, S1, S2, S3.
Figure 2: After P but before Q. The low position shows right-side branches, while the high position still shows left-side branches. Order: S1, S0, S2, S3.Figure 2: After P but before Q. The low position shows right-side branches, while the high position still shows left-side branches. Order: S1, S0, S2, S3.
Figure 3: After Q. Both positions show right-side branches. Order: S1, S0, S3, S2; S0 and S3 are new neighbors.Figure 3: After Q. Both positions show right-side branches. Order: S1, S0, S3, S2; S0 and S3 are new neighbors.

Figure 2 is crucial: the low position has its post-event state, while the high position retains its pre-event state. Both are at x=0x=0, but their processing progress differs. The maintained order is now

S1,S0,S2,S3(bottom to top).S_1,\quad S_0,\quad S_2,\quad S_3\qquad\text{(bottom to top)}.

This is not the order seen after moving an entire vertical sweep line to the right of x=0x=0. Moving the whole column right would also turn the high pair into S3,S2S_3,S_2. But we have not yet removed QQ from the list, so that update cannot be treated as completed.

The new boundary neighbors are S0,S2S_0,S_2, which are parallel, so no new intersection is registered. The adjacency of S2,S3S_2,S_3 and the scheduled event QQ remain. Next remove QQ, collect S2,S3S_2,S_3, report QQ for that pair, then order them by increasing slope as S3,S2S_3,S_2. The complete order in Figure 3 becomes

S1,S0,S3,S2.S_1,\quad S_0,\quad S_3,\quad S_2.

Only the current block changes each time. Swapping the high pair prematurely at PP would leave its stored order different from its pre-event order before QQ is reached. Applying the next point-by-point update would then lack its required premise. This identifies a mismatch between state and processing progress; it does not claim that every batch-processing approach misses intersections.

Section 3: New neighbors discover the intersection to the right​

After QQ, the new neighbors at the lower boundary are S0,S3S_0,S_3. Section 1 confirmed their real intersection R=(2,0)R=(2,0) lies in both closed ranges. It is to the right of current horizontal coordinate 00, so register RR now, but do not yet report this pair.

Discovery confirms a real intersection. Registration keeps that position on the pending list. Reporting produces an intersection result after reaching the position and collecting its participants. Rediscovering a listed position does not add another copy; intersections inside the current meeting block are not scheduled again either.

Next reach RR, whose participants are S0,S3S_0,S_3, and report their pair. On the right, the smaller-slope S3S_3 is below S0S_0, giving

S1,S3,S0,S2.S_1,\quad S_3,\quad S_0,\quad S_2.
Figure 4: After reporting at R, S3 is below S0; the outside inputs S1 and S2 are unchanged. The figure shows local segments to the right of x=2 and the complete order.Figure 4: After reporting at R, S3 is below S0; the outside inputs S1 and S2 are unchanged. The figure shows local segments to the right of x=2 and the complete order.

The new outer adjacencies S1,S3S_1,S_3 and S0,S2S_0,S_2 are both parallel pairs, so there are no new intersections. At x=3x=3, process the four right endpoints individually too: their heights are −5,−1,1,5-5,-1,1,5, so S1,S3,S0,S2S_1,S_3,S_0,S_2 leave in that order, leaving an empty order. Exactly the three nonempty input pairs from Section 1 have been reported, once each.

Although QQ was registered earlier, it must still count as future after PP is processed. Requiring only a strictly greater candidate horizontal coordinate would wrongly exclude it. In general, write the current position as E=(t,h)E=(t,h) and a candidate as F=(u,v)F=(u,v). These four lowercase letters are the points' horizontal and vertical coordinates; E,FE,F do not replace P,Q,RP,Q,R in the example. The strict-future condition is

u>tor(u=t and v>h).u>t\quad\text{or}\quad (u=t\ \text{and}\ v>h).

Equal values for both coordinates mean the current position, which is not scheduled again. A smaller horizontal coordinate, or the same column at a lower height, means a position already passed and is not scheduled either. After PP, QQ satisfies the second future condition and RR the first. The next section supplies general reasons: a four-segment example cannot replace an argument for all allowed inputs.

Section 4: Why intermediate states still support height-based search​

Continue to denote the current event by E=(t,h)E=(t,h), where tt is horizontal coordinate and hh is height. First specify the maintained state. For the column x=tx=t, not every position steps right simultaneously. Instead:

Position within this columnBefore processing EEAfter processing EE
Already processed positions strictly below hhInsertions, removals, and local right-side ordering are completeRetain them
Current position at exactly height hhOld members have arrived; starters await mergingAfter reporting, retain only rightward continuers and order the new block
Unprocessed positions strictly above hhRetain left-side members and local left-side orderContinue retaining them until their own event

Heights without events require no update. Here “right-side ordering” determines only the internal order of one equal-height block; it does not give the entire column one shared horizontal coordinate slightly to the right. For overlaps, reuse Chapter 5's collinear groups: each order position below represents a nonempty group. Without overlaps, each group has one input, as in the main example.

Why heights are nondecreasing on arrival at a column​

Assume only that earlier events have been handled correctly, not that intersections in this column have already been reached. There are finitely many endpoints, and each pair of fixed lines from different groups has at most one intersection, so real event positions are finite. Choose a short event-free horizontal interval strictly to the left of tt. Other events in this column lie at boundary x=tx=t, not inside this open interval. If this is the leftmost column, the old order is empty and the claim holds directly.

An input active in this interval still contains its corresponding point at x=tx=t: it cannot end inside the interval, and even if it ends exactly at the boundary, its closed endpoint is included. Thus Chapter 2's boundary height-difference and between-neighbors result still applies. A group lower in the old order cannot suddenly be strictly above a formerly higher group at tt. Otherwise, members of the two groups covering this interval would have intersected inside it, contradicting the absence of events. Equality at the boundary and endings at the boundary are allowed here; we are not retaining Chapter 2's exclusion of endpoints with equal horizontal coordinates.

Evaluating all old groups' heights at tt therefore gives a nondecreasing bottom-to-top sequence. Distinct equal-height groups meet at one point; before updating, they remain in their existing left-side slope order.

Why processing a low position preserves this property​

Suppose the entire height sequence is nondecreasing before a particular height is processed. All old participating groups at that height must be consecutive. Take their lowest and highest groups: heights between them can be neither below the lower one nor above the upper one. Both ends equal the current height, so every intermediate height must equal it too. With zero or one group, the block is simply empty or a single position.

After reporting, every removed member ends at this height; every newly inserted or reordered group also lies at this height. Deleting a run of equal numbers, or replacing it with several copies of the same number at that position, cannot put a lower height above a higher one. Removing an empty group just deletes a position. Heights therefore remain nondecreasing after the update.

Apply this step successively from the lowest event in the column. Every processed lower position preserves the property. When EE is reached, we can still locate exactly the first group whose height is at least hh, then collect the entire consecutive run with height hh. If that first group is already higher, or no group has height at least hh, the old block is empty and we obtain an insertion gap. Reordering within lower positions does not prevent locating higher positions by exact heights in the current column.

Section 5: Why only the current block is updated​

First consider membership. A nonvertical line has only one height at x=tx=t, so one nonzero input cannot pass through both a low event and a different high event in the same column. Its endpoints in this column can likewise lie only at its own height.

An input just inserted low down cannot be a same-point participant higher up; an input just removed low down cannot be needed as a participant higher up either. A high ending input must wait to be reported at its own endpoint before leaving; a high starting input must wait for its own endpoint before joining. Premature whole-column insertions or removals would violate this membership meaning.

At current height hh, the old block collects ending and through members arriving from the left, then merges starters and point inputs from the endpoint list. A nonzero input containing EE has its left endpoint either strictly left of tt or exactly at EE: if the left endpoint also has x=tx=t, its line has only one height there, so it cannot lie elsewhere in the column. The former input has not been removed at a lower height and belongs to the old block; the latter comes from the endpoint list. Thus Chapter 4's two collection routes still find everyone, without prematurely including inputs that have not started.

Closed endpoints participate in reporting before ending identities are removed. A point input participates only at its own exact position and leaves no slope or order position behind. In particular, even if it shares a horizontal coordinate with a later event, a different height means a different point; it cannot remain to be paired again higher up. Further deduplication and pairing of same-point identities follow Chapter 4. Section 7 reconnects the classified reporting for overlaps.

Which side orders the block, and what stays outside it​

For distinct groups through EE that continue rightward, reuse Chapter 3's two-sided slope relation and order the new block by increasing slope. This requires only that the groups exist on that side. Distinct groups sharing both a point and a slope would be on one line and should already form one group, so there is no slope tie between groups. Within a group, retain original member identities without inventing a vertical order.

Outside heights are strictly below or above hh, so the current group block still belongs between those strict heights. We cannot copy Chapter 4's reason that outside groups have no endpoint or crossing at this horizontal coordinate: now they may, just at other heights. The correct reasons are separate:

  • Positions at different heights are ordered by height first. Changing slope order within the current block does not affect that comparison.
  • Equal-height groups at a lower position have already been processed; retain their right-side order and updated members.
  • Equal-height groups at a higher position have not been processed; retain their left-side order and pre-event members. They are not part of the current event, so it has no reason to insert, remove, or reorder them.

Thus the relative order and membership outside the current block retain their own processing progress. Their boundary adjacency with the current block may change, and that is what must be checked next. Unchanged relative order outside the block does not mean unchanged boundary neighbors. If the old block is empty, insert in the height gap. If the new block is empty, connect the surviving sides. If both are empty, leave the order unchanged while still completing point-input reporting.

Only after every event in the column is processed have all meeting heights adopted right-side order, all ending inputs left, and all starters joined. We can then interpret the whole column as the active order immediately right of tt. Distinct heights have strict height differences, and finitely many fixed lines intersect at finitely many positions. Hence a sufficiently close event-free interval on the right preserves those strict comparisons, while right-side slope relations order each equal-height block. With no events, Chapter 2's result continues to apply until the next column. This proves an interval exists; it does not ask a program to guess a decimal offset.

Section 6: Connect the complete future order to event discovery​

Section 3's future condition must agree with the list's removal order. For current position E=(t,h)E=(t,h) and a candidate F=(u,v)F=(u,v) already confirmed real, check each case:

Position relationshipStrictly future?List action
u>tu>tYes, regardless of vvAdd if unregistered; otherwise retain
u=t, v>hu=t,\ v>hYes, higher in this columnSame action; horizontal-coordinate equality must not exclude it
u=t, v=hu=t,\ v=hNo: this is the current positionDo not schedule again
u<tu<t, or u=t, v<hu=t,\ v<hNo: an already processed positionDo not add

Testing only a strict horizontal-coordinate inequality misses the second row. Changing it to “greater than or equal” wrongly accepts same-column positions in the third and fourth rows. Compare complete positions. Processing a point only once deduplicates exact coordinates; it does not merge results for distinct input pairs.

The classification of new adjacencies remains complete​

Section 5 proved that we replace just one consecutive block and preserve outside order. Chapter 4's classification of new adjacencies therefore applies directly to groups: if the new block is nonempty, check its upper and lower boundaries. Distinct groups inside it already meet at the current point and cannot have another line intersection. If the new block is empty, check the two outside groups newly connected across it. A missing side means no such pair. When both blocks are empty and coverage has not changed, no new reason for a check arises.

The new connection is that every check uses the complete future condition above, rather than the horizontal-only test valid under the previous chapter's restriction. Chapter 5's groups also require a coverage check: a line intersection is not automatically a real segment intersection. Section 7 checks these two requirements separately.

Can updates lower in the column prevent discovering a high event?​

Choose a real cross-group intersection with no input endpoint, denoted F∗=(u∗,v∗)F_*=(u_*,v_*). The star distinguishes this arbitrary target and is not multiplication. Assume only that events earlier in the complete position order have been correctly processed.

Take an event-free interval strictly left of x=u∗x=u_*. Every input containing F∗F_* has already started and has not ended there, since the target contains no endpoints. By Chapter 5's consecutive meeting-block and coverage-discovery result, the target's participating groups form a consecutive block of at least two groups on the left.

We may now process lower events in the same column first. Can those updates split the target block? No. Every participating group has height v∗v_* at u∗u_*. Its nonvertical line has only that height in this column and participates in no lower event. Groups inserted or reordered lower down have strictly lower heights and cannot enter this equal-height block. Its internal adjacencies therefore persist until the target is processed.

Choose adjacent groups within this block. Look back through the finite earlier events to the formation of this uninterrupted adjacency. The previous chapter gives two cases: if both groups already covered the target when adjacency formed, they were checked then; otherwise, during that continuous adjacency, some member insertion first made both coverages sufficient, and the coverage-extension check handled it. We need not rederive that result, only verify the new conditions: members containing the target start left of u∗u_*, and lower events in this column do not change the target groups' membership or internal adjacency. The necessary formation or coverage extension therefore cannot be delayed until after the target.

The resulting candidate is real and strictly follows the event of the check in the complete order. It is therefore either added to the list or retained if already listed. A registered real event is not canceled merely because its groups temporarily cease to be neighbors. Endpoints and cross-group intersections are finite, and the same position is not repeatedly added. Replace the order in Chapter 2's retention and ordered-removal argument with horizontal-first, then vertical order. Only finitely many positions precede the target, so removing them eventually reaches it.

This argument did not assume that the target had already arrived. If an earliest real position were never reached, it could not be a preregistered endpoint. Its earlier events would have been processed, so Sections 4 and 5 would preserve the required state, and the discovery argument would force arrival, a contradiction. These are the extra connections needed after removing the distinct-horizontal-coordinate restriction. General correctness of the complete mixed-input sweep remains for later chapters.

Section 7: Reconnect collinear-group coverage and reporting​

Each group in the main example has one input. In general, retain Chapter 5's original member identities and reporting times. One nonvertical line has only one point in a column: this connects those rules to point-by-point processing progress.

First, same-group members starting at the same horizontal coordinate must start at the same position. They still join one at a time by identity within one event. The later start event of an intersecting collinear pair remains that same event; it is not split into two heights in a column. Thus the proof of reporting the complete intersection on insertion and the complete interval remain valid. Ending members leave only after closed-endpoint pairing.

Second, when a cross-group event arrives, every old member of a group through the current position covers the current horizontal coordinate and thus contains the current point. Merge starters at this position too. Report using Chapter 5's cross-group expansion and point-input pairing, without re-enumerating old collinear member pairs. Members at other heights do not join merely because they share the column. Results remain attached to original unordered input pairs; overlap intervals are neither split nor converted into points.

How equality works in intermediate-state coverage​

We must adjust the conditions under which Chapter 5's coverage proof is used. It stated that, after an event, every active member's right endpoint is strictly beyond the current horizontal coordinate. Now, ending members higher in this column have not yet left, so their right endpoint may equal tt. We cannot remove them prematurely just to preserve the old wording.

For any nonempty group GaG_a in an intermediate state, let ℓi,ri\ell_i,r_i denote the horizontal coordinates of the left and right endpoints of its current member SiS_i. Every member already in the set satisfies

ℓi≤t≤ri.\ell_i\le t\le r_i.

Equality at the left endpoint can come only from a start position already processed in this column; unprocessed starters are not in the set. Equality at the right endpoint comes from an end position still awaiting processing in this column. The endpoint is included, so it still provides valid current coverage.

Continue to write RGaR_{G_a} for the maximum of these rir_i. Chapter 5's proof that the maximum right endpoint provides continuous coverage requires only that every member cover tt: the member attaining the maximum covers the closed range from tt to RGaR_{G_a}. We now allow candidate horizontal coordinate u=tu=t too. Thus, for u≥tu\ge t, some member covers that coordinate if and only if u≤RGau\le R_{G_a}. This also holds when RGa=tR_{G_a}=t: it covers only the boundary position, not a positive length to the right.

For another adjacent nonempty group GbG_b, with farthest right endpoint RGbR_{G_b}, first find candidate F=(u,v)F=(u,v) from their two fixed lines. Distinct parallel lines have no candidate. When one exists, require both kinds of condition:

The complete position is strictly in the future:

u>tor(u=t and v>h).u>t\quad\text{or}\quad (u=t\ \text{and}\ v>h).

Both groups actually cover it:

u≤RGa,u≤RGb.u\le R_{G_a},\qquad u\le R_{G_b}.

If u=t,v>hu=t,v>h, both candidate lines have height vv in this column. They belong to an unprocessed high position, not the low position just updated. Their old members remain, and the closed-range check can accept members ending at that high position. Such an event may already be registered or supplied by an endpoint. Being allowed by the future test does not mean it must have just been discovered at the low event. Conversely, passing coverage cannot turn the current position back into a future event. These two checks have different responsibilities and both are necessary.

Coverage extension and empty groups are still handled at their own positions​

A new member joins only at its own start position. If the farthest right endpoint extends, use Chapter 5's coverage-extension check on that group's updated neighbors, with the complete future condition. Unchanged adjacency with newly sufficient coverage may discover a real intersection for the first time, so this check cannot be omitted.

An ending member is removed only at its own end position. If the group remains nonempty, its retained members continue rightward from the same group point in this column, with right endpoints strictly greater than tt. An ending member with right endpoint tt therefore cannot provide a farther maximum; removing it does not shorten the still-nonempty group's farthest right endpoint. If no continuing member or same-point starter remains, the empty group exits and its newly connected neighbors are checked. A collinear member starting in the future cannot fill the gap early. This reuses Chapter 5's empty-group exit and reactivation, specifying execution at each exact position.

An update low down thus affects only its current block, boundary adjacency, and coverage that actually extends. Higher positions remain until their own events. Collinear pairs and pairs containing point inputs still arrive through registered endpoints; cross-group positions arrive by the preceding section's adjacency and coverage arguments. Actual identities are expanded when reporting.

We have moved from the four-segment example to a general point-by-point state: bottom to top within a column, local updates of the current block, complete-position future comparison, and separate coverage verification. For the full overlapping-member example, return to Chapter 5, How overlapping segments participate in the sweep. Next, Chapter 7, Handling vertical segments with a shear, incorporates vertical inputs and shearing. Enter the related mathematics through Choosing and proving the shear coefficient. Chapters 8–10 cover the complete mixed-input sweep, general correctness, and total work respectively.