diff options
Diffstat (limited to 'src/silx/gui/plot/utils/intersections.py')
-rw-r--r-- | src/silx/gui/plot/utils/intersections.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/silx/gui/plot/utils/intersections.py b/src/silx/gui/plot/utils/intersections.py index 4f6ed23..faf6641 100644 --- a/src/silx/gui/plot/utils/intersections.py +++ b/src/silx/gui/plot/utils/intersections.py @@ -24,7 +24,9 @@ """This module contains utils class for axes management. """ -__authors__ = ["H. Payno", ] +__authors__ = [ + "H. Payno", +] __license__ = "MIT" __date__ = "18/05/2020" @@ -59,11 +61,11 @@ def lines_intersection(line1_pt1, line1_pt2, line2_pt1, line2_pt2): return None return ( (num / denom.astype(float)) * dir_line2[0] + line2_pt1[0], - (num / denom.astype(float)) * dir_line2[1] + line2_pt1[1]) + (num / denom.astype(float)) * dir_line2[1] + line2_pt1[1], + ) -def segments_intersection(seg1_start_pt, seg1_end_pt, seg2_start_pt, - seg2_end_pt): +def segments_intersection(seg1_start_pt, seg1_end_pt, seg2_start_pt, seg2_end_pt): """ Compute intersection between two segments @@ -74,10 +76,12 @@ def segments_intersection(seg1_start_pt, seg1_end_pt, seg2_start_pt, :return: numpy.array if an intersection exists, else None :rtype: Union[None,numpy.array] """ - intersection = lines_intersection(line1_pt1=seg1_start_pt, - line1_pt2=seg1_end_pt, - line2_pt1=seg2_start_pt, - line2_pt2=seg2_end_pt) + intersection = lines_intersection( + line1_pt1=seg1_start_pt, + line1_pt2=seg1_end_pt, + line2_pt1=seg2_start_pt, + line2_pt2=seg2_end_pt, + ) if intersection is not None: max_x_seg1 = max(seg1_start_pt[0], seg1_end_pt[0]) max_x_seg2 = max(seg2_start_pt[0], seg2_end_pt[0]) @@ -93,8 +97,10 @@ def segments_intersection(seg1_start_pt, seg1_end_pt, seg2_start_pt, max_tmp_x = min(max_x_seg1, max_x_seg2) min_tmp_y = max(min_y_seg1, min_y_seg2) max_tmp_y = min(max_y_seg1, max_y_seg2) - if (min_tmp_x <= intersection[0] <= max_tmp_x and - min_tmp_y <= intersection[1] <= max_tmp_y): + if ( + min_tmp_x <= intersection[0] <= max_tmp_x + and min_tmp_y <= intersection[1] <= max_tmp_y + ): return intersection else: return None |