MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / distance_to

Method distance_to

src/licensedcode/spans.py:402–435  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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):

Callers 3

get_matching_regionsFunction · 0.95
qdistance_toMethod · 0.80
idistance_toMethod · 0.80

Calls 3

overlapMethod · 0.95
touchMethod · 0.95
is_beforeMethod · 0.95

Tested by

no test coverage detected