<commit_before>#-*- coding:Utf-8 -*-

# from pylayers.gis.layout import *
# from itertools import combinations
# from scipy.spatial import Delaunay
# import shapely.geometry as sh
# L = Layout('WHERE1_2.ini')
# L.build('t')
# # L.dumpr()
# L.showG('s')

# for n in L.Gt.nodes():
#     no = L.Gt.node[n]['cycle'].cycle
#     nop = L.Gt.node[n]['cycle'].cycle

#     tcc, nn = L.Gt.node[n]['polyg'].ptconvex()

#     utconvex = np.nonzero(tcc == 1)[0]
#     utsconvex = np.nonzero(abs(tcc) == 1)[0]
#     if len(utconvex) != 0:
#         # get points ID in the cycle
#         uu = filter(lambda x: x<0,no)
#         uus = filter(lambda x: x<0,no)
#         # get point convex ID
#         uc = np.array(uu)[utconvex]
#         ucs = np.array(uus)[utsconvex]
#         puc = array(map(lambda x: L.Gs.pos[x], uc))
#         pucs = array(map(lambda x: L.Gs.pos[x], ucs))

#         trid=Delaunay(pucs)
#         tri =trid.simplices
#         # filter tri in the cycle
#         kt = []
#         pkt = []
#         for t in tri:
#             ts = sh.Polygon(pucs[t])
#             U = ts.intersection(L.Gt.node[n]['polyg'])
#             if not U.area < 1e-2:
#                 #pkt.append(pucs[t])
#                 kt.append(t) 
#             # # ptt = puc[tt]
#         plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))




from pylayers.gis.layout import *
from itertools import combinations
from scipy.spatial import Delaunay
import shapely.geometry as sh
L = Layout('TA-Office.ini')
#L.dumpr()
L.build('t')
fig,ax=L.showG('s',labels=True)

# for n in L.Gt.nodes():
#     if n > 0:
#         no = L.Gt.node[n]['cycle'].cycle
#         tcc, nn = L.Gt.node[n]['polyg'].ptconvex()
#         utconvex = np.nonzero(tcc == 1)[0]
#         utsconvex = np.nonzero(abs(tcc) == 1)[0]
#         if len(utconvex) != 0:
#             # get points ID in the cycle
#             uu = filter(lambda x: x<0,no)
#             uus = filter(lambda x: x<0,no)
#             # get point convex ID
#             # uc = np.array(uu)[utconvex]
#             ucs = np.array(uus)[utsconvex]
#             puc = array(map(lambda x: L.Gs.pos[x], uc))
#             pucs = array(map(lambda x: L.Gs.pos[x], ucs))
#             if len(ucs) >2:
#                 trid=Delaunay(pucs)
#                 tri =trid.simplices
#                 # filter tri in the cycle
#                 kt = []
#                 pkt = []
#                 for t in tri:
#                     ts = sh.Polygon(pucs[t])
#                     U = L.Gt.node[n]['polyg'].contains(ts)
#                     if U:
#                         #pkt.append(pucs[t])
#                         kt.append(t) 
#                     # # ptt = puc[tt]
#             try:
#                 plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))
#             except: 
#                 pass
        
def polyplot(poly):
    fig,ax=L.showG('s')
    color=['r','b','g']*10
    for ip, p in enumerate(poly):
        fig,ax = p.plot(fig=fig,ax=ax,color=color[ip],alpha =1)


