Determine whether this range overlaps with `other`.
(self, other: Range[_T])
| 332 | __contains__ = contains |
| 333 | |
| 334 | def overlaps(self, other: Range[_T]) -> bool: |
| 335 | "Determine whether this range overlaps with `other`." |
| 336 | |
| 337 | # Empty ranges never overlap with any other range |
| 338 | if self.empty or other.empty: |
| 339 | return False |
| 340 | |
| 341 | slower = self.lower |
| 342 | slower_b = self.bounds[0] |
| 343 | supper = self.upper |
| 344 | supper_b = self.bounds[1] |
| 345 | olower = other.lower |
| 346 | olower_b = other.bounds[0] |
| 347 | oupper = other.upper |
| 348 | oupper_b = other.bounds[1] |
| 349 | |
| 350 | # Check whether this lower bound is contained in the other range |
| 351 | if ( |
| 352 | self._compare_edges(slower, slower_b, olower, olower_b) >= 0 |
| 353 | and self._compare_edges(slower, slower_b, oupper, oupper_b) <= 0 |
| 354 | ): |
| 355 | return True |
| 356 | |
| 357 | # Check whether other lower bound is contained in this range |
| 358 | if ( |
| 359 | self._compare_edges(olower, olower_b, slower, slower_b) >= 0 |
| 360 | and self._compare_edges(olower, olower_b, supper, supper_b) <= 0 |
| 361 | ): |
| 362 | return True |
| 363 | |
| 364 | return False |
| 365 | |
| 366 | def strictly_left_of(self, other: Range[_T]) -> bool: |
| 367 | "Determine whether this range is completely to the left of `other`." |