import math


def deRuiter_radius(src1, src2):
    """Calculates the De Ruiter radius for two sources"""

    # The errors are the square root of the quadratic sum of
    # the systematic and fitted errors.
    src1_ew_uncertainty = math.sqrt(src1.ew_sys_err**2 + src1.error_radius**2) / 3600.
    src1_ns_uncertainty = math.sqrt(src1.ns_sys_err**2 + src1.error_radius**2) / 3600.
    src2_ew_uncertainty = math.sqrt(src2.ew_sys_err**2 + src2.error_radius**2) / 3600.
    src2_ns_uncertainty = math.sqrt(src2.ns_sys_err**2 + src2.error_radius**2) / 3600.

    ra_nom = ((src1.ra - src2.ra) * math.cos(math.radians(0.5 * (src1.dec + src2.dec))))**2
    ra_denom = src1_ew_uncertainty**2 + src2_ew_uncertainty**2
    ra_fac = ra_nom / ra_denom

    dec_nom = (src1.dec - src2.dec)**2
    dec_denom = src1_ns_uncertainty**2 + src2_ns_uncertainty**2
    dec_fac = dec_nom / dec_denom

    dr = math.sqrt(ra_fac + dec_fac)
    return dr