예제 #1
0
파일: area.py 프로젝트: ctogle/dilapidator
        def clear(b):
            b = tuple(dpr.inflate([bp.copy() for bp in b], 2))
            clr = True
            '''#
            if dpr.concaves_intersect(bnd,b):return False
            if not dpr.inconcave(b[0],bnd):return False
            for h in holes:
                if dpr.concaves_intersect(h,b):return False
                if dpr.inconcave(b[0],h):return False
            for p in prints:
                if dpr.concaves_intersect(p,b):return False
                if dpr.inconcave(b[0],p):return False
            '''#
            if dpr.concaves_intersect(bnd, b): clr = False
            if not dpr.inconcave_xy(b[0], bnd): clr = False
            for h in holes:
                if dpr.concaves_intersect(h, b): clr = False
                if dpr.inconcave_xy(b[0], h): clr = False
            for p in prints:
                if dpr.concaves_intersect(p, b): clr = False
                if dpr.inconcave_xy(b[0], p): clr = False

            #if not clr:
            if False:
                ax = dtl.plot_axes_xy()
                ax = dtl.plot_polygon_xy(list(bnd), ax, lw=1)
                ax = dtl.plot_polygon_xy(list(b), ax, lw=5)
                for h in holes:
                    ax = dtl.plot_polygon_xy(list(h), ax, lw=2)
                for p in prints:
                    ax = dtl.plot_polygon_xy(list(p), ax, lw=1)
                plt.show()

            #return True
            return clr
예제 #2
0
파일: tools.py 프로젝트: ctogle/dilapidator
def containment(py1,py2):
    if dpr.inconcave_xy(py1[0],py2):return  1
    if dpr.inconcave_xy(py2[0],py1):return -1
    print('CONTAINMENT IS SKETCHY')
    return 0

    raise NotImplemented
예제 #3
0
파일: area.py 프로젝트: ctogle/dilapidator
        def clear(b):
            b = tuple(dpr.inflate([bp.copy() for bp in b],2))
            clr = True
            '''#
            if dpr.concaves_intersect(bnd,b):return False
            if not dpr.inconcave(b[0],bnd):return False
            for h in holes:
                if dpr.concaves_intersect(h,b):return False
                if dpr.inconcave(b[0],h):return False
            for p in prints:
                if dpr.concaves_intersect(p,b):return False
                if dpr.inconcave(b[0],p):return False
            '''#
            if dpr.concaves_intersect(bnd,b):clr = False
            if not dpr.inconcave_xy(b[0],bnd):clr = False
            for h in holes:
                if dpr.concaves_intersect(h,b):clr = False
                if dpr.inconcave_xy(b[0],h):clr = False
            for p in prints:
                if dpr.concaves_intersect(p,b):clr = False
                if dpr.inconcave_xy(b[0],p):clr = False

            #if not clr:
            if False:
                ax = dtl.plot_axes_xy()
                ax = dtl.plot_polygon_xy(list(bnd),ax,lw = 1)
                ax = dtl.plot_polygon_xy(list(b),ax,lw = 5)
                for h in holes:
                    ax = dtl.plot_polygon_xy(list(h),ax,lw = 2)
                for p in prints:
                    ax = dtl.plot_polygon_xy(list(p),ax,lw = 1)
                plt.show()

            #return True
            return clr
예제 #4
0
파일: tools.py 프로젝트: ctogle/dilapidator
def containment(py1, py2):
    if dpr.inconcave_xy(py1[0], py2): return 1
    if dpr.inconcave_xy(py2[0], py1): return -1
    print('CONTAINMENT IS SKETCHY')
    return 0

    raise NotImplemented
예제 #5
0
파일: tools.py 프로젝트: ctogle/dilapidator
def break_polygons(p1,p2):
    p1segs = polygon_segments(p1)
    p2segs = polygon_segments(p2)
    isects = intersections(p1segs+p2segs)
    if len(isects) == 0:
        tpt1,tpt2 = p1segs[0][0],p2segs[0][0]
        p1inp2 = dpr.inconcave_xy(tpt1,p2[0])
        p2inp1 = dpr.inconcave_xy(tpt2,p1[0])
        if not (p1inp2 or p2inp1):
            return
    else:
        p1segs = break_segments(p1segs,isects)
        p2segs = break_segments(p2segs,isects)
    '''#
    ax = plot_axes_xy()
    plot_polygon_full_xy(p1,ax)
    plot_polygon_full_xy(p2,ax)
    for seg in p1segs:ax = plot_edges_xy(seg,ax,lw = 4.0)
    for seg in p2segs:ax = plot_edges_xy(seg,ax,lw = 4.0)
    plt.show()
    '''#
    return p1segs,p2segs
예제 #6
0
파일: tools.py 프로젝트: ctogle/dilapidator
def segments_outpolygon(segments,py):
    eb,ibs = py
    outpoly = []
    for x in range(len(segments)):
        i1,i2 = segments[x]
        eisect = False
        for ex in range(len(eb)):
            ep1,ep2 = eb[ex-1],eb[ex]
            isect = segments_intersect_at(i1,i2,ep1,ep2)
            if not isect is None:eisect = True 
        if not eisect and not dpr.inconcave_xy(dpv.midpoint(i1,i2),eb):
            outpoly.append((i1,i2))
    return outpoly
예제 #7
0
파일: tools.py 프로젝트: ctogle/dilapidator
def segments_outpolygon(segments, py):
    eb, ibs = py
    outpoly = []
    for x in range(len(segments)):
        i1, i2 = segments[x]
        eisect = False
        for ex in range(len(eb)):
            ep1, ep2 = eb[ex - 1], eb[ex]
            isect = segments_intersect_at(i1, i2, ep1, ep2)
            if not isect is None: eisect = True
        if not eisect and not dpr.inconcave_xy(dpv.midpoint(i1, i2), eb):
            outpoly.append((i1, i2))
    return outpoly
예제 #8
0
파일: tools.py 프로젝트: ctogle/dilapidator
def break_polygons(p1, p2):
    p1segs = polygon_segments(p1)
    p2segs = polygon_segments(p2)
    isects = intersections(p1segs + p2segs)
    if len(isects) == 0:
        tpt1, tpt2 = p1segs[0][0], p2segs[0][0]
        p1inp2 = dpr.inconcave_xy(tpt1, p2[0])
        p2inp1 = dpr.inconcave_xy(tpt2, p1[0])
        if not (p1inp2 or p2inp1):
            return
    else:
        p1segs = break_segments(p1segs, isects)
        p2segs = break_segments(p2segs, isects)
    '''#
    ax = plot_axes_xy()
    plot_polygon_full_xy(p1,ax)
    plot_polygon_full_xy(p2,ax)
    for seg in p1segs:ax = plot_edges_xy(seg,ax,lw = 4.0)
    for seg in p2segs:ax = plot_edges_xy(seg,ax,lw = 4.0)
    plt.show()
    '''#
    return p1segs, p2segs
예제 #9
0
def clean_polygon(eb,ibs):
    clean = False
    neb = eb[:]
    #nibs = [ib[:] for ib in ibs]

    flag = False

    while not clean:
        icnt = len(ibs)
        nibs = []
        if icnt == 0:clean = True
        else:
            for x in range(icnt):
                ib = ibs[x]
                isect = dpr.concaves_intersect(neb,ib)
                ins = dpr.inconcave_xy(ib[0],neb)
                if isect:
                    neb = dtl.polygon_difference((neb,()),(ib,()))[0]

                    print('polygon hole intersects boundary',x)
                    ax = dtl.plot_axes()
                    ax = dtl.plot_polygon_full((neb,()),ax)
                    plt.show()
                    flag = True

                    break
                elif ins:nibs.append(ib)
                else:print('polygon hole found outside of boundary',x)

                print('wtf',x,icnt)

                if x == icnt - 1:clean = True

    if flag:
        tns = [dpv.distance(neb[t-1],neb[t]) for t in range(len(neb))]
        print('exit CLEANPOLYGON',tns)
        ax = dtl.plot_axes()
        ax = dtl.plot_polygon_full((neb,nibs),ax)
        plt.show()

    return neb,nibs
예제 #10
0
    def _rank_edge_loops(self,eloops):
        bedgeloops = {}

        #ax = dtl.plot_axes_xy()
        #ax = self.plot_xy(ax)
        #for bedge in eloops:ax = dtl.plot_edges_xy(bedge,ax)
        #plt.show()

        containments = [[] for el in eloops]
        for elx in range(len(eloops)):
            elp = tuple(eloops[elx])
            for elxo in range(len(eloops)):
                if elxo == elx:continue
                elpo = tuple(eloops[elxo])
                isect = dpr.concaves_intersect(elp,elpo)
                elins = dpr.inconcave_xy(elpo[0],elp)
                if isect:raise ValueError
                elif elins:containments[elx].append(elxo)
        looplook = {'king':[],'interiors':[]}
        for elx in range(len(eloops)):
            cont = containments[elx]
            if cont:looplook['king'].append(eloops[elx])
            else:looplook['interiors'].append(eloops[elx])
        return looplook
예제 #11
0
파일: tools.py 프로젝트: ctogle/dilapidator
def line_intersects_polygon_at(l1,l2,py,intins):
    eb,ibs = py

    ltn = dpv.v1_v2(l1,l2).normalize()
    pyprj = dpv.project_coords(list(eb),ltn)
    midpt = dpv.midpoint(l1,l2)
    mpprj = dpv.dot(midpt,ltn)
    offst = mpprj-((pyprj.x+pyprj.y)/2.0)
    l1del = ltn.copy().scale_u(offst+100)
    l2del = ltn.copy().scale_u(offst-100)
    l1far = midpt.copy().translate(l1del)
    l2far = midpt.copy().translate(l2del)
    pysegs = polygon_segments(py)
    lnsegs = [(l1far,l2far)]

    prot = prot_to_xy(py)

    '''#
    print('before you rotate!!',prot.__str__())
    ax = plot_axes()
    for p in pysegs:plot_edges(p,ax)
    plot_edges(lnsegs[-1],ax,lw = 5.0)
    #for p in isects:plot_point(p,ax)
    #for p in isects2:plot_point(p,ax,marker = 's')
    plt.show()
    print('AMEN')
    '''#

    dpr.rotate_segments(pysegs,prot)
    dpr.rotate_coords(list(lnsegs[0]),prot)
    isects = intersections(pysegs+lnsegs)
    #isects = [x for x in isects if dpr.orient3d(eb[0],eb[1],eb[2],x) == 0]

    if len(isects) == 1:
      print('while you were rotated!!')
      ax = plot_axes()
      for p in pysegs:plot_edges(p,ax)
      plot_edges(lnsegs[-1],ax,lw = 5.0)
      for p in isects:plot_point(p,ax)
      #for p in isects2:plot_point(p,ax,marker = 's')
      plt.show()
      print('AMEN.5',len(isects))

    if len(isects) == 0:
        prot.flip()
        dpr.rotate_segments(pysegs,prot)
        dpr.rotate_coords(list(lnsegs[0]),prot)
        dpv.rotate_coords(isects,prot)
        return
    else:
        #print('actuallyinsssssisects',isects)
        actuallyintins = dpr.inconcave_xy(dpv.midpoint(*isects),eb)

        '''#
        print('wattttch',actuallyintins)
        ax = plot_axes()
        plot_polygon(list(eb),ax)
        plot_edges(isects,ax,lw = 4.0)
        plt.show()
        '''#

        prot.flip()
        dpr.rotate_segments(pysegs,prot)
        dpr.rotate_coords(list(lnsegs[0]),prot)
        dpv.rotate_coords(isects,prot)
        if intins and not actuallyintins:return

        if len(isects) == 1:
          print('after you rotate!!')
          ax = plot_axes()
          for p in pysegs:plot_edges(p,ax)
          plot_edges(lnsegs[-1],ax,lw = 5.0)
          for p in isects:plot_point(p,ax)
          #for p in isects2:plot_point(p,ax,marker = 's')
          plt.show()
          print('AMEN2',len(isects))

        #ebn = dpr.polygon_normal(eb)
        #pyj = dpv.project_coords(list(eb),ebn)
        #isects2 = [x for x in isects if dpr.isnear(dpv.dot(x,ebn),pyj.x)]
        #isects2 = [x for x in isects if dpr.orient3d(eb[0],eb[1],eb[2],x) == 0]

        #if intins and not dpr.inconcave_xy(dpv.midpoint(*isects),eb):return
        #intins = dpr.inconcave_xy(dpv.midpoint(*isects),eb)
        #if not intins:return

        '''#
        print('breakin some shit!!',intins)
        ax = plot_axes()
        for p in pysegs:plot_edges(p,ax)
        plot_edges(lnsegs[-1],ax,lw = 5.0)
        for p in isects:plot_point(p,ax)
        #for p in isects2:plot_point(p,ax,marker = 's')
        plt.show()
        '''#

        return isects
예제 #12
0
파일: tools.py 프로젝트: ctogle/dilapidator
def line_intersects_polygon_at(l1, l2, py, intins):
    eb, ibs = py

    ltn = dpv.v1_v2(l1, l2).normalize()
    pyprj = dpv.project_coords(list(eb), ltn)
    midpt = dpv.midpoint(l1, l2)
    mpprj = dpv.dot(midpt, ltn)
    offst = mpprj - ((pyprj.x + pyprj.y) / 2.0)
    l1del = ltn.copy().scale_u(offst + 100)
    l2del = ltn.copy().scale_u(offst - 100)
    l1far = midpt.copy().translate(l1del)
    l2far = midpt.copy().translate(l2del)
    pysegs = polygon_segments(py)
    lnsegs = [(l1far, l2far)]

    prot = prot_to_xy(py)

    '''#
    print('before you rotate!!',prot.__str__())
    ax = plot_axes()
    for p in pysegs:plot_edges(p,ax)
    plot_edges(lnsegs[-1],ax,lw = 5.0)
    #for p in isects:plot_point(p,ax)
    #for p in isects2:plot_point(p,ax,marker = 's')
    plt.show()
    print('AMEN')
    '''#

    dpr.rotate_segments(pysegs, prot)
    dpr.rotate_coords(list(lnsegs[0]), prot)
    isects = intersections(pysegs + lnsegs)
    #isects = [x for x in isects if dpr.orient3d(eb[0],eb[1],eb[2],x) == 0]

    if len(isects) == 1:
        print('while you were rotated!!')
        ax = plot_axes()
        for p in pysegs:
            plot_edges(p, ax)
        plot_edges(lnsegs[-1], ax, lw=5.0)
        for p in isects:
            plot_point(p, ax)
        #for p in isects2:plot_point(p,ax,marker = 's')
        plt.show()
        print('AMEN.5', len(isects))

    if len(isects) == 0:
        prot.flip()
        dpr.rotate_segments(pysegs, prot)
        dpr.rotate_coords(list(lnsegs[0]), prot)
        dpv.rotate_coords(isects, prot)
        return
    else:
        #print('actuallyinsssssisects',isects)
        actuallyintins = dpr.inconcave_xy(dpv.midpoint(*isects), eb)

        '''#
        print('wattttch',actuallyintins)
        ax = plot_axes()
        plot_polygon(list(eb),ax)
        plot_edges(isects,ax,lw = 4.0)
        plt.show()
        '''#

        prot.flip()
        dpr.rotate_segments(pysegs, prot)
        dpr.rotate_coords(list(lnsegs[0]), prot)
        dpv.rotate_coords(isects, prot)
        if intins and not actuallyintins: return

        if len(isects) == 1:
            print('after you rotate!!')
            ax = plot_axes()
            for p in pysegs:
                plot_edges(p, ax)
            plot_edges(lnsegs[-1], ax, lw=5.0)
            for p in isects:
                plot_point(p, ax)
            #for p in isects2:plot_point(p,ax,marker = 's')
            plt.show()
            print('AMEN2', len(isects))

        #ebn = dpr.polygon_normal(eb)
        #pyj = dpv.project_coords(list(eb),ebn)
        #isects2 = [x for x in isects if dpr.isnear(dpv.dot(x,ebn),pyj.x)]
        #isects2 = [x for x in isects if dpr.orient3d(eb[0],eb[1],eb[2],x) == 0]

        #if intins and not dpr.inconcave_xy(dpv.midpoint(*isects),eb):return
        #intins = dpr.inconcave_xy(dpv.midpoint(*isects),eb)
        #if not intins:return

        '''#
        print('breakin some shit!!',intins)
        ax = plot_axes()
        for p in pysegs:plot_edges(p,ax)
        plot_edges(lnsegs[-1],ax,lw = 5.0)
        for p in isects:plot_point(p,ax)
        #for p in isects2:plot_point(p,ax,marker = 's')
        plt.show()
        '''#

        return isects