def rect_compare(rect1, rect2, area):
    """Calculate the ratio of overlap between two rectangles and the given area

    :param rect1: rectangle specified as (x, y, w, h)
    :type rect1: tuple
    :param rect2: rectangle specificed as (x, y, w, h)
    :type rect2: tuple
    :param area: the area to compare to
    :type area: float
    :return: the ratio of the overlap of rect1 and rect2 to the area, e.g overlap(rect1, rect2)/area
    :rtype: float
    """
    xx1 = max(rect1[0], rect2[0])
    yy1 = max(rect1[1], rect2[1])
    xx2 = min(rect1[0] + rect1[2], rect2[0] + rect2[2])
    yy2 = min(rect1[1] + rect1[3], rect2[1] + rect2[3])
    w = max(0, xx2 - xx1 + 1)
    h = max(0, yy2 - yy1 + 1)
    return float(w * h) / area
