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; |
3c1ac1
|
32 |
blist->bond[blist->n - 1]->idx=blist->n-1; |
a10dd5
|
33 |
//Should we calculate bond length NOW? |
SP |
34 |
|
|
35 |
return blist->bond[blist->n-1]; |
d7639a
|
36 |
} |
SP |
37 |
|
58230a
|
38 |
|
M |
39 |
ts_bool bond_vector(ts_bond *bond){ |
|
40 |
|
bcf455
|
41 |
bond->x = bond->vtx1->x - bond->vtx2->x; |
M |
42 |
bond->y = bond->vtx1->y - bond->vtx2->y; |
|
43 |
bond->z = bond->vtx1->z - bond->vtx2->z; |
58230a
|
44 |
|
M |
45 |
return TS_SUCCESS; |
|
46 |
} |
|
47 |
|
|
48 |
|
d7639a
|
49 |
ts_bool bond_list_free(ts_bond_list *blist){ |
a10dd5
|
50 |
ts_uint i; |
SP |
51 |
for(i=0;i<blist->n;i++){ |
|
52 |
free(blist->bond[i]); |
|
53 |
} |
d7639a
|
54 |
free(blist->bond); |
a10dd5
|
55 |
free(blist); |
d7639a
|
56 |
return TS_SUCCESS; |
SP |
57 |
} |