commit | author | age
|
d7639a
|
1 |
#include<stdlib.h> |
SP |
2 |
#include "general.h" |
a10dd5
|
3 |
#include "vertex.h" |
d7639a
|
4 |
|
a10dd5
|
5 |
ts_bond_list *init_bond_list(){ |
SP |
6 |
ts_bond_list *blist=(ts_bond_list *)malloc(sizeof(ts_bond_list)); |
d7639a
|
7 |
blist->n=0; |
SP |
8 |
blist->bond=NULL; |
a10dd5
|
9 |
return blist; |
d7639a
|
10 |
} |
SP |
11 |
|
a10dd5
|
12 |
ts_bond *bond_add(ts_bond_list *blist, ts_vertex *vtx1, ts_vertex *vtx2){ |
b01cc1
|
13 |
ts_uint i; |
a10dd5
|
14 |
/* no vertices must be null! */ |
SP |
15 |
if(vtx1==NULL || vtx2==NULL) return NULL; |
b01cc1
|
16 |
/* Verify if the bond already exists... Don't do multiple bonds */ |
SP |
17 |
for(i=0;i<blist->n;i++){ |
e016c4
|
18 |
if((blist->bond[i]->vtx1==vtx1 || blist->bond[i]->vtx1==vtx2) |
SP |
19 |
&&(blist->bond[i]->vtx2==vtx1 || blist->bond[i]->vtx2==vtx2)) |
b01cc1
|
20 |
return blist->bond[i]; |
SP |
21 |
} |
d7639a
|
22 |
blist->n++; |
a10dd5
|
23 |
blist->bond=(ts_bond **)realloc(blist->bond,blist->n*sizeof(ts_bond *)); |
SP |
24 |
if(blist->bond==NULL) fatal("Cannot reallocate memory for additional **ts_bond.",100); |
|
25 |
blist->bond[blist->n-1]=(ts_bond *)malloc(sizeof(ts_bond)); |
|
26 |
if(blist->bond[blist->n-1]==NULL) fatal("Cannot allocate memory for additional *ts_bond.",100); |
|
27 |
|
|
28 |
//NOW insert vertices into data! |
e016c4
|
29 |
blist->bond[blist->n - 1]->vtx1=vtx1; |
SP |
30 |
blist->bond[blist->n - 1]->vtx2=vtx2; |
a63f17
|
31 |
blist->bond[blist->n - 1]->tainted=0; |
a10dd5
|
32 |
//Should we calculate bond length NOW? |
SP |
33 |
|
|
34 |
return blist->bond[blist->n-1]; |
d7639a
|
35 |
} |
SP |
36 |
|
|
37 |
ts_bool bond_list_free(ts_bond_list *blist){ |
a10dd5
|
38 |
ts_uint i; |
SP |
39 |
for(i=0;i<blist->n;i++){ |
|
40 |
free(blist->bond[i]); |
|
41 |
} |
d7639a
|
42 |
free(blist->bond); |
a10dd5
|
43 |
free(blist); |
d7639a
|
44 |
return TS_SUCCESS; |
SP |
45 |
} |