def line_goes_through_border(pos1, pos2, dest1, dest2, border, lower, upper):
    """
    Test if the line from (pos1, pos2) to (dest1, dest2) goes through the border between lower and upper.
    """
    try:
        m = (border - pos1) / (dest1 - pos1)
    except ZeroDivisionError:
        return False
    wall_closer = 0 < m < 1
    through_wall = lower <= pos2 + m * (dest2 - pos2) <= upper
    return wall_closer and through_wall