def _is_within_rect(xy, p1, p2):
    """ If xy is withing rectangle defined by p1, p2

    """

    for i in range(2):
        if p1[i] <= xy[i] <= p2[i] or p2[i] <= xy[i] <= p1[i]:
            continue
        else:
            return False

    return True