Exemplo n.º 1
0
def decode(name, twoway_mask=False):
    blocks = []
    xleft_cur = None
    nl_cur = None
    # the string is parsed using a two-pointer algorithm
    p1 = p2 = 0
    twoway = False
    while (p1 <= len(name) and p2 <= len(name)):
        if nl_cur is None:
            twoway = False
            if p1 >= len(name):
                break
            while p2 < len(name) and '0' <= name[p2] <= '9':
                p2 += 1
            nl_cur = int(name[p1:p2])
        elif xleft_cur is None:
            if p1 >= len(name):
                break
            location = name[p1]
            p1 += 1
            if name[p1 - 1] == 'D':
                location = name[p1]
                p1 += 1
                twoway = True
            p2 = p1
            # only support 1-digit position!
            if p2 < len(name) and '1' <= name[p2] <= '9':
                p2 += 1
                if p2 < len(name) and name[p2] == 'P':
                    p2 += 1
            elif p2 < len(name) and name[p2:p2 + 2] == '0P':
                p2 += 2
            if p2 < len(name) and (name[p2] < '1' or name[p2] > '9'):
                p2 -= 1
            nl_single = nl_cur // 2 if twoway else nl_cur
            offset_code = str(nl_single) if p1 == p2 else name[p1:p2]
            #print(p1, p2, location, offset_code)
            if location == 'R':
                xleft_cur = offset_x(offset_code) - nl_single * LANEWIDTH
            elif location == 'L':
                xleft_cur = -offset_x(offset_code)
            elif location == 'C':
                xleft_cur = -nl_cur / 2 * LANEWIDTH
            elif location == 'S':
                xleft_cur = (1 - nl_cur) / 2 * LANEWIDTH
            else:
                raise NotImplementedError(
                    "Offset location not understood! Must be L, C, R, or S")
        else:
            #print('add')
            blocks.append(None if twoway and twoway_mask else (xleft_cur,
                                                               nl_cur))
            xleft_cur = None
            nl_cur = None
        p1 = p2
    #print(blocks)
    return blocks
Exemplo n.º 2
0
def find_base(nlane, codes=['5', '5P', '6P', '7P', '8P'], mode=DEFAULT_MODE):
    roads = []
    lefts = [offset_x(k) - nlane * SW.LANE for k in codes]
    for x in lefts:
        v = BaseAsset(x, nlane)
        roads.append(v)
    return roads
Exemplo n.º 3
0
def find_access(nlane, base, name=None, codes=['3', '3P', '4P', '5P', '6P']):
    access_roads = []
    nlane_g = base.get_blocks()[0].nlanes
    x0 = base.x0()
    offsets = [offset_x(code) for code in codes]
    for i_a in range(2, nlane_g - nlane):
        if x0 + (i_a + nlane - 1) * SW.LANE + SW.MEDIAN in offsets:
            access_roads.append(
                Asset(x0, nlane_g, x0,
                      [i_a - 1, nlane, nlane_g - nlane - i_a]))
    return access_roads