for n in L.Gt.nodes():
    if n > 0:
        no = L.Gt.node[n]['cycle'].cycle
        tcc, nn = L.Gt.node[n]['polyg'].ptconvex()
        # diffracting points 
        utconvex = np.nonzero(tcc == 1)[0]
        # all possible diffracting point (in and out of cycle)
        utsconvex = np.nonzero(abs(tcc) == 1)[0]
        if len(utconvex) != 0:
            # get points ID in the cycle
            uus = filter(lambda x: x<0,no)
            # get point convex ID
            ucs = np.array(uus)[utsconvex]
            pucs = array(map(lambda x: L.Gs.pos[x], ucs))
            pucs = np.vstack((pucs,pucs[-1]))

            if len(ucs) >2:
                trid=Delaunay(pucs)
                tri =trid.simplices
                # filter tri in the cycle
                kt = []
                pkt = []
                polys = []
                for t in tri:
                    ts = geu.Polygon(pucs[t])
                    #check if inside the original polygon
                    U = L.Gt.node[n]['polyg'].contains(ts)
                    # fig,ax=ts.plot(fig=fig,ax=ax)
                    if U:
                        #pkt.append(pucs[t])
                        kt.append(t) 
                        polys.append(ts)
  
                    # # ptt = puc[tt]
            # try:
            #     plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))
            # except: 
            #     pass
            kt = array(kt)
            npttri = np.arange(0,np.max(kt))
            # search for each triangle, which is connecte
            conecttri = [np.where(kt == i) for i in npttri]

            cpolys = []
            nbpolys = len(polys)
            while polys !=[]:
                p = polys.pop(0)
                for ip2,p2 in enumerate(polys):
                    conv=False
                    inter = p.intersection(p2)
                    # if 2 triangles have a common segment
                    if isinstance(inter,sh.LineString):
                        pold = p
                        p = p + p2
                        if p.isconvex():
                            polys.pop(ip2)
                            polys.insert(0,p)
                            conv=True
                            break
                        else:
                            cpolys.append(pold)
                            p = pold
                if (ip2 >= len(polys)):# and (conv):
                    import ipdb
                    ipdb.set_trace()
                    if conv :
                        cpolys.append(p)
                    else:
                        cpolys.append(pold)

            polyplot(cpolys)



            # for n in range(nbpolys):
            #     p = polys.pop(-1)
            #     ip = iter(polys)
            #     for p2 in ip:
            #         inter = p.intersection(p2)
            #         if isinstance(inter,sh.LineString):
                        

            #     import ipdb
            #     ipdb.set_trace()
            #     try:
            #         mpold = mp
            #         if mp.touches(p):
            #             mp = mp + p
            #             if mp.isconvex():
            #                 mpold = mp
            #             else :
            #                 cpolys.append(mpold)<commit_msg>-remove pdb<commit_after>#-*- coding:Utf-8 -*-

# from pylayers.gis.layout import *
# from itertools import combinations
# from scipy.spatial import Delaunay
# import shapely.geometry as sh
# L = Layout('WHERE1_2.ini')
# L.build('t')
# # L.dumpr()
# L.showG('s')

# for n in L.Gt.nodes():
#     no = L.Gt.node[n]['cycle'].cycle
#     nop = L.Gt.node[n]['cycle'].cycle

#     tcc, nn = L.Gt.node[n]['polyg'].ptconvex()

#     utconvex = np.nonzero(tcc == 1)[0]
#     utsconvex = np.nonzero(abs(tcc) == 1)[0]
#     if len(utconvex) != 0:
#         # get points ID in the cycle
#         uu = filter(lambda x: x<0,no)
#         uus = filter(lambda x: x<0,no)
#         # get point convex ID
#         uc = np.array(uu)[utconvex]
#         ucs = np.array(uus)[utsconvex]
#         puc = array(map(lambda x: L.Gs.pos[x], uc))
#         pucs = array(map(lambda x: L.Gs.pos[x], ucs))

#         trid=Delaunay(pucs)
#         tri =trid.simplices
#         # filter tri in the cycle
#         kt = []
#         pkt = []
#         for t in tri:
#             ts = sh.Polygon(pucs[t])
#             U = ts.intersection(L.Gt.node[n]['polyg'])
#             if not U.area < 1e-2:
#                 #pkt.append(pucs[t])
#                 kt.append(t) 
#             # # ptt = puc[tt]
#         plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))




from pylayers.gis.layout import *
from itertools import combinations
from scipy.spatial import Delaunay
import shapely.geometry as sh
L = Layout('TA-Office.ini')
#L.dumpr()
L.build('t')
fig,ax=L.showG('s',labels=True)

# for n in L.Gt.nodes():
#     if n > 0:
#         no = L.Gt.node[n]['cycle'].cycle
#         tcc, nn = L.Gt.node[n]['polyg'].ptconvex()
#         utconvex = np.nonzero(tcc == 1)[0]
#         utsconvex = np.nonzero(abs(tcc) == 1)[0]
#         if len(utconvex) != 0:
#             # get points ID in the cycle
#             uu = filter(lambda x: x<0,no)
#             uus = filter(lambda x: x<0,no)
#             # get point convex ID
#             # uc = np.array(uu)[utconvex]
#             ucs = np.array(uus)[utsconvex]
#             puc = array(map(lambda x: L.Gs.pos[x], uc))
#             pucs = array(map(lambda x: L.Gs.pos[x], ucs))
#             if len(ucs) >2:
#                 trid=Delaunay(pucs)
#                 tri =trid.simplices
#                 # filter tri in the cycle
#                 kt = []
#                 pkt = []
#                 for t in tri:
#                     ts = sh.Polygon(pucs[t])
#                     U = L.Gt.node[n]['polyg'].contains(ts)
#                     if U:
#                         #pkt.append(pucs[t])
#                         kt.append(t) 
#                     # # ptt = puc[tt]
#             try:
#                 plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))
#             except: 
#                 pass
        
def polyplot(poly):
    fig,ax=L.showG('s')
    color=['r','b','g']*10
    for ip, p in enumerate(poly):
        fig,ax = p.plot(fig=fig,ax=ax,color=color[ip],alpha =1)


for n in L.Gt.nodes():
    if n > 0:
        no = L.Gt.node[n]['cycle'].cycle
        tcc, nn = L.Gt.node[n]['polyg'].ptconvex()
        # diffracting points 
        utconvex = np.nonzero(tcc == 1)[0]
        # all possible diffracting point (in and out of cycle)
        utsconvex = np.nonzero(abs(tcc) == 1)[0]
        if len(utconvex) != 0:
            # get points ID in the cycle
            uus = filter(lambda x: x<0,no)
            # get point convex ID
            ucs = np.array(uus)[utsconvex]
            pucs = array(map(lambda x: L.Gs.pos[x], ucs))
            pucs = np.vstack((pucs,pucs[-1]))

            if len(ucs) >2:
                trid=Delaunay(pucs)
                tri =trid.simplices
                # filter tri in the cycle
                kt = []
                pkt = []
                polys = []
                for t in tri:
                    ts = geu.Polygon(pucs[t])
                    #check if inside the original polygon
                    U = L.Gt.node[n]['polyg'].contains(ts)
                    # fig,ax=ts.plot(fig=fig,ax=ax)
                    if U:
                        #pkt.append(pucs[t])
                        kt.append(t) 
                        polys.append(ts)
  
                    # # ptt = puc[tt]
            # try:
            #     plt.triplot(pucs[:,0],pucs[:,1], np.array(kt))
            # except: 
            #     pass
            kt = array(kt)
            npttri = np.arange(0,np.max(kt))
            # search for each triangle, which is connecte
            conecttri = [np.where(kt == i) for i in npttri]

            cpolys = []
            nbpolys = len(polys)
            while polys !=[]:
                p = polys.pop(0)
                for ip2,p2 in enumerate(polys):
                    conv=False
                    inter = p.intersection(p2)
                    # if 2 triangles have a common segment
                    if isinstance(inter,sh.LineString):
                        pold = p
                        p = p + p2
                        if p.isconvex():
                            polys.pop(ip2)
                            polys.insert(0,p)
                            conv=True
                            break
                        else:
                            cpolys.append(pold)
                            p = pold
                if (ip2 >= len(polys)):# and (conv):
                    if conv :
                        cpolys.append(p)
                    else:
                        cpolys.append(pold)

            polyplot(cpolys)



            # for n in range(nbpolys):
            #     p = polys.pop(-1)
            #     ip = iter(polys)
            #     for p2 in ip:
            #         inter = p.intersection(p2)
            #         if isinstance(inter,sh.LineString):
                        

            #     import ipdb
            #     ipdb.set_trace()
            #     try:
            #         mpold = mp
            #         if mp.touches(p):
            #             mp = mp + p
            #             if mp.isconvex():
            #                 mpold = mp
            #             else :
            #                 cpolys.append(mpold)
{'fraction_non_alphanumeric': 0.13631625370860395, 'fraction_numerical': 0.00833934728570283, 'mean_word_length': 1.1499741423892433, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1444555', 'n_tokens_mistral': 4308, 'n_tokens_neox': 4037, 'n_words': 833}