def boxline_(D,X,L,U):
    """ This routine finds the smallest t>=0 for which X+t*D hits the box [L,U]
    Parameters
    ----------
    D      = [dbl] [n-by-1] Direction
    L      = [dbl] [n-by-1] Lower bounds
    X      = [dbl] [n-by-1] Current Point (assumed to live in [L,U])
    U      = [dbl] [n-by-1] Upper bounds

    Returns
    ----------
    t      = [dbl] Value of smallest t>=0 for which X+t*D hits a constraint. Set to 1 if t=1 does not hit constraint for t<1.
    """

    n = len(X)
    t = 1
    for i in range(0,n):
        if D[i] > 0:
            t = min(t,(U[i] - X[i]) / D[i])
        else:
            if D[i] < 0:
                t = min(t,(L[i] - X[i]) / D[i])
    return t