<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def check_limits(user_rule):
 """Stop recursion if resolution is too low on number of components is too high """


    def wrapper(*args, **kwargs):
        """The body of the decorator """
        global _state
        _state["cnt_elements"] += 1
        _state["depth"] += 1
        matrix = _state["ctx"].get_matrix()
        # TODO: add check of transparency = 0
        if _state["depth"] >= MAX_DEPTH:
            logger.info("stop recursion by reaching max depth {}".format(MAX_DEPTH))
        else:
            min_size_scaled = SIZE_MIN_FEATURE / min(WIDTH, HEIGHT)
            current_scale = max([abs(matrix[i]) for i in range(2)])
            if (current_scale < min_size_scaled):
                logger.info("stop recursion by reaching min feature size")
                # TODO: check feature size with respect to current ink size
            else:
                if _state["cnt_elements"] > MAX_ELEMENTS:
                    logger.info("stop recursion by reaching max elements")
                else:
                    user_rule(*args, **kwargs)
        _state["depth"] -= 1
    return wrapper