def IsPointBetween(M, A, B):
    """ Return True if M is in the rectangle defined by the two points
    A and B."""
    return (A[0] <= M[0] <= B[0] or B[0] <= M[0] <= A[0]) and (A[1] <= M[1] <= B[1] or B[1] <= M[1] <= A[1])