(Q_L1, Q_L2, Q_L3, Q_L4, exclude=None)
return rules
Transform sequences of quadrants to a sequence of rules.
Transform sequences of quadrants to a sequence of rules.
Transform sequences of quadrants to a sequence of rules .
def _traverse_quadrants(Q_L1, Q_L2, Q_L3, Q_L4, exclude=None):
    """Transform sequences of quadrants to a sequence of rules. """
    if exclude is True:
        edges = [1, 1, 0, 0]

        corners = {
            (0, 1): 1,
            (1, 2): 1,
            (2, 3): 0,
            (3, 0): 1,
        }
    else:
        edges = [0, 0, 0, 0]

        corners = {
            (0, 1): 0,
            (1, 2): 0,
            (2, 3): 0,
            (3, 0): 0,
        }

    if exclude is not None and exclude is not True:
        exclude = set(exclude)

        for i, edge in enumerate(['S', 'E', 'N', 'W']):
            if edge in exclude:
                edges[i] = 1

        for i, corner in enumerate(['SW', 'SE', 'NE', 'NW']):
            if corner in exclude:
                corners[((i - 1) % 4, i)] = 1

    QQ, rules = [Q_L1, Q_L2, Q_L3, Q_L4], []

    for i, Q in enumerate(QQ):
        if not Q:
            continue

        if Q[-1] == OO:
            Q = Q[:-1]

        if Q[0] == OO:
            j, Q = (i - 1) % 4, Q[1:]
            qq = (QQ[j][-2], OO, Q[0])

            if qq in _rules_ambiguous:
                rules.append((_rules_ambiguous[qq], corners[(j, i)]))
            else:
                raise NotImplementedError("3 element rule (corner): " + str(qq))

        q1, k = Q[0], 1

        while k < len(Q):
            q2, k = Q[k], k + 1

            if q2 != OO:
                qq = (q1, q2)

                if qq in _rules_simple:
                    rules.append((_rules_simple[qq], 0))
                elif qq in _rules_ambiguous:
                    rules.append((_rules_ambiguous[qq], edges[i]))
                else:
                    raise NotImplementedError("2 element rule (inside): " + str(qq))
            else:
                qq, k = (q1, q2, Q[k]), k + 1

                if qq in _rules_ambiguous:
                    rules.append((_rules_ambiguous[qq], edges[i]))
                else:
                    raise NotImplementedError("3 element rule (edge): " + str(qq))

            q1 = qq[-1]

    return rules
def _traverse_quadrants ( Q_L1 , Q_L2 , Q_L3 , Q_L4 , exclude = None ) : if exclude is True : edges = [ 1 , 1 , 0 , 0 ] corners = { ( 0 , 1 ) : 1 , ( 1 , 2 ) : 1 , ( 2 , 3 ) : 0 , ( 3 , 0 ) : 1 , } else : edges = [ 0 , 0 , 0 , 0 ] corners = { ( 0 , 1 ) : 0 , ( 1 , 2 ) : 0 , ( 2 , 3 ) : 0 , ( 3 , 0 ) : 0 , } if exclude is not None and exclude is not True : exclude = set ( exclude ) for i , edge in enumerate ( [ 'S' , 'E' , 'N' , 'W' ] ) : if edge in exclude : edges [ i ] = 1 for i , corner in enumerate ( [ 'SW' , 'SE' , 'NE' , 'NW' ] ) : if corner in exclude : corners [ ( ( i - 1 ) % 4 , i ) ] = 1 QQ , rules = [ Q_L1 , Q_L2 , Q_L3 , Q_L4 ] , [ ] for i , Q in enumerate ( QQ ) : if not Q : continue if Q [ - 1 ] == OO : Q = Q [ : - 1 ] if Q [ 0 ] == OO : j , Q = ( i - 1 ) % 4 , Q [ 1 : ] qq = ( QQ [ j ] [ - 2 ] , OO , Q [ 0 ] ) if qq in _rules_ambiguous : rules . append ( ( _rules_ambiguous [ qq ] , corners [ ( j , i ) ] ) ) else : raise NotImplementedError ( "3 element rule (corner): " + str ( qq ) ) q1 , k = Q [ 0 ] , 1 while k < len ( Q ) : q2 , k = Q [ k ] , k + 1 if q2 != OO : qq = ( q1 , q2 ) if qq in _rules_simple : rules . append ( ( _rules_simple [ qq ] , 0 ) ) elif qq in _rules_ambiguous : rules . append ( ( _rules_ambiguous [ qq ] , edges [ i ] ) ) else : raise NotImplementedError ( "2 element rule (inside): " + str ( qq ) ) else : qq , k = ( q1 , q2 , Q [ k ] ) , k + 1 if qq in _rules_ambiguous : rules . append ( ( _rules_ambiguous [ qq ] , edges [ i ] ) ) else : raise NotImplementedError ( "3 element rule (edge): " + str ( qq ) ) q1 = qq [ - 1 ] return rules