def METHOD_NAME(self):
    for ty, wire in chain(product(['driver'],self.driver_terminals),
                          product(['receiver'],self.receiver_terminals),
                          product(['wire'],self.wires)):
        llx, lly, urx, ury = wire['rect']
        l = wire['layer']
        if llx < urx:
            assert lly == ury
            for x in range(llx, urx+1):
                self.raster[(x,lly)].add((ty,l))
            for x in range(llx, urx):
                self.segments.add(((x,lly,l),(x+1,lly,l)))
        elif lly < ury:
            assert llx == urx
            for y in range(lly, ury+1):
                self.raster[(llx,y)].add((ty,wire['layer']))
            for y in range(lly, ury):
                self.segments.add(((llx,y,l), (llx,y+1,l)))
        else:
            assert llx == urx and lly == ury
            self.raster[(llx,lly)].add((ty,wire['layer']))
    p = re.compile(r'^M(\d+)$')
    def next_layer(ly):
        m = p.match(ly)
        assert m is not None
        n = int(m.groups()[0])
        return f'M{n+1}'
    for k, lst in self.raster.items():
        x, y = k
        s = set(l for _, l in lst)
        for l in s:
            nl = next_layer(l)
            if nl in s:
                self.segments.add( ( (x,y,l), (x,y,nl) ) )