Created
June 26, 2019 11:38
-
-
Save kayibal/8b488c41fd6ece1344cf55d8f650f600 to your computer and use it in GitHub Desktop.
Computes overlap between two ranges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def compute_overlap(x1, x2, y1, y2): | |
if x2 >= y1 and y2 >= x1: | |
if x1 < y1 < x2 and x2 < y2: | |
return x2 - y1 | |
elif y1 < x1 < y2 and y2 < x2: | |
return y2 - x1 | |
elif x1 < y1 and y2 < x2: | |
return y2 - y1 | |
elif y1 < x1 and x2 < y2: | |
return x2 - x1 | |
else: | |
return np.nan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment