def intersects(box_a, box_b, grace, dynamic_grace):
    """
    Checks whether two rectangles intersect or inside in other.
    Args:
        box_a         <tuple>   : First rectangle (x, y, w, h)
        box_b         <tuple>   : Second rectangle (x, y, w, h)
        grace         <list>    : Relaxation for intersecting rectangles, [x_grace, y_grace]
        dynamic_grace <boolean> : Set True if using relaxation based on rectangle's height otherwise False

    Returns:
        <Boolean> : True if rectangles intersect or inside in other considering grace values otherwise False
    """

    ax1, ay1, aw, ah = box_a
    ax2, ay2 = ax1+aw-1, ay1+ah-1

    bx1, by1, bw, bh = box_b
    bx2, by2 = bx1+bw-1, by1+bh-1

    x_grace = y_grace = 0
    if dynamic_grace:
        x_grace = float(grace[0] * (ah+bh)/2)  # min(ah, bh)  # note: here height is used instead of width
        y_grace = float(grace[1] * min(ah, bh))

    x_grace = round(x_grace)
    y_grace = round(y_grace)

    if ax1-bx2 > x_grace or bx1-ax2 > x_grace or ay1-by2 > y_grace or by1-ay2 > y_grace:
        return False
    else:
        return True