def height_of_beam_after_dx(d1, d2, L12, distance):
    """
    Calculate the total widths of beam a given distance away from a collimation
    slit.

    if distance >= 0, then it's taken to be the distance after d2.
    if distance < 0, then it's taken to be the distance before d1.

    Parameters
    ----------
    d1: float
        opening of first collimation slit
    d2: float
        opening of second collimation slit
    L12: float
        distance between first and second collimation slits
    distance: float
        distance from first or last slit to a given position

    Notes
    -----
    Units - equivalent distances (inches, mm, light years)

    Returns
    -------
    (umbra, penumbra): float, float
        full width of umbra and penumbra

    """
    alpha = (d1 + d2) / 2.0 / L12
    beta = abs(d1 - d2) / 2.0 / L12
    if distance >= 0:
        return beta * distance * 2 + d2, alpha * distance * 2 + d2
    else:
        return beta * abs(distance) * 2 + d1, alpha * abs(distance) * 2 + d1
