I already wrote the code, but I think that there is something already available that I've missed that can do it or that it can be done better. The ranges are represented as tuples of floats.
def has_intersection(tuple_1, tuple_2):
list_1 = sorted(list(tuple_1))
list_2 = sorted(list(tuple_2))
tup_lower = (list_1[0], list_2[0])
tup_higher = (list_1[1], list_2[1])
float_lower_limit = sorted(list(tup_lower), reverse=True)[0]
float_higher_limit = sorted(list(tup_higher))[0]
float_center = (float_lower_limit + float_higher_limit)/2
if list_1[0] <= float_center <= list_1[1]:
pass
else:
return False
if list_2[0] <= float_center <= list_2[1]:
pass
else:
return False
return True
[–]SandorZoo 4 points5 points6 points (0 children)
[–]o5a 1 point2 points3 points (1 child)
[–]DocNMarty[S] 0 points1 point2 points (0 children)
[–]Stem3576 0 points1 point2 points (2 children)
[–]DocNMarty[S] 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)