'top is a rectangle (w,h)
bottom is a rectangle (w,h)
pos is the top left corner of the top rectangle with respect to the bottom rectangle\'s top left corner
method returns none if the two rectangles do not overlap. Otherwise returns the top rectangle\'s ROI (x,y,w,h)
and the bottom rectangle\'s ROI (x,y,w,h)'

def _rectOverlapROIs(self, top, bottom, pos):

    tr = ((pos[0] + top[0]), pos[1])
    tl = pos
    br = ((pos[0] + top[0]), (pos[1] + top[1]))
    bl = (pos[0], (pos[1] + top[1]))
    def inBounds((w, h), (x, y)):
        retVal = True
        if ((x < 0) or (y < 0) or (x > w) or (y > h)):
            retVal = False
        return retVal
    trc = inBounds(bottom, tr)
    tlc = inBounds(bottom, tl)
    brc = inBounds(bottom, br)
    blc = inBounds(bottom, bl)
    if ((not trc) and (not tlc) and (not brc) and (not blc)):
        return (None, None)
    elif (trc and tlc and brc and blc):
        tRet = (0, 0, top[0], top[1])
        bRet = (pos[0], pos[1], top[0], top[1])
        return (tRet, bRet)
    tl = (np.clip(tl[0], 0, bottom[0]), np.clip(tl[1], 0, bottom[1]))
    br = (np.clip(br[0], 0, bottom[0]), np.clip(br[1], 0, bottom[1]))
    bx = tl[0]
    by = tl[1]
    bw = abs((tl[0] - br[0]))
    bh = abs((tl[1] - br[1]))
    pos = (((-1) * pos[0]), ((-1) * pos[1]))
    tr = ((pos[0] + bottom[0]), pos[1])
    tl = pos
    br = ((pos[0] + bottom[0]), (pos[1] + bottom[1]))
    bl = (pos[0], (pos[1] + bottom[1]))
    tl = (np.clip(tl[0], 0, top[0]), np.clip(tl[1], 0, top[1]))
    br = (np.clip(br[0], 0, top[0]), np.clip(br[1], 0, top[1]))
    tx = tl[0]
    ty = tl[1]
    tw = abs((br[0] - tl[0]))
    th = abs((br[1] - tl[1]))
    return ((tx, ty, tw, th), (bx, by, bw, bh))
