def calc_intersection(r1, r2):
    """
    Calculates the intersection of 2 rects
    Maths from https://es.wikipedia.org/wiki/Intersecci%C3%B3n_de_dos_rectas
    :param r1:
    :param r2:
    :return:
    """
    p1, p2, p3, p4 = r1[0], r1[1], r2[0], r2[1]

    x1, y1 = p1[0], p1[1]
    x2, y2 = p2[0], p2[1]
    x3, y3 = p3[0], p3[1]
    x4, y4 = p4[0], p4[1]
    denom = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
    if denom == 0:
        return None  # parallel
    else:
        tmp_x = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)
        tmp_y = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)
        return tuple([tmp_x / denom, tmp_y / denom])