ideasman42 / isect_segments-bentley_ottmann

BentleyOttmann sweep-line implementation (for finding all intersections in a set of line segments)
MIT License
91 stars 40 forks source link

flyback lines (USE_IGNORE_SEGMENT_ENDINGS=True) -> AssertionError #13

Closed smichr closed 3 years ago

smichr commented 6 years ago

The repeated segment ((0, 0), (0, 1)) in this polygon don't raise an error

>>> G = [(0,0),(2,0),(2,4),(-2,4),(-2,0),(0,0),(0,1),(-1,2),(1,2),(0,1)]
>>> isect_polygon(G)
[]

But an error occurs in this case

>>> Z = [(-1,0),(0,0),(1,1),(0,0)]
>>> isect_polygon(Z)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "isect.py", line 599, in isect_polygon
    return isect_polygon_impl(segments, include_segments=False)
  File "isect.py", line 591, in isect_polygon_impl
    return isect_segments_impl(segments, include_segments=include_segments)
  File "isect.py", line 578, in isect_segments_impl
    sweep_line.handle(p, events_current)
  File "isect.py", line 386, in handle
    self.handle_event(e)
  File "isect.py", line 393, in handle_event
    self.insert(event)
  File "isect.py", line 323, in insert
    assert(event not in self._events_current_sweep)
AssertionError

Removal of duplicate segments after canonicalization (either in isect_segments_impl or in the __init__ of the EventQueue) solves the latter problem.

ideasman42 commented 6 years ago

@smichr it's likely that duplicate segments aren't supported and need to be checked for - before the operation runs.

Fix could be just to document this limitation.

ideasman42 commented 3 years ago

Solved #24