def METHOD_NAME(r, t, imgw, imgh):
    eps = 1e-9
    if abs(t) < eps or abs(t-pi) < eps:
        # near-vertical.
        s = (abs(t) < eps) and 1 or -1
        y0 = 0
        y1 = ((r*s >= 0) * (r*s < imgw)) * imgh
        x0 = x1 = clip(r, 0, imgw)
        return (x0, x1, y0, y1)
    m = -cos(t)/sin(t)
    b = r/sin(t)
    x0 = 0
    x1 = imgw
    y0 = clip(b + m*x0, 0, imgh)
    y1 = clip(b + m*x1, 0, imgh)
    x0 = clip((y0 - b) / m, 0, imgw)
    x1 = clip((y1 - b) / m, 0, imgw)
    y0 = clip(b + m*x0, 0, imgh)
    y1 = clip(b + m*x1, 0, imgh)
    return (x0, x1, y0, y1)