def polar_line_boundaries(polar_line, boundaries = None):
    """
    Input `polar_line` should contain: (rho, cos_theta, sin_theta)

    Returns line points in cartesian space from the polar space parameters for that line:
        (x1, y1, x2, y2)

    `boundaries` if provided define the image boundaries over which the segment should be presented.
    """

    x1, y1, x2, y2 = 0, 0, 0, 0
    rho, cos_theta, sin_theta, d = polar_line

    # Provide more numerical robustness by dividing over greater
    # projection for the line normal
    if cos_theta >= abs(sin_theta):
        y1 = 0

        if boundaries:
            y2 = boundaries[0]
        else:
            y2 = 1

        x1 = (rho - sin_theta * y1) / cos_theta
        x2 = (rho - sin_theta * y2) / cos_theta
    else:
        x1 = 0

        if boundaries:
            x2 = boundaries[1]
        else:
            x2 = 1

        y1 = (rho - cos_theta * x1) / sin_theta
        y2 = (rho - cos_theta * x2) / sin_theta

    return (x1, y1, x2, y2)