def _metric(x1, l1, x2, l2):
    """
    A 1-d metric to define the distance between two lines.

    'x1', 'x2' are coordinates, 'l1', 'l2' are lengths
    """
    return min([abs(x1 + l1 - x2), abs(x2 + l2 - x1), abs(x1 - x2)])