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? |
d335d9
|
33 |
|
SP |
34 |
|
|
35 |
|
a10dd5
|
36 |
|
SP |
37 |
return blist->bond[blist->n-1]; |
d7639a
|
38 |
} |
SP |
39 |
|
d335d9
|
40 |
|
SP |
41 |
/* Two triangles are assigned to the bond. Bond must already be initialized. */ |
|
42 |
ts_bool bond_assign_triangles(ts_bond *bond){ |
|
43 |
ts_vertex *vtx1=bond->vtx1, *vtx2=bond->vtx2; |
|
44 |
ts_uint i,j,k; |
|
45 |
|
|
46 |
for(i=0,k=0;i<vtx1->tristar_no;i++){ |
|
47 |
for(j=0;j<3;j++){ |
|
48 |
if(vtx1->tristar[i]->vertex[j]==vtx2){ |
|
49 |
//triangle found; |
|
50 |
bond->tria[k]=vtx1->tristar[i]; |
|
51 |
k++; |
|
52 |
} |
|
53 |
} |
|
54 |
} |
|
55 |
if(k<2) return TS_FAIL; |
|
56 |
else return TS_SUCCESS; |
|
57 |
} |
|
58 |
|
d7639a
|
59 |
ts_bool bond_list_free(ts_bond_list *blist){ |
a10dd5
|
60 |
ts_uint i; |
SP |
61 |
for(i=0;i<blist->n;i++){ |
|
62 |
free(blist->bond[i]); |
|
63 |
} |
d7639a
|
64 |
free(blist->bond); |
a10dd5
|
65 |
free(blist); |
d7639a
|
66 |
return TS_SUCCESS; |
SP |
67 |
} |