def on_segment(p, q, r):
    """
    Given three collinear points p, q, r, the function checks if point q lies on line segment 'pr'
    :param p: Point p
    :type p: Point
    :param q: Point q
    :type q: Point
    :param r: Point r
    :type r: Point
    :return: True if points are collinear, else False
    """
    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
    return False