def intersection(a, b, scale=1):
    """Intersection between two segments."""
    try:
        a1, a2 = a
    except TypeError:
        a1 = a.start
        a2 = a.stop
    try:
        b1, b2 = b
    except TypeError:
        b1 = b.start
        b2 = b.stop
    if a2 <= b1:
        return None
    if a1 >= b2:
        return None
    if a2 <= b2:
        if a1 <= b1:
            return slice(b1 * scale, a2 * scale)
        else:
            return slice(a1 * scale, a2 * scale)
    elif a1 <= b1:
        return slice(b1 * scale, b2 * scale)
    else:
        return slice(a1 * scale, b2 * scale)
