def inSegment(P, S):
    """inSegment(): determine if a point is inside a segment

        Input:  a point P, and a collinear segment S
        Return: 1 = P is inside S
                0 = P is  not inside S
    """
    if S.P0.x != S.P1.x:    # S is not  vertical
        if S.P0.x <= P.x and P.x <= S.P1.x:
            return 1
        if S.P0.x >= P.x and P.x >= S.P1.x:
            return 1
    else :    # S is vertical, so test y  coordinate
        if S.P0.y <= P.y and P.y <= S.P1.y:
            return 1
        if S.P0.y >= P.y and P.y >= S.P1.y:
            return 1
    return 0