from research import circular_research
def coord_to_inter(liste_coord,lat,long,main_street):
    dist=[]
    inter_street=[]
    inter_street_coord=[]
    for inter in liste_coord:
        d=(inter[0]-long)**2 + (inter[1]-lat)**2
        dist.append(d)
    while len(inter_street)<1 :
        candidat=liste_coord[dist.index(min(dist))]
        nom_de_rue=circular_research(candidat[1], candidat[0], main_street)
        if nom_de_rue== None :
            indice=dist.index(min(dist))
            dist.pop(indice)
            liste_coord.pop(indice)
        else : 
            inter_street.append(nom_de_rue)
            inter_street_coord.append(candidat)
            indice=dist.index(min(dist))
            dist.pop(indice)
            liste_coord.pop(indice)
    while len(inter_street)<2 :
        candidat=liste_coord[dist.index(min(dist))]
        dist_1_2= (candidat[0]-inter_street_coord[0][0])**2 + (candidat[1]-inter_street_coord[0][1])**2
        dist_main_2= min(dist)
        if dist_1_2<dist_main_2 :
            indice=dist.index(min(dist))
            dist.pop(indice)
            liste_coord.pop(indice)
        else:
            nom_de_rue=circular_research(candidat[1], candidat[0], main_street)
            if nom_de_rue== None :
                indice=dist.index(min(dist))
                dist.pop(indice)
                liste_coord.pop(indice)
            elif nom_de_rue==inter_street[0]:
                indice=dist.index(min(dist))
                dist.pop(indice)
                liste_coord.pop(indice)
            else : 
                inter_street.append(nom_de_rue)
                inter_street_coord.append(candidat)
                indice=dist.index(min(dist))
                dist.pop(indice)
                liste_coord.pop(indice)
    return inter_street+inter_street_coord