commit | author | age
|
d7639a
|
1 |
#include<stdlib.h> |
SP |
2 |
#include<math.h> |
|
3 |
#include<string.h> |
|
4 |
#include "general.h" |
|
5 |
#include "vertex.h" |
|
6 |
#include<stdio.h> |
|
7 |
|
|
8 |
/* Argument je struktura vlist in stevilo vertexov, ki jih zelimo dati v |
|
9 |
* vlist je lahko NULL, N mora biti vecje od 0. Ce vlist obstaja, potem resizamo |
|
10 |
* vlist na stevilo N. |
|
11 |
*/ |
|
12 |
ts_vertex **init_vertex_list(ts_uint N){ |
|
13 |
ts_int i; |
|
14 |
ts_vertex **vlist; |
|
15 |
if(N==0){ |
|
16 |
err("Initialized vertex list with zero elements. Pointer set to NULL"); |
|
17 |
vlist=NULL; |
|
18 |
return NULL; |
|
19 |
} |
|
20 |
vlist=(ts_vertex **)malloc(N*sizeof(ts_vertex *)); |
|
21 |
if(vlist==NULL) |
|
22 |
fatal("Fatal error reserving memory space for vertex list! Could number of requsted vertices be too large?", 100); |
|
23 |
|
|
24 |
for(i=0;i<N;i++){ |
|
25 |
vlist[i]=init_vertex(i); |
|
26 |
} |
|
27 |
return vlist; |
|
28 |
} |
|
29 |
|
|
30 |
ts_vertex *init_vertex(ts_uint idx){ |
|
31 |
ts_vertex *vtx; |
|
32 |
vtx=(ts_vertex *)malloc(sizeof(ts_vertex)); |
|
33 |
if(vtx==NULL) |
|
34 |
fatal("Fatal error reserving memory space for ts_vertex! Memory full?", 100); |
|
35 |
vtx->idx=idx; |
|
36 |
return vtx; |
|
37 |
} |
|
38 |
|
|
39 |
/* |
|
40 |
ts_bool vtx_set_global_values(ts_vertex **vlist, ts_vesicle *vesicle){ |
|
41 |
ts_double xk=vesicle->bending_rigidity; |
|
42 |
ts_uint i; |
|
43 |
for(i=0;i<vesicle->vlist.n;i++){ |
|
44 |
vlist[i]->xk=xk; |
|
45 |
} |
|
46 |
return TS_SUCCESS; |
|
47 |
} |
|
48 |
*/ |
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
ts_bool vtx_add_neighbour(ts_vertex **vtx, ts_vertex **nvtx){ |
|
53 |
ts_uint i; |
|
54 |
/* no neighbour can be null! */ |
|
55 |
if(vtx==NULL || nvtx==NULL) return TS_FAIL; |
|
56 |
|
|
57 |
/*if it is already a neighbour don't add it to the list */ |
|
58 |
for(i=0; i<(*vtx)->neigh_no;i++){ |
|
59 |
if((*vtx)->neigh[i]==nvtx) return TS_FAIL; |
|
60 |
} |
|
61 |
ts_uint nn=(*vtx)->neigh_no++; |
|
62 |
(*vtx)->neigh=(ts_vertex ***)realloc((*vtx)->neigh, nn*sizeof(ts_vertex **)); |
|
63 |
(*vtx)->neigh[nn]=nvtx; |
|
64 |
|
|
65 |
/* pa se sosedu dodamo vertex */ |
|
66 |
/*if it is already a neighbour don't add it to the list */ |
|
67 |
for(i=0; i<(*nvtx)->neigh_no;i++){ |
|
68 |
if((*nvtx)->neigh[i]==vtx) return TS_FAIL; |
|
69 |
} |
|
70 |
nn=(*nvtx)->neigh_no++; |
|
71 |
(*nvtx)->neigh=(ts_vertex ***)realloc((*nvtx)->neigh, nn*sizeof(ts_vertex **)); |
|
72 |
(*nvtx)->neigh[nn]=vtx; |
|
73 |
|
|
74 |
|
|
75 |
/* Ustvari bond in doloci dolzino */ |
|
76 |
|
|
77 |
return TS_SUCCESS; |
|
78 |
} |
|
79 |
|
|
80 |
|
|
81 |
ts_bool vtx_free(ts_vertex **vtx){ |
|
82 |
if((*vtx)->neigh!=NULL) free((*vtx)->neigh); |
|
83 |
if((*vtx)->tristar!=NULL) free((*vtx)->tristar); |
|
84 |
if((*vtx)->bond!=NULL) free((*vtx)->bond); |
|
85 |
if((*vtx)->cell!=NULL) free((*vtx)->cell); |
|
86 |
free(*vtx); |
|
87 |
return TS_SUCCESS; |
|
88 |
} |
|
89 |
|
|
90 |
|
|
91 |
inline ts_double vertex_distance_sq(ts_vertex **vtx1, ts_vertex **vtx2){ |
|
92 |
ts_double dist; |
|
93 |
#ifdef TS_DOUBLE_DOUBLE |
|
94 |
dist=pow((*vtx1)->x-(*vtx2)->x,2) + pow((*vtx1)->y-(*vtx2)->y,2) + pow((*vtx1)->z-(*vtx2)->z,2); |
|
95 |
#endif |
|
96 |
#ifdef TS_DOUBLE_LONGDOUBLE |
|
97 |
dist=powl((*vtx1)->x-(*vtx2)->x,2) + powl((*vtx1)->y-(*vtx2)->y,2) + powl((*vtx1)->z-(*vtx2)->z,2); |
|
98 |
#endif |
|
99 |
#ifdef TS_DOUBLE_FLOAT |
|
100 |
dist=powf((*vtx1)->x-(*vtx2)->x,2) + powf((*vtx1)->y-(*vtx2)->y,2) + powf((*vtx1)->z-(*vtx2)->z,2); |
|
101 |
#endif |
|
102 |
return(dist); |
|
103 |
} |
|
104 |
|