def inside_area(p, q, r):
    """
    Given a line segment pr and a point q, determine if the point q
    lies inside the rectangle surrounding line segment pr.
    """
    # Taken from:
    # http://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/

    if (q.x <= max(p.x, r.x) and q.x >= min(p.x, r.x) and
        q.y <= max(p.y, r.y) and q.y >= min(p.y, r.y)):
        return True
    else:
        return False