| Total Complexity | 10 | 
| Total Lines | 62 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | """  | 
            ||
| 10 | class Allen:  | 
            ||
| 11 | """  | 
            ||
| 12 | Utility class for Allen's interval algebra, https://en.wikipedia.org/wiki/Allen%27s_interval_algebra.  | 
            ||
| 13 | """  | 
            ||
| 14 | # ------------------------------------------------------------------------------------------------------------------  | 
            ||
| 15 | X_BEFORE_Y = 1  | 
            ||
| 16 | X_MEETS_Y = 2  | 
            ||
| 17 | X_OVERLAPS_WITH_Y = 3  | 
            ||
| 18 | X_STARTS_Y = 4  | 
            ||
| 19 | X_DURING_Y = 5  | 
            ||
| 20 | X_FINISHES_Y = 6  | 
            ||
| 21 | X_EQUAL_Y = 0  | 
            ||
| 22 | X_BEFORE_Y_INVERSE = -1  | 
            ||
| 23 | X_MEETS_Y_INVERSE = -2  | 
            ||
| 24 | X_OVERLAPS_WITH_Y_INVERSE = -3  | 
            ||
| 25 | X_STARTS_Y_INVERSE = -4  | 
            ||
| 26 | X_DURING_Y_INVERSE = -5  | 
            ||
| 27 | X_FINISHES_Y_INVERSE = -6  | 
            ||
| 28 | |||
| 29 | # ------------------------------------------------------------------------------------------------------------------  | 
            ||
| 30 | @staticmethod  | 
            ||
| 31 | def relation(x_start, x_end, y_start, y_end):  | 
            ||
| 32 | """  | 
            ||
| 33 | Returns the relation between two intervals.  | 
            ||
| 34 | |||
| 35 | :param int x_start: The start point of the first interval.  | 
            ||
| 36 | :param int x_end: The end point of the first interval.  | 
            ||
| 37 | :param int y_start: The start point of the second interval.  | 
            ||
| 38 | :param int y_end: The end point of the second interval.  | 
            ||
| 39 | |||
| 40 | :rtype: int  | 
            ||
| 41 | """  | 
            ||
| 42 | diff_start = y_start - x_start  | 
            ||
| 43 | diff_end = y_end - x_end  | 
            ||
| 44 | gab = y_start - x_end  | 
            ||
| 45 | |||
| 46 | if diff_end == 0:  | 
            ||
| 47 | if diff_start == 0:  | 
            ||
| 48 | return Allen.X_EQUAL_Y  | 
            ||
| 49 | |||
| 50 | if diff_start < 0:  | 
            ||
| 51 | return Allen.X_FINISHES_Y  | 
            ||
| 52 | |||
| 53 | return Allen.X_FINISHES_Y_INVERSE  | 
            ||
| 54 | |||
| 55 | if diff_end < 0:  | 
            ||
| 56 | return -Allen.relation(y_start, y_end, x_start, x_end)  | 
            ||
| 57 | |||
| 58 | if gab > 1:  | 
            ||
| 59 | return Allen.X_BEFORE_Y  | 
            ||
| 60 | |||
| 61 | if gab == 1:  | 
            ||
| 62 | return Allen.X_MEETS_Y  | 
            ||
| 63 | |||
| 64 | if diff_start > 0:  | 
            ||
| 65 | return Allen.X_OVERLAPS_WITH_Y  | 
            ||
| 66 | |||
| 67 | if diff_start == 0:  | 
            ||
| 68 | return Allen.X_STARTS_Y  | 
            ||
| 69 | |||
| 70 | if diff_start < 0:  | 
            ||
| 71 | return Allen.X_DURING_Y  | 
            ||
| 72 | |||
| 74 |