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){ |
SP |
13 |
|
|
14 |
/* no vertices must be null! */ |
|
15 |
if(vtx1==NULL || vtx2==NULL) return NULL; |
|
16 |
/* TODO: Verify if the bond already exists... Don't do multiple bonds */ |
d7639a
|
17 |
blist->n++; |
a10dd5
|
18 |
blist->bond=(ts_bond **)realloc(blist->bond,blist->n*sizeof(ts_bond *)); |
SP |
19 |
if(blist->bond==NULL) fatal("Cannot reallocate memory for additional **ts_bond.",100); |
|
20 |
blist->bond[blist->n-1]=(ts_bond *)malloc(sizeof(ts_bond)); |
|
21 |
if(blist->bond[blist->n-1]==NULL) fatal("Cannot allocate memory for additional *ts_bond.",100); |
|
22 |
blist->bond[blist->n-1]->data=(ts_bond_data *)malloc(sizeof(ts_bond_data)); |
|
23 |
|
|
24 |
//NOW insert vertices into data! |
|
25 |
blist->bond[blist->n - 1]->data->vtx1=vtx1; |
|
26 |
blist->bond[blist->n - 1]->data->vtx2=vtx2; |
|
27 |
|
|
28 |
//Should we calculate bond length NOW? |
|
29 |
|
|
30 |
return blist->bond[blist->n-1]; |
d7639a
|
31 |
} |
SP |
32 |
|
|
33 |
ts_bool bond_list_free(ts_bond_list *blist){ |
a10dd5
|
34 |
ts_uint i; |
SP |
35 |
for(i=0;i<blist->n;i++){ |
|
36 |
free(blist->bond[i]->data); |
|
37 |
free(blist->bond[i]); |
|
38 |
} |
d7639a
|
39 |
free(blist->bond); |
a10dd5
|
40 |
free(blist); |
d7639a
|
41 |
return TS_SUCCESS; |
SP |
42 |
} |