Return the absolute positive distance from this span to other span. Overlapping spans have a zero distance. Non-overlapping touching spans have a distance of one. For example: >>> Span([8, 9]).distance_to(Span([5, 7])) 1 >>> Span([5, 7]).dist
(self, other)
| 400 | return self.start == other.end + 1 or self.end == other.start - 1 |
| 401 | |
| 402 | def distance_to(self, other): |
| 403 | """ |
| 404 | Return the absolute positive distance from this span to other span. |
| 405 | Overlapping spans have a zero distance. |
| 406 | Non-overlapping touching spans have a distance of one. |
| 407 | |
| 408 | For example: |
| 409 | >>> Span([8, 9]).distance_to(Span([5, 7])) |
| 410 | 1 |
| 411 | >>> Span([5, 7]).distance_to(Span([8, 9])) |
| 412 | 1 |
| 413 | >>> Span([5, 6]).distance_to(Span([8, 9])) |
| 414 | 2 |
| 415 | >>> Span([8, 9]).distance_to(Span([5, 6])) |
| 416 | 2 |
| 417 | >>> Span([5, 7]).distance_to(Span([5, 7])) |
| 418 | 0 |
| 419 | >>> Span([4, 5, 6]).distance_to(Span([5, 6, 7])) |
| 420 | 0 |
| 421 | >>> Span([5, 7]).distance_to(Span([10, 12])) |
| 422 | 3 |
| 423 | >>> Span([1, 2]).distance_to(Span(range(4, 52))) |
| 424 | 2 |
| 425 | """ |
| 426 | if self.overlap(other): |
| 427 | return 0 |
| 428 | |
| 429 | if self.touch(other): |
| 430 | return 1 |
| 431 | |
| 432 | if self.is_before(other): |
| 433 | return other.start - self.end |
| 434 | else: |
| 435 | return self.start - other.end |
| 436 | |
| 437 | @staticmethod |
| 438 | def from_ints(ints): |
no test coverage detected