def on_segment(pt, start, end):
    """Check if pt is between start and end. The three points are presumed to be collinear."""
    pt -= start
    end -= start
    ex, ey = end.x, end.y
    px, py = pt.x, pt.y
    px *= 1 if ex > 0 else -1
    py *= 1 if ey > 0 else -1
    return px >= 0 and px <= abs(ex) and py >= 0 and py <= abs(ey)