Exemplo n.º 1
0
def splitGroupOnLine(points, group1pos, group2pos, groupSizes):
    """
    :type points: [(int, Vector)]
    :type group1pos: Vector
    :type group2pos: Vector
    :type groupSizes: (int, int)
    """
    if len(points) > sum(groupSizes):
        return False
    order = sortAlongLine(points,
                          group1pos,
                          group2pos,
                          access=lambda x: x[1],
                          incTValue=True)
    # typ order: [(float, (int, Vector))]
    #          t value, objIndex, position
    groups = [[], []]
    for o in order:
        if o[0] < 0.5:
            groups[0].append(o[1])
        else:
            groups[1].append(o[1])
    while len(groups[0]) > groupSizes[0]:
        groups[1].append(groups[0].pop())
    while len(groups[1]) > groupSizes[1]:
        groups[0].append(groups[1].pop(0))
    return groups
Exemplo n.º 2
0
def splitGroupOnLine(points, group1pos, group2pos, groupSizes):
    """
    :type points: [(int, Vector)]
    :type group1pos: Vector
    :type group2pos: Vector
    :type groupSizes: (int, int)
    """
    if len(points) > sum(groupSizes):
        return False
    order = sortAlongLine(points, group1pos, group2pos, access=lambda x: x[1],
                          incTValue=True)
    # typ order: [(float, (int, Vector))]
    #          t value, objIndex, position
    groups = [[], []]
    for o in order:
        if o[0] < 0.5:
            groups[0].append(o[1])
        else:
            groups[1].append(o[1])
    while len(groups[0]) > groupSizes[0]:
        groups[1].append(groups[0].pop())
    while len(groups[1]) > groupSizes[1]:
        groups[0].append(groups[1].pop(0))
    return groups