def bezier(point, line, check=False):
    """
    Apply bezier algorithm to return a value t from 0 to 1 in x and y,
    that is tx and ty, if point is inside line where t would be the
     percentage of the distance from point1 to point2. If point
    is outside line then t<0 or t>1. If line is horizontal then ty is not
    percentage but the distance from the horizontal and conversely if line
    is vertical then tx is not percentage but the distance from the vertical.

    :param point: point
    :param line: (point1, point2)
    :param check: True to check tx and ty and return None if point is not
        between point1 and point2 in the line.
    :return: tx, ty
    """
    px, py = point
    (x1, y1), (x2, y2) = line
    dx = x1 - x2
    dy = y1 - y2
    tx = x1 - px
    if dx != 0:
        tx /= dx
        if check and not 0 <= tx <= 1:
            return None
    elif check and px != x1:
        return None
    ty = y1 - py
    if dy != 0:
        ty /= dy
        if check and not 0 <= ty <= 1:
            return None
    elif check and py != y1:
        return None
    return tx, ty
