I wrote the following method in python that finds the intersection of 2 segments on a plane (assuming the segments are parallel to either the x or y axis)
segment_endpoints = []
def intersection(s1, s2):
segment_endpoints = [] left = max(min(s1[0], s1[2]), min(s2[0], s2[2])) right = min(max(s1[0], s1[2]), max(s2[0], s2[2])) top = max(min(s1[1], s1[3]), min(s2[1], s2[3])) bottom = min(max(s1[1], s1[3]), max(s2[1], s2[3])) if top > bottom or left > right: segment_endpoints = [] return 'NO INTERSECTION' elif top == bottom and left == right: segment_endpoints.append(left) segment_endpoints.append(top) return 'POINT INTERSECTION' else: segment_endpoints.append(left) segment_endpoints.append(bottom) segment_endpoints.append(right) segment_endpoints.append(top) return 'SEGMENT INTERSECTION'
Can this be considered in good functional form? If not what would be the proper functional way of rewriting it?