from ezdxf.entities import Line
import math
import plant2dxf

RADIUS = 400
def erstellung_gefaelle_block_verbunenden_am_einen(msp,x, y, doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, hoehe_gefaehlle, drehung0, laenge,blockname,config, hight = None,  block_vario = None, vario_richtung = None, verbungden_höher = None,gefaelle_block=None,start = None,ende = None,mit_horizontal_verbunden = None):
    halbe_laenge = laenge / 2
    dy = halbe_laenge * math.cos(0)
    asoffset = float(config.get("ILS 2.0 Gefällestrecke", "asoffset"))
    esoffset = float(config.get("ILS 2.0 Gefällestrecke", "esoffset"))
    winkel_as = float(config.get("Ils 2.0 core winkel", "winkel_as"))
    winkel_es = float(config.get("Ils 2.0 core winkel", "winkel_es"))
    asoffset_y = asoffset * math.cos(math.radians(winkel_as))
    asoffset_z = asoffset * math.sin(math.radians(winkel_as))
    esoffset_y = esoffset * math.cos(math.radians(winkel_es))
    esoffset_z = esoffset * math.sin(math.radians(winkel_es))
    block_as = None
    block_es = None
    if (( hight == "higher" and drehung0 == "GUZS" )or (vario_richtung == "Auf"and verbungden_höher == False and drehung0 == "GUZS")or
         (vario_richtung == "Ab" and verbungden_höher == True and drehung0 == "GUZS")or (vario_richtung == "Horizontal"  and drehung0 == "GUZS" and (mit_horizontal_verbunden == "unten_drehung_0_or_-90" or mit_horizontal_verbunden == "oben_drehung_-180_or_-270"))):
        block_as = "200000241_AS-Element_90_rechts"
        plant2dxf.import_block(block_as,lib_doc,doc)
        layer, color = plant2dxf.get_insert_color_layer(lib_doc, block_as)

    elif  ((hight == "lower" and drehung0 == "GUZS") or (vario_richtung == "Auf"and verbungden_höher == True and drehung0 == "GUZS")  or 
           (vario_richtung == "Ab" and verbungden_höher == False and drehung0 == "GUZS")or (vario_richtung == "Horizontal"  and drehung0 == "GUZS" and (mit_horizontal_verbunden == "oben_drehung_0_or_-90" or mit_horizontal_verbunden == "unten_drehung_-180_or_-270"))):
        block_es = "200000146_ES-Element_90_rechts"
        plant2dxf.import_block(block_es,lib_doc,doc)
        layer, color = plant2dxf.get_insert_color_layer(lib_doc, block_es)

    elif ((hight == "higher" and drehung0 == "UZS")or (vario_richtung == "Auf"and verbungden_höher == False and drehung0 == "UZS")  or 
          (vario_richtung == "Ab" and verbungden_höher == True and drehung0 == "UZS")or (vario_richtung == "Horizontal"  and drehung0 == "UZS" and (mit_horizontal_verbunden == "unten_drehung_0_or_-90" or mit_horizontal_verbunden == "oben_drehung_-180_or_-270"))):
        block_as = "200000217_AS-Element_90_links"
        plant2dxf.import_block(block_as,lib_doc,doc)
        layer, color = plant2dxf.get_insert_color_layer(lib_doc, block_as)

    elif (( hight == "lower" and drehung0 == "UZS") or (vario_richtung == "Auf" and verbungden_höher == True and drehung0 == "UZS")  or 
          (vario_richtung == "Ab" and verbungden_höher == False and drehung0 == "UZS")or (vario_richtung == "Horizontal"  and drehung0 == "UZS" and  (mit_horizontal_verbunden == "oben_drehung_0_or_-90" or mit_horizontal_verbunden == "unten_drehung_-180_or_-270"))):
        block_es = "400102632_ES-Element_90_links"
        plant2dxf.import_block(block_es,lib_doc,doc)
        layer, color = plant2dxf.get_insert_color_layer(lib_doc, block_es)

    if block_as != None:
        block_as = plant2dxf.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as))
        if vario_richtung == "Auf" or vario_richtung =="Horizontal":
            start = (x , y + dy ,upper_hoehe_gefaehlle)
            ende  = (x , y - dy + asoffset_y ,lower_hoehe_gefaehlle - asoffset_z)
            block_vario.add_blockref(block_as,(ende[0]-x  ,ende[1]-asoffset_y -y,ende[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"rotation": 180,"layer":layer,"color":color})
            return start, ende
        elif vario_richtung == "Ab":
            start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z)
            ende  = (x , y - dy ,lower_hoehe_gefaehlle)
            block_vario.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"layer":layer,"color":color})
            return start,ende

        if laenge > asoffset:
            start[1] = start[1] - asoffset_y
            start[2] = start[2] - asoffset_z
            line = Line.new(dxfattribs={"start": start, "end": ende})
            line.dxf.layer = "6-SP"
            copy= line.copy()
            copy.translate(-x,-y,-hoehe_gefaehlle)
            gefaelle_block.add_entity(copy)
            gefaelle_block.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] -hoehe_gefaehlle + asoffset_z),dxfattribs={"layer":layer,"color":color})
            return False
        else:
            msp.add_blockref(block_as,(x,y,upper_hoehe_gefaehlle),dxfattribs={"layer":layer,"color":color})
            return True
    elif block_es != None:
        block_es = plant2dxf.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es))
        if vario_richtung == "Auf" or vario_richtung =="Horizontal":
            start = (x , y + dy-esoffset_y ,upper_hoehe_gefaehlle + esoffset_z)
            ende  = (x , y - dy,lower_hoehe_gefaehlle)
            block_vario.add_blockref(block_es, (start[0]-x  ,start[1]+esoffset_y -y,start[2] - hoehe_gefaehlle - esoffset_z),dxfattribs={"rotation": 180,"layer":layer,"color":color})
            return  start, ende
        elif vario_richtung == "Ab":
            start = (x , y + dy ,upper_hoehe_gefaehlle)
            ende  = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z)
            block_vario.add_blockref(block_es, (ende[0]-x  ,ende[1]-esoffset_y -y,ende[2] - hoehe_gefaehlle -esoffset_z),dxfattribs={"layer":layer,"color":color})
            return start,ende

        if laenge > esoffset:
            ende[1]  = ende[1] + esoffset_y
            ende[2]  = ende[2] + esoffset_z
            line = Line.new(dxfattribs={"start": start, "end": ende})
            line.dxf.layer = "6-SP"
            copy= line.copy()
            copy.translate(-x ,-y,-hoehe_gefaehlle)
            gefaelle_block.add_entity(copy)
            gefaelle_block.add_blockref(block_es, (ende[0]-x  ,ende[1]-esoffset_y -y,ende[2] - hoehe_gefaehlle -esoffset_z),dxfattribs={"layer":layer,"color":color})
            return False
        else:
            msp.add_blockref(block_es,(x,y,lower_hoehe_gefaehlle),dxfattribs={"layer":layer,"color":color})
            return True

def gefaellegerade_erstellung(x, y, doc, lib_doc, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, hoehe_gefaehlle,richtung2, drehung0, drehung1, laenge, hight_position, blockname,config, block_vario = None,voerder_richtung = None, am_kreisel = None, erster_kreisel_höher = None,y1=None,z1 =None):
    #erstellung des blockes falls die gefaelle strecke mit einem kreisel verbunden ist, mehrere variation von selben weil diese nötig sind sobald man die richtigen inserts bekommen

    asoffset = float(config.get("ILS 2.0 Gefällestrecke", "asoffset"))
    esoffset = float(config.get("ILS 2.0 Gefällestrecke", "esoffset"))
    winkel_as = float(config.get("Ils 2.0 core winkel", "winkel_as"))
    winkel_es = float(config.get("Ils 2.0 core winkel", "winkel_es"))
    asoffset_y = asoffset * math.cos(math.radians(winkel_as))
    asoffset_z = asoffset * math.sin(math.radians(winkel_as))
    esoffset_y = esoffset * math.cos(math.radians(winkel_es))
    esoffset_z = esoffset * math.sin(math.radians(winkel_es))
    block_as = None
    block_es = None
    halbe_laenge = laenge / 2
    dy = halbe_laenge * math.cos(0)
    if upper_hoehe_gefaehlle < lower_hoehe_gefaehlle:
        middle_hoehe = upper_hoehe_gefaehlle
        upper_hoehe_gefaehlle = lower_hoehe_gefaehlle
        lower_hoehe_gefaehlle = middle_hoehe

    if richtung2!= "DEFAULT" or am_kreisel != None:
        # Schaut bei gleicher Orentierung
        if ((drehung0 == "GUZS" and drehung1 == "GUZS" and hight_position == "higher") or
            (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel== 2 and erster_kreisel_höher == True)) and drehung0 == "GUZS" and drehung1== "GUZS") or
            (voerder_richtung == "Ab"and ((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel== 2 and erster_kreisel_höher == False)) and drehung0 == "GUZS" and drehung1== "GUZS") or
        # Schaut bei ungleicher Orentierung
            ((drehung0 == "UZS" and drehung1 == "GUZS" and hight_position== "higher"))or
            (voerder_richtung == "Auf"and ((am_kreisel == 1 and erster_kreisel_höher == False) or (am_kreisel ==2 and erster_kreisel_höher ==True))and  (drehung0 == "GUZS" and drehung1 == "UZS")) or
            (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "UZS" and drehung1 == "GUZS"))):
            block_es = "200000146_ES-Element_90_rechts"
            plant2dxf.import_block(block_es,lib_doc,doc) 
            layer, color = plant2dxf.get_insert_color_layer(lib_doc,block_es)
            
        elif  ((drehung0 == "GUZS" and drehung1 == "GUZS") or
            (am_kreisel != None and drehung0 == "GUZS" and drehung1 == "GUZS") or
            (drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "lower")or
            (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "UZS" and drehung1 == "GUZS")) or
            (voerder_richtung == "Ab"and ((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "GUZS" and drehung1 == "UZS"))):
            block_as = "200000241_AS-Element_90_rechts"
            plant2dxf.import_block(block_as,lib_doc,doc)
            layer, color = plant2dxf.get_insert_color_layer(lib_doc,block_as)
            
        elif ((drehung0 == "UZS" and drehung1 == "UZS" and hight_position == "higher")or
            (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel== 2 and erster_kreisel_höher == True)) and drehung0 == "UZS" and drehung1== "UZS")or
            (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel== 2 and erster_kreisel_höher == False)) and drehung0 == "UZS" and drehung1== "UZS") or
            
            (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "higher")or
            (voerder_richtung == "Auf" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "UZS" and drehung1 == "GUZS")) or
            (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == True) or (am_kreisel ==2 and erster_kreisel_höher ==False))and  (drehung0 == "GUZS" and drehung1 == "UZS"))):

            block_es = "400102632_ES-Element_90_links"
            plant2dxf.import_block(block_es,lib_doc,doc)
            layer, color = plant2dxf.get_insert_color_layer(lib_doc,block_es)



        elif (((drehung0 == "UZS" and drehung1 == "UZS")or
            (am_kreisel!= None and drehung0 == "UZS" and drehung1 == "UZS")) or
            (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "lower")or
            (voerder_richtung == "Auf"and((am_kreisel == 1 and erster_kreisel_höher == True)or (am_kreisel == 2 and erster_kreisel_höher == False))and (drehung0 == "GUZS" and drehung1 == "UZS")) or
            (voerder_richtung == "Ab" and((am_kreisel == 1 and erster_kreisel_höher == False)or (am_kreisel == 2 and erster_kreisel_höher == True))and (drehung0 == "UZS" and drehung1 == "GUZS"))):
            block_as = "200000217_AS-Element_90_links"
            plant2dxf.import_block(block_as,lib_doc,doc)
            layer, color = plant2dxf.get_insert_color_layer(lib_doc,block_as)

        
        if block_es != None:
            block_es = plant2dxf.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es))
            if voerder_richtung == "Auf":
                start = (x , y+ dy - esoffset_y,upper_hoehe_gefaehlle + esoffset_z)
                ende  = (x , y1 ,z1)
                block_vario.add_blockref(block_es, (start[0]-x ,start[1]+esoffset_y-y ,start[2] - esoffset_z-hoehe_gefaehlle),dxfattribs={"rotation": 180,"layer": layer,"color": color})
                return start,ende
            elif(voerder_richtung == "Ab"):
                start = (x , y1 ,z1)
                ende  = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z)
                block_vario.add_blockref(block_es, (ende[0]-x ,ende[1]-esoffset_y-y ,ende[2] - esoffset_z -hoehe_gefaehlle),dxfattribs={"layer": layer,"color": color})
                return start, ende
            elif am_kreisel == None and blockname not in doc.blocks:
                block = doc.blocks.new(name=blockname, base_point=(0,0,0))
                start = (x , y + dy,upper_hoehe_gefaehlle)
                ende  = (x , y - dy  + esoffset_y,lower_hoehe_gefaehlle + esoffset_z)
                line = Line.new(dxfattribs={"start": start, "end": ende})
                line.dxf.layer = "6-SP"
                copy= line.copy()
                copy.translate(-x,-y,-hoehe_gefaehlle)
                block.add_entity(copy)
                block.add_blockref(block_es, (ende[0]-x ,ende[1]- esoffset_y -y ,ende[2] -hoehe_gefaehlle ),dxfattribs={"layer": layer,"color": color})
        if block_as != None:
            block_as = plant2dxf.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as))
            if voerder_richtung == "Auf":
                start = (x , y1,z1)
                ende  = (x , y - dy + asoffset_y ,lower_hoehe_gefaehlle)
                block_vario.add_blockref(block_as,(ende[0]-x  ,ende[1]-asoffset_y -y,ende[2] - esoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": layer,"color": color})
                return start, ende
            elif voerder_richtung == "Ab":
                start = (x , y +dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z)
                ende  = (x , y1 ,z1)
                block_vario.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": layer,"color": color})
                return start,ende
            elif am_kreisel == None and blockname not in doc.blocks:
                block = doc.blocks.new(name=blockname, base_point=(0,0,0))
                start = (x , y +dy - asoffset_y,upper_hoehe_gefaehlle- asoffset_z)
                ende  = (x , y - dy ,lower_hoehe_gefaehlle)
                line = Line.new(dxfattribs={"start": start, "end": ende})
                line.dxf.layer = "6-SP"

                copy= line.copy()
                copy.translate(-x ,-y,-hoehe_gefaehlle)

                block.add_entity(copy)
                block.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle))
    else:
        if (( drehung0 == "GUZS" and drehung1 == "GUZS") or (voerder_richtung != None and  drehung0 == "GUZS" and drehung1 == "GUZS")):
            block_as = "200000241_AS-Element_90_rechts"
            plant2dxf.import_block(block_as,lib_doc,doc)
            block_es = "200000146_ES-Element_90_rechts"
            plant2dxf.import_block(block_es,lib_doc,doc)
            as_layer, as_color = plant2dxf.get_insert_color_layer(lib_doc,block_as)
            es_layer, es_color = plant2dxf.get_insert_color_layer(lib_doc,block_es)
        elif  (((drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "higher")or (drehung0 == "UZS" and drehung1 == "GUZS" and hight_position == "lower")) or
               (voerder_richtung == "Auf" and drehung0 == "UZS"and drehung1 == "GUZS") or
               (voerder_richtung == "Ab" and drehung0 == "GUZS" and drehung1 == "UZS")) :
            block_as = "200000241_AS-Element_90_rechts"
            plant2dxf.import_block(block_as,lib_doc,doc)
            block_es = "400102632_ES-Element_90_links"
            plant2dxf.import_block(block_es,lib_doc,doc)
            as_layer, as_color = plant2dxf.get_insert_color_layer(lib_doc,block_as)
            es_layer, es_color = plant2dxf.get_insert_color_layer(lib_doc,block_es)
        elif (( drehung0 == "UZS" and drehung1 == "UZS") or (voerder_richtung != None and  drehung0 == "UZS" and drehung1 == "UZS")):
            block_as = "200000217_AS-Element_90_links"
            plant2dxf.import_block(block_as,lib_doc,doc)
            block_es = "400102632_ES-Element_90_links"
            plant2dxf.import_block(block_es,lib_doc,doc)
            as_layer, as_color = plant2dxf.get_insert_color_layer(lib_doc,block_as)
            es_layer, es_color = plant2dxf.get_insert_color_layer(lib_doc,block_es)
        elif ((((drehung0 == "UZS" and drehung1 == "GUZS" and hight_position== "higher")or (drehung0 == "GUZS" and drehung1 == "UZS" and hight_position == "lower")))or
            (voerder_richtung == "Auf" and drehung0 == "GUZS" and drehung1 == "UZS") or
            (voerder_richtung == "Ab" and drehung0 == "UZS"and drehung1 == "GUZS")) :

            block_as = "200000217_AS-Element_90_links"
            plant2dxf.import_block(block_as,lib_doc,doc)
            block_es = "200000146_ES-Element_90_rechts"
            plant2dxf.import_block(block_es,lib_doc,doc)
            as_layer, as_color = plant2dxf.get_insert_color_layer(lib_doc,block_as)
            es_layer, es_color = plant2dxf.get_insert_color_layer(lib_doc,block_es)
        block_as = plant2dxf.dreh_block(block_as,doc,lib_doc,math.radians(winkel_as))
        block_es = plant2dxf.dreh_block(block_es,doc,lib_doc,math.radians(winkel_es))
        halbe_laenge = laenge / 2

        dy = halbe_laenge * math.cos(0)
        if hight_position != None and blockname not in doc.blocks:
            block = doc.blocks.new(name=blockname, base_point=(0,0,0))
            start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle- asoffset_z)
            ende  = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z)
            line = Line.new(dxfattribs={"start": start, "end": ende})
            line.dxf.layer = "6-SP"

            copy= line.copy()

            copy.translate(-x ,-y,-hoehe_gefaehlle)
            block.add_entity(copy)
            block.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": as_layer,"color": as_color})
            block.add_blockref(block_es, (ende[0]-x  ,ende[1]-esoffset_y -y,ende[2]  - esoffset_z - hoehe_gefaehlle ),dxfattribs={"layer": es_layer,"color": es_color})
            return
        if voerder_richtung == "Auf":
            start = (x , y + dy - esoffset_y,upper_hoehe_gefaehlle + esoffset_z)
            ende  = (x , y - dy + asoffset,lower_hoehe_gefaehlle -asoffset_z)

            block_vario.add_blockref(block_es,(start[0]-x  ,start[1]+esoffset_y -y,start[2] - esoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": as_layer,"color": as_color})
            block_vario.add_blockref(block_as, (ende[0]-x  ,ende[1]-asoffset_y -y,ende[2] + asoffset_z - hoehe_gefaehlle ),dxfattribs={"rotation": 180,"layer": es_layer,"color": es_color})
            return start,ende
        elif voerder_richtung == "Ab":
            start = (x , y + dy - asoffset_y,upper_hoehe_gefaehlle - asoffset_z)
            ende  = (x , y - dy + esoffset_y,lower_hoehe_gefaehlle + esoffset_z)

            block_vario.add_blockref(block_as,(start[0]-x  ,start[1]+asoffset_y -y,start[2] + asoffset_z - hoehe_gefaehlle),dxfattribs={"layer": as_layer,"color": as_color})
            block_vario.add_blockref(block_es, (ende[0]-x  ,ende[1]-esoffset_y -y,ende[2] - esoffset_z - hoehe_gefaehlle),dxfattribs={"layer": es_layer,"color": es_color})
            return start,ende

        
def am_kreisel_direct_verbunden(x, y, upper_hoehe_gefaehlle, lower_hoehe_gefaehlle, x0_kreisel, y0_kreisel, richtung_rad0, abstand0, dx, dy, x1_kreisel, y1_kreisel, richtung_rad1, abstand1,kreisel_verbunden= None, richtung0 = None, richtung1 = None, richtung2 = None):
    if kreisel_verbunden == None:
        kreisel_verbunden = 0
    unterschiedlich = False
    am_kreisel = 0
    halbabstand0 = abstand0 / 2
    dx0 = halbabstand0 * math.cos(richtung_rad0)
    dy0 = halbabstand0 * math.sin(richtung_rad0)
    pos0_0_floor= (math.floor(x0_kreisel + dx0),math.floor( y0_kreisel + dy0))
    pos0_1_floor = (math.floor(x0_kreisel- dx0),math.floor( y0_kreisel- dy0))
    pos0_0_round= (round(x0_kreisel + dx0),round( y0_kreisel + dy0))
    pos0_1_round = (round(x0_kreisel- dx0),round( y0_kreisel- dy0))
    if (x1_kreisel != None):
        halbabstand1 = abstand1 / 2
        dx1 = halbabstand1 * math.cos(richtung_rad1 )
        dy1 = halbabstand1 * math.sin(richtung_rad1)
        pos1_0_floor = (math.floor(x1_kreisel + dx1), math.floor(y1_kreisel + dy1))
        pos1_1_floor = (math.floor(x1_kreisel - dx1), math.floor(y1_kreisel - dy1))
        pos1_0_round = (round(x1_kreisel + dx1), round(y1_kreisel + dy1))
        pos1_1_round = (round(x1_kreisel - dx1), round(y1_kreisel - dy1))

    # berechnung der geraden einmal abgerunden und einmal gerunden zur negirung des offsets
    start_floor = (math.floor(x +dx ), math.floor(y + dy ),upper_hoehe_gefaehlle)
    ende_floor  = (math.floor(x -dx), math.floor(y - dy ) ,lower_hoehe_gefaehlle)
    start_round = (round(x +dx ), round(y + dy ),upper_hoehe_gefaehlle)
    ende_round= (round(x -dx), round(y - dy ) ,lower_hoehe_gefaehlle)
        # verschiebund der endpunkte der gerade in richtung von dem potentiellen Kreisel für den vergleich wieder mit floor und rundung
    abstand_fuer_kreis_start_x_floor = start_floor[0] +RADIUS, start_floor[1]
    abstand_gegen_kreis_start_x_floor = start_floor[0] -RADIUS, start_floor[1]
    abstand_fuer_kreis_start_y_floor = start_floor[0], start_floor[1] + RADIUS
    abstand_gegen_kreis_start_y_floor = start_floor[0], start_floor[1] - RADIUS
    abstand_fuer_kreis_ende_x_floor= ende_floor[0] + RADIUS, ende_floor[1]
    abstand_gegen_kreis_ende_x_floor= ende_floor[0] - RADIUS, ende_floor[1]
    abstand_fuer_kreis_ende_y_floor = ende_floor[0] , ende_floor[1] + RADIUS
    abstand_gegen_kreis_ende_y_floor = ende_floor[0] , ende_floor[1] - RADIUS

    abstand_fuer_kreis_start_x_round= start_round[0] +RADIUS, start_round[1]
    abstand_gegen_kreis_start_x_round = start_round[0] -RADIUS, start_round[1]
    abstand_fuer_kreis_start_y_round = start_round[0], start_round[1] + RADIUS
    abstand_gegen_kreis_start_y_round = start_round[0], start_round[1] - RADIUS
    abstand_fuer_kreis_ende_x_round= ende_round[0] + RADIUS, ende_round[1]
    abstand_gegen_kreis_ende_x_round= ende_round[0] - RADIUS, ende_round[1]
    abstand_fuer_kreis_ende_y_round = ende_round[0] , ende_round[1] + RADIUS
    abstand_gegen_kreis_ende_y_round = ende_round[0] , ende_round[1] - RADIUS
    if(richtung0 != None and richtung0 != None):
        if (richtung0 != richtung1 and kreisel_verbunden ==1):
            if(
                (abstand_fuer_kreis_start_y_floor  == pos0_0_floor) or
                (abstand_fuer_kreis_start_y_floor  == pos0_1_floor) or
                (abstand_gegen_kreis_start_y_floor == pos0_0_floor) or
                (abstand_gegen_kreis_start_y_floor == pos0_1_floor) or
                (abstand_fuer_kreis_ende_y_floor   == pos0_0_floor) or
                (abstand_fuer_kreis_ende_y_floor   == pos0_1_floor) or
                (abstand_gegen_kreis_ende_y_floor  == pos0_0_floor) or
                (abstand_gegen_kreis_ende_y_floor  == pos0_1_floor) or
                (abstand_fuer_kreis_start_y_round  == pos0_0_round) or
                (abstand_fuer_kreis_start_y_round  == pos0_1_round) or
                (abstand_gegen_kreis_start_y_round == pos0_0_round) or
                (abstand_gegen_kreis_start_y_round == pos0_1_round) or
                (abstand_fuer_kreis_ende_y_round   == pos0_0_round) or
                (abstand_fuer_kreis_ende_y_round   == pos0_1_round) or
                (abstand_gegen_kreis_ende_y_round  == pos0_0_round) or
                (abstand_gegen_kreis_ende_y_round  == pos0_1_round) or

                (abstand_fuer_kreis_start_y_floor  == pos1_0_floor) or
                (abstand_fuer_kreis_start_y_floor  == pos1_1_floor) or
                (abstand_gegen_kreis_start_y_floor == pos1_0_floor) or
                (abstand_gegen_kreis_start_y_floor == pos1_1_floor) or
                (abstand_fuer_kreis_ende_y_floor   == pos1_0_floor) or
                (abstand_fuer_kreis_ende_y_floor   == pos1_1_floor) or
                (abstand_gegen_kreis_ende_y_floor  == pos1_0_floor) or
                (abstand_gegen_kreis_ende_y_floor  == pos1_1_floor) or

                (abstand_fuer_kreis_start_y_round  == pos1_0_round) or
                (abstand_fuer_kreis_start_y_round  == pos1_1_round) or
                (abstand_gegen_kreis_start_y_round == pos1_0_round) or
                (abstand_gegen_kreis_start_y_round == pos1_1_round) or
                (abstand_fuer_kreis_ende_y_round   == pos1_0_round) or
                (abstand_fuer_kreis_ende_y_round   == pos1_1_round) or
                (abstand_gegen_kreis_ende_y_round  == pos1_0_round) or
                (abstand_gegen_kreis_ende_y_round  == pos1_1_round)
            ):
                richtung2= "Vertikal"
                unterschiedlich = True

            else:
                richtung2 = "Horinzontal"
            unterschiedlich = True
            return richtung2, unterschiedlich
        return richtung2, unterschiedlich

    # vergleich mit einem kreisel von zwei
    if( (abstand_fuer_kreis_start_x_floor  == pos0_0_floor) or
            (abstand_fuer_kreis_start_x_floor  == pos0_1_floor) or
            (abstand_gegen_kreis_start_x_floor == pos0_0_floor) or
            (abstand_gegen_kreis_start_x_floor == pos0_1_floor) or
            (abstand_fuer_kreis_ende_x_floor   == pos0_0_floor) or
            (abstand_fuer_kreis_ende_x_floor   == pos0_1_floor) or
            (abstand_gegen_kreis_ende_x_floor  == pos0_0_floor) or
            (abstand_gegen_kreis_ende_x_floor  == pos0_1_floor) or
            (abstand_fuer_kreis_start_y_floor  == pos0_0_floor) or
            (abstand_fuer_kreis_start_y_floor  == pos0_1_floor) or
            (abstand_gegen_kreis_start_y_floor == pos0_0_floor) or
            (abstand_gegen_kreis_start_y_floor == pos0_1_floor) or
            (abstand_fuer_kreis_ende_y_floor   == pos0_0_floor) or
            (abstand_fuer_kreis_ende_y_floor   == pos0_1_floor) or
            (abstand_gegen_kreis_ende_y_floor  == pos0_0_floor) or
            (abstand_gegen_kreis_ende_y_floor  == pos0_1_floor) or
            (abstand_fuer_kreis_start_x_round  == pos0_0_round ) or
            (abstand_fuer_kreis_start_x_round  == pos0_1_round) or
            (abstand_gegen_kreis_start_x_round == pos0_0_round) or
            (abstand_gegen_kreis_start_x_round == pos0_1_round) or
            (abstand_fuer_kreis_ende_x_round   == pos0_0_round) or
            (abstand_fuer_kreis_ende_x_round   == pos0_1_round) or
            (abstand_gegen_kreis_ende_x_round  == pos0_0_round) or
            (abstand_gegen_kreis_ende_x_round  == pos0_1_round) or
            (abstand_fuer_kreis_start_y_round  == pos0_0_round) or
            (abstand_fuer_kreis_start_y_round  == pos0_1_round) or
            (abstand_gegen_kreis_start_y_round == pos0_0_round) or
            (abstand_gegen_kreis_start_y_round == pos0_1_round) or
            (abstand_fuer_kreis_ende_y_round   == pos0_0_round) or
            (abstand_fuer_kreis_ende_y_round   == pos0_1_round) or
            (abstand_gegen_kreis_ende_y_round  == pos0_0_round) or
            (abstand_gegen_kreis_ende_y_round  == pos0_1_round)
        ):
        kreisel_verbunden = kreisel_verbunden +1
            # setzung auf kreisel 1 für spätere ausrechnung der geraden form
        am_kreisel = 1
    if (x1_kreisel == None):
        return am_kreisel,kreisel_verbunden

    if( (abstand_fuer_kreis_start_x_floor  == pos1_0_floor )or
            (abstand_fuer_kreis_start_x_floor  == pos1_1_floor) or
            (abstand_gegen_kreis_start_x_floor == pos1_0_floor) or
            (abstand_gegen_kreis_start_x_floor == pos1_1_floor) or
            (abstand_fuer_kreis_ende_x_floor   == pos1_0_floor) or
            (abstand_fuer_kreis_ende_x_floor   == pos1_1_floor) or
            (abstand_gegen_kreis_ende_x_floor  == pos1_0_floor) or
            (abstand_gegen_kreis_ende_x_floor  == pos1_1_floor) or
            (abstand_fuer_kreis_start_y_floor  == pos1_0_floor ) or
            (abstand_fuer_kreis_start_y_floor  == pos1_1_floor) or
            (abstand_gegen_kreis_start_y_floor == pos1_0_floor) or
            (abstand_gegen_kreis_start_y_floor == pos1_1_floor) or
            (abstand_fuer_kreis_ende_y_floor   == pos1_0_floor ) or
            (abstand_fuer_kreis_ende_y_floor   == pos1_1_floor) or
            (abstand_gegen_kreis_ende_y_floor  == pos1_0_floor) or
            (abstand_gegen_kreis_ende_y_floor  == pos1_1_floor) or
            (abstand_fuer_kreis_start_x_round  == pos1_0_round ) or
            (abstand_fuer_kreis_start_x_round  == pos1_1_round) or
            (abstand_gegen_kreis_start_x_round == pos1_0_round) or
            (abstand_gegen_kreis_start_x_round == pos1_1_round) or
            (abstand_fuer_kreis_ende_x_round   == pos1_0_round) or
            (abstand_fuer_kreis_ende_x_round   == pos1_1_round) or
            (abstand_gegen_kreis_ende_x_round  == pos1_0_round) or
            (abstand_gegen_kreis_ende_x_round  == pos1_1_round) or
            (abstand_fuer_kreis_start_y_round  == pos1_0_round) or
            (abstand_fuer_kreis_start_y_round  == pos1_1_round) or
            (abstand_gegen_kreis_start_y_round == pos1_0_round) or
            (abstand_gegen_kreis_start_y_round == pos1_1_round) or
            (abstand_fuer_kreis_ende_y_round   == pos1_0_round) or
            (abstand_fuer_kreis_ende_y_round   == pos1_1_round) or
            (abstand_gegen_kreis_ende_y_round  == pos1_0_round) or
            (abstand_gegen_kreis_ende_y_round  == pos1_1_round)
        ):
            kreisel_verbunden = kreisel_verbunden +1
            am_kreisel = 2
    return am_kreisel,kreisel_verbunden