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 4, 2021
1 parent b8e3e0f commit 255a74c
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions bentley_ottmann/planar.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,7 @@ def segments_intersections(segments: _Sequence[_Segment]
.update(ids))
(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
discrete = {} # type: _Dict[_Tuple[int, int], _Tuple[_Point]]
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 @@ -241,10 +232,7 @@ def segments_intersections(segments: _Sequence[_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,))))
discrete.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 = (
left_parts_ids.get(intersection_point),
Expand All @@ -259,8 +247,15 @@ def segments_intersections(segments: _Sequence[_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,))))
return result
discrete.update(zip(ids_pairs, _repeat((intersection_point,))))
continuous = {} # type: _Dict[_Tuple[int, int], _Tuple[_Point, _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 continuous:
prev_start, prev_end = continuous[ids_pair]
endpoints = min(prev_start, start), max(prev_end, end)
else:
endpoints = (start, end)
continuous[ids_pair] = endpoints
return {**discrete, **continuous}

0 comments on commit 255a74c

Please sign in to comment.