Skip to content

Commit

Permalink
Complete 'segments_intersections' function
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Apr 2, 2021
1 parent abb63ac commit 478a467
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions bentley_ottmann/planar.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ def segments_intersections(segments: _Sequence[_hints.Segment]
(right_parts_ids.setdefault(end, {}).setdefault(start, set())
.update(ids))
result = {}
for start, ends_ids in left_parts_ids.items():
for end, ids in ends_ids.items():
for ids_pair in _to_pairs_combinations(sorted(ids)):
if ids_pair in result:
prev_start, prev_end = result[ids_pair]
endpoints = min(prev_start, start), max(prev_end, end)
else:
endpoints = (start, end)
result[ids_pair] = endpoints
for intersection_point, ends_tangents_ends in left_tangents.items():
left_intersection_point_ids, right_intersection_point_ids = (
left_parts_ids.get(intersection_point),
Expand All @@ -230,6 +239,9 @@ def segments_intersections(segments: _Sequence[_hints.Segment]
_to_sorted_pair(id_, tangent_id)
for id_, tangent_id in _product(ids - tangent_ids,
tangent_ids - ids)]
ids_pairs = [ids_pair
for ids_pair in ids_pairs
if ids_pair not in result]
result.update(zip(ids_pairs, _repeat((intersection_point,))))
for intersection_point, starts_tangents_ends in right_tangents.items():
left_intersection_point_ids, right_intersection_point_ids = (
Expand All @@ -245,14 +257,8 @@ def segments_intersections(segments: _Sequence[_hints.Segment]
_to_sorted_pair(id_, tangent_id)
for id_, tangent_id in _product(ids - tangent_ids,
tangent_ids - ids)]
ids_pairs = [ids_pair
for ids_pair in ids_pairs
if ids_pair not in result]
result.update(zip(ids_pairs, _repeat((intersection_point,))))
for start, ends_ids in left_parts_ids.items():
for end, ids in ends_ids.items():
for ids_pair in _to_pairs_combinations(sorted(ids)):
if ids_pair in result:
prev_start, prev_end = result[ids_pair]
endpoints = min(prev_start, start), max(prev_end, end)
else:
endpoints = (start, end)
result[ids_pair] = endpoints
return result

0 comments on commit 478a467

Please sign in to comment.