| | |
| | | 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*)); |
| | |
| | | return TS_SUCCESS; |
| | | } |
| | | |
| | | |
| | | // 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){ |
| | | vertex_list_add_vtx(vtx1->neigh, vtx2); |
| | | vertex_list_add_vtx(vtx2->neigh, vtx1); |
| | | 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=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); |
| | | |
| | | 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; |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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; |