def LineObsColFlag(state1, state2, obstaclelist, robrad):
    """
    Performs a collision check between a line connecting two states and a list of obstacles
    We assume that points are inside the environment and not colliding with any obstacles.

    Inputs:
    state1, state2: two states to check (must have passed the PtObsColFlag check)
    obstaclelist: list of obstacles arranged as [[ox,oy,wd,ht],[ox,oy,wd,ht], ...] (ox,oy are lower left corner, wd, ht are width and height)
    robrad: robot radius. if nonzero, it is used to enlarge obstacles and shrink the environment

    Outputs:
    True if collision detected, False if safe
    """

    collision_found = False

    # Get the coordinates of the line connecting two points
    x1 = state1[0]
    y1 = state1[1]
    x2 = state2[0]
    y2 = state2[1]

    for (ox, oy, wd, ht) in obstaclelist:
        # Prepare bloated version of min and max x,y positions of obstacle
        minX = ox - robrad
        minY = oy - robrad
        maxX = ox + wd + robrad
        maxY = oy + ht + robrad

        # Condition for Line to be Completely outside the rectangle: both points on the same side of the obstacle
        if (x1 <= minX and x2 <= minX or  # on the left side
                y1 <= minY and y2 <= minY or  # on the bottom side
                x1 >= maxX and x2 >= maxX or  # on the right side
                y1 >= maxY and y2 >= maxY):  # on the top side
            continue  # if both points on the same side of the obstacle --> no collision possible --> move on

        # The two state are on two different sides of the obstacle
        # Calculate the slope of the line
        lineSlope = (y2 - y1) / (x2 - x1)

        # Connect with a line to other point and check if it lies inside
        yPoint1 = lineSlope * (minX - x1) + y1
        yPoint2 = lineSlope * (maxX - x1) + y1
        xPoint1 = (minY - y1) / lineSlope + x1
        xPoint2 = (maxY - y1) / lineSlope + x1

        if (minY < yPoint1 < maxY or
            minY < yPoint2 < maxY or
            minX < xPoint1 < maxX or
            minX < xPoint2 < maxX):

            collision_found = True
            return collision_found

    return collision_found