def _same_side(pos, p, q, a, b):
    """Indicates whether the points a and b are at the same side of segment p-q"""
    dx = pos[p][0] - pos[q][0]
    dy = pos[p][1] - pos[q][1]
    dxa = pos[a][0] - pos[p][0]
    dya = pos[a][1] - pos[p][1]
    dxb = pos[b][0] - pos[p][0]
    dyb = pos[b][1] - pos[p][1]
    return (dy*dxa - dx*dya > 0) == (dy*dxb - dx*dyb > 0)