Skip to content

Commit

Permalink
Complete 'sweep' function
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Jun 1, 2020
1 parent ed97f3f commit 07454e6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion bentley_ottmann/core/planar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import (Iterable,
List,
Optional,
Sequence,
Tuple)
Expand Down Expand Up @@ -31,9 +32,14 @@ def sweep(segments: Sequence[Segment],
segments = [to_rational_segment(segment) for segment in segments]
events_queue = to_events_queue(segments)
sweep_line = SweepLine()
prev_start = None
prev_same_start_events = [] # type: List[Event]
while events_queue:
event = events_queue.pop()
start, same_start_events = event.start, [event]
start = event.start
same_start_events = (prev_same_start_events + [event]
if start == prev_start
else [event])
while events_queue and events_queue.peek().start == start:
same_start_events.append(events_queue.pop())
for event, other_event in to_pairs_combinations(same_start_events):
Expand Down Expand Up @@ -63,6 +69,7 @@ def sweep(segments: Sequence[Segment],
yield from detect_intersection(
below_event, above_event,
events_queue=events_queue)
prev_start, prev_same_start_events = start, same_start_events


def to_events_queue(segments: Sequence[Segment]) -> EventsQueue:
Expand Down

0 comments on commit 07454e6

Please sign in to comment.