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