From d33abe246221255be91bacda79f5852b8c4ed8fd Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Sun, 08 Dec 2013 17:47:21 +0000 Subject: [PATCH] Triangles are ordered in the bond now. Also kp and km are found as adjvtx. They are also ordered. --- src/vertex.c | 42 ++++++++++++++++++++++++++++++++---------- 1 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/vertex.c b/src/vertex.c index efe3cae..023e6fc 100644 --- a/src/vertex.c +++ b/src/vertex.c @@ -22,17 +22,20 @@ for(i=0;i<N;i++) { vlist->vtx[i]=(ts_vertex *)calloc(1,sizeof(ts_vertex)); vlist->vtx[i]->idx=i; + vlist->vtx[i]->neigh=init_vertex_list(0); /* initialize Ylm for spherical hamonics DONE in sh.c */ } vlist->n=N; - return vlist; + vlist->list_size=TS_VLIST_CHUNK; //TODO: can be buggy in some cases, when N>0 and we want to delete some vertices. + return vlist; } ts_bool vertex_list_add_vtx(ts_vertex_list *vlist, ts_vertex *vtx){ #ifdef DEBUG - if(vtx==NULL || vlist==NULL) return TS_FAIL; + if(vtx==NULL || vlist==NULL) + return TS_FAIL; #endif if(vlist->list_size < vlist->n+1){ vlist->vtx=(ts_vertex **)realloc(vlist->vtx, (vlist->list_size+TS_VLIST_CHUNK)*sizeof(ts_vertex*)); @@ -91,13 +94,29 @@ return TS_SUCCESS; } -ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex_list *vlist, ts_vertex *vtx1, ts_vertex *vtx2){ - ts_bool retval; - retval=vertex_list_add_vtx(vtx1->neigh, vtx2); - retval=vertex_list_add_vtx(vtx2->neigh, vtx1); - if(retval==TS_SUCCESS) - retval=vtx_add_bond(blist,vtx1,vtx2); +// Add neighbour just in one direction (add vtx2 as a neigh of vtx1 and not another way around! +ts_bool vtx_add_neighbour(ts_vertex *vtx1, ts_vertex *vtx2){ + ts_uint i; + if(vtx1==NULL || vtx2==NULL) return TS_FAIL; + for(i=0;i<vtx1->neigh->n;i++){ + if (vtx1->neigh->vtx[i]==vtx2){ + return TS_FAIL; + } + } + vertex_list_add_vtx(vtx1->neigh, vtx2); + return TS_SUCCESS; +} + +ts_bool vtx_add_cneighbour(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){ + ts_bool retval; + retval=vtx_add_neighbour(vtx1, vtx2); +// retval=vertex_list_add_vtx(vtx1->neigh, vtx2); +// retval=vertex_list_add_vtx(vtx2->neigh, vtx1); + if(retval==TS_SUCCESS){ + // fprintf(stderr,"Bond added\n"); + retval=vtx_add_bond(blist,vtx1,vtx2); + } return retval; } @@ -113,7 +132,10 @@ ts_bool vtx_free(ts_vertex *vtx){ - if(vtx->neigh!=NULL) free(vtx->neigh); + if(vtx->neigh!=NULL) { + if (vtx->neigh->vtx!=NULL) free(vtx->neigh->vtx); + free(vtx->neigh); + } if(vtx->tristar!=NULL) free(vtx->tristar); if(vtx->bond!=NULL) free(vtx->bond); free(vtx); @@ -209,7 +231,7 @@ ts_bool vtx_copy(ts_vertex *cvtx, ts_vertex *ovtx){ memcpy((void *)cvtx,(void *)ovtx,sizeof(ts_vertex)); - cvtx->neigh=NULL; + cvtx->neigh=init_vertex_list(0); cvtx->tristar_no=0; cvtx->bond_no=0; cvtx->tristar=NULL; -- Gitblit v1.9.3