Compute the intersection of this range with the `other`. .. versionadded:: 2.0.10
(self, other: Range[_T])
| 625 | return self.difference(other) |
| 626 | |
| 627 | def intersection(self, other: Range[_T]) -> Range[_T]: |
| 628 | """Compute the intersection of this range with the `other`. |
| 629 | |
| 630 | .. versionadded:: 2.0.10 |
| 631 | |
| 632 | """ |
| 633 | if self.empty or other.empty or not self.overlaps(other): |
| 634 | return Range(None, None, empty=True) |
| 635 | |
| 636 | slower = self.lower |
| 637 | slower_b = self.bounds[0] |
| 638 | supper = self.upper |
| 639 | supper_b = self.bounds[1] |
| 640 | olower = other.lower |
| 641 | olower_b = other.bounds[0] |
| 642 | oupper = other.upper |
| 643 | oupper_b = other.bounds[1] |
| 644 | |
| 645 | if self._compare_edges(slower, slower_b, olower, olower_b) < 0: |
| 646 | rlower = olower |
| 647 | rlower_b = olower_b |
| 648 | else: |
| 649 | rlower = slower |
| 650 | rlower_b = slower_b |
| 651 | |
| 652 | if self._compare_edges(supper, supper_b, oupper, oupper_b) > 0: |
| 653 | rupper = oupper |
| 654 | rupper_b = oupper_b |
| 655 | else: |
| 656 | rupper = supper |
| 657 | rupper_b = supper_b |
| 658 | |
| 659 | return Range( |
| 660 | rlower, |
| 661 | rupper, |
| 662 | bounds=cast(_BoundsType, rlower_b + rupper_b), |
| 663 | ) |
| 664 | |
| 665 | def __mul__(self, other: Range[_T]) -> Range[_T]: |
| 666 | return self.intersection(other) |
no test coverage detected