Exemple #1
0
def test_adjacent_nodes_dim1():
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0] ]
    for pnt in pnts:
        dt.add_node( x=pnt )

    assert np.all( dt.topo_sort_adjacent_nodes(1,ref_nbr=0)==[0,2] )
Exemple #2
0
 def init():
     # inserting a constraint
     dt = Triangulation()
     pnts = [ [0,0],
              [5,0],
              [10,0],
              [5,5],
              [3,0],
              [6,2],
              [12,4]]
     for pnt in pnts:
         dt.add_node( x=pnt )
     return dt
Exemple #3
0
def test_constraints_dim1():
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0] ]
    for pnt in pnts:
        dt.add_node( x=pnt )

    dt.add_constraint(0,1)
    dt.add_constraint(1,2)
    dt.remove_constraint(0,1)
    dt.remove_constraint(1,2)
    try:
        dt.add_constraint(0,2)
        assert False
    except dt.ConstraintCollinearNode:
        pass # 
Exemple #4
0
def test_test_dim_down():
    dt = Triangulation()

    n=dt.add_node( x=[0,0] )

    for i in range(5):
        other=dt.add_node( x=[10,i] )

    assert dt.test_delete_node_dim_down(n)
    assert not dt.test_delete_node_dim_down(other)

    friend=dt.add_node( x=[0,2])
    assert not dt.test_delete_node_dim_down(friend)
    assert not dt.test_delete_node_dim_down(n)
Exemple #5
0
def test_find_int_elts_dim1():
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0] ]
    for pnt in pnts:
        dt.add_node( x=pnt )

    assert len(dt.find_intersected_elements(0,1))==2
    assert len(dt.find_intersected_elements(0,2))==3
    assert len(dt.find_intersected_elements(1,2))==2
Exemple #6
0
def test_move1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear

    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    n=dt.add_node( x=[6,2] ) # into cell interior

    dt.modify_node(4,x=[3.01,0.25])

    dt.modify_node(4,x=[3.01,-0.25])
    if plot:
        plt.clf()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    dt.check_global_delaunay()
    return dt
Exemple #7
0
def test_extra1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear

    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)

    n=dt.add_node( x=[6,2] ) # into cell interior

    if plot:
        plt.clf()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #8
0
def test_fuzz1():
    plot=False
    # Fuzzing, regular
    x=np.arange(5)
    y=np.arange(5)

    X,Y=np.meshgrid(x,y)
    xys=np.array([X.ravel(),Y.ravel()]).T

    if plot:
        plt.figure(1).clf()
        fig,ax=plt.subplots(num=1)

        ax.plot(xys[:,0],xys[:,1],'go',alpha=0.4)
        ax.axis([-1,5,-1,5])

    idxs=np.zeros(len(xys),'i8')-1

    dt = Triangulation()

    # definitely slows down as the number of nodes gets larger.
    # starting off with <1s per 100 operations, later more like 2s
    for repeat in range(1):
        print "Repeat: ",repeat
        for step in range(1000):
            if step%200==0:
                print "  step: ",step
            toggle=np.random.randint(len(idxs))
            if idxs[toggle]<0:
                idxs[toggle] = dt.add_node( x=xys[toggle] )
            else:
                dt.delete_node(idxs[toggle])
                idxs[toggle]=-1

            if plot:
                del ax.lines[1:]
                ax.texts=[]
                ax.collections=[]
                dt.plot_nodes(labeler=lambda n,nrec: str(n) )
                dt.plot_edges(alpha=0.5,lw=2)
                dt.plot_cells(lw=7,facecolor='#ddddff',edgecolor='w',zorder=-5)
                plt.draw()
Exemple #9
0
def test_lowdim1():
    plot=False
    dt = Triangulation()

    dt.add_node( x=[0,0] )
    dt.add_node( x=[5,0] )
    dt.add_node( x=[10,0] )
    dt.add_node( x=[-2,3] )
    dt.add_node( x=[-2,-3] )
    
    # and now delete the one in the middle:
    dt.delete_node(1)
    dt.delete_node(0)
    dt.delete_node(2)
    dt.delete_node(3)
    dt.delete_node(4)
    
    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=7,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #10
0
def test_flip2():
    plot=False
    # testing Delaunay flipping
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(10):
        dt.add_node( x=[10,i] )

    dt.add_node( x=[5,1.0] ) 

    dt.add_node( x=[10,10] ) 
    dt.add_node( x=[5,2] )
    
    # and test a flip when the new vertex is outside the convex hull
    dt.add_node( x=[5,-1])

    dt.delete_node(11)

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nrec: str(n) )
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #11
0
def test_delete3():
    plot=False
    dt = Triangulation()

    nodes=[ dt.add_node( x=[10,i] )
            for i in range(10) ]

    dt.delete_node( nodes[0])
    dt.delete_node( nodes[4])
    if plot:
        plt.cla()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #12
0
def test_delete2():
    plot=False
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(5):
        if 0: # sparser nodes for testing
            if i>0 and i<4:
                continue
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    
    far=dt.add_node( x=[12,4] ) 

    dt.delete_node(0) 
    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=6,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #13
0
def test_delete1():
    plot=False
    dt = Triangulation() # ExactDelaunay()

    dt.add_node( x=[0,0] )
    for i in range(5):
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    # deleting n work okay
    dt.delete_node(n)

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    # delete a node which defines part of the convex hull:
    dt.delete_node(5) # works, though may need to patch up edges['cells'] ?
    dt.delete_node(2) # collinear portion of the convex hull
    dt.delete_node(3)

    # everything looks okay.  Surprising that we didn't have to
    # add code to deal with this case...

    if plot:
        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)

    dt.delete_node(0)

    if plot:
        assert dt.dim() == 1

        plt.cla()
        dt.plot_nodes(labeler=lambda n,nr:str(n))
        dt.plot_edges(alpha=0.5,lw=2)

        bad=(~dt.cells['deleted'])&(dt.cells_area()<=0)
        good=(~dt.cells['deleted'])&(dt.cells_area()>0)
        dt.plot_cells(lw=8,facecolor='#ddddff',edgecolor='w',zorder=-5,mask=good)
        dt.plot_cells(lw=8,facecolor='#ffdddd',edgecolor='r',zorder=-5,mask=bad)
Exemple #14
0
def test_flip2():
    plot=False
    dt = Triangulation()

    dt.add_node( x=[0,0] )
    for i in range(5):
        dt.add_node( x=[10,i] )
    # This one requires a flip:
    n=dt.add_node( x=[5,1] )
    
    if plot:
        plt.cla()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #15
0
def test_flip1():
    plot=False
    dt = Triangulation()
    pnts = [ [0,0],
             [8,0],
             [10,5],
             [5,5] ]

    dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear
    if plot:
        plt.clf()
        dt.plot_nodes()
        dt.plot_edges(alpha=0.5,lw=2)
        dt.plot_cells(lw=13,facecolor='#ddddff',edgecolor='w',zorder=-5)
Exemple #16
0
def test_find_intersected_elements():
    dt = Triangulation()
    pnts = [ [0,0],
             [5,0],
             [10,0],
             [5,5] ]

    nA=dt.add_node( x=pnts[0] ) # This tests insert into empty
    dt.add_node( x=pnts[1] ) # adjacent_vertex
    dt.add_node( x=pnts[2] ) # adjacent_vertex
    dt.add_node( x=pnts[3] ) # adjacent_edge

    dt.add_node( x=[3,0] ) # colinear

    dt.add_node( x=[6,2] ) # into cell interior
    nB=dt.add_node( x=[12,4] ) # collinear cell interior
    
    nodes=list(dt.valid_node_iter())

    for iA in range(len(nodes)):
        for iB in range(iA+1,len(nodes)):
            nA=nodes[iA]
            nB=nodes[iB]
            fwd=dt.find_intersected_elements(nA,nB)
            rev=dt.find_intersected_elements(nB,nA)
            assert len(fwd) == len(rev)