import cv2


def is_large_enough(cont, min_area):
    return cv2.contourArea(cont, False) > min_area


def is_not_too_large(cnt, max_area):
    return cv2.contourArea(cnt, False) < max_area


def has_acceptable_format(cont, max_width_to_height_ratio):
    _, _, w, h = cv2.boundingRect(cont)
    return max_width_to_height_ratio >= w / h >= (1 / max_width_to_height_ratio)


def is_filled(hierarchy):
    """Checks whether a hierarchy is filled.

    References:
        https://stackoverflow.com/questions/60095520/how-to-distinguish-filled-circle-contour-and-unfilled-circle-contour-in-opencv
    """
    return hierarchy[3] <= 0 and hierarchy[2] == -1


def is_boxy(contour):
    epsilon = 0.01 * cv2.arcLength(contour, True)
    approx = cv2.approxPolyDP(contour, epsilon, True)
    return len(approx) <= 10
