-
Notifications
You must be signed in to change notification settings - Fork 0
/
pasuli_macros.h
executable file
·336 lines (299 loc) · 8.28 KB
/
pasuli_macros.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#ifndef __PASULI_MACRO_DEFINITIONS__
#define __PASULI_MACRO_DEFINITIONS__
#include "pasuli_cfg.h"
#if (USE_ID_IN_PASULI_FUNCTION != 0)
#define PASULI_SET_TYPE_ID(X) pO->_ID = X;
#else
#define PASULI_SET_TYPE_ID(X)
#endif
#define PASULI_USE_NORMAL_BY_CROSS_PRODUCT 1
#define PASULI_CALC_SIGN(F) ((F < 0) ? -1 : (F > 0 ? 1 : 0))
// Or 2*cos(v)^2-1
#define PASULI_TRIG_CALC_SUM_DIFFERENCE(C, S) (C * C - S * S)
// cos(x)^4 = 1/8 (cos 4x + 4 cos 2x + 3)
#define PASULI_TRIG_CALC_COS_POW_4(COS_VALUE, VAL) (pow(COS_VALUE, 4))
// sin(x)^4 = 1/8 (cos 4x - 4 cos 2x + 3)
#define PASULI_TRIG_CALC_SIN_POW_4(SIN_VALUE, VAL) (pow(SIN_VALUE, 4))
// 1/4 (3 cos x + cos 3x)
#define PASULI_TRIG_COS_POW3(COS_VALUE, V) ((3 * COS_VALUE + cos(3 * V)) * 0.25)
// 1/4 (3 sin x - sin 3x)
#define PASULI_TRIG_SIN_POW3(SIN_VALUE, V) ((3 * SIN_VALUE - sin(3 * V)) * 0.25)
// Position macros
#if (PASULIOBJECT_POS != 0)
#define P_X(V) pO->pos[0] = V
#define P_Y(V) pO->pos[1] = V
#define P_Z(V) pO->pos[2] = V
#define POS_OP(O) O
#else
#define P_X(V)
#define P_Y(V)
#define P_Z(V)
#define POS_OP(O)
#endif
// Macros for derivative with respect to U
#if (PASULIOBJECT_UD != 0)
#define UD_X(V) \
pasuli_calctype xu = (V); \
pO->ud[0] = xu
#define UD_Y(V) \
pasuli_calctype yu = (V); \
pO->ud[1] = yu
#define UD_Z(V) \
pasuli_calctype zu = (V); \
pO->ud[2] = zu
#define UD_OP(O) O
#else
#if (PASULI_USE_NORMAL_BY_CROSS_PRODUCT != 0)
#define UD_X(V) pasuli_calctype xu = (V)
#define UD_Y(V) pasuli_calctype yu = (V)
#define UD_Z(V) pasuli_calctype zu = (V)
#define UD_OP(O) O
#else
#define UD_X(V)
#define UD_Y(V)
#define UD_Z(V)
#define UD_OP(O)
#endif
#endif
// Macros for derivative for V
#if (PASULIOBJECT_VD != 0)
#define VD_X(V) \
pasuli_calctype xv = (V); \
pO->vd[0] = xv
#define VD_Y(V) \
pasuli_calctype yv = (V); \
pO->vd[1] = yv
#define VD_Z(V) \
pasuli_calctype zv = (V); \
pO->vd[2] = zv
#define VD_OP(O) O
#else
#if (PASULI_USE_NORMAL_BY_CROSS_PRODUCT != 0)
#define VD_X(V) pasuli_calctype xv = (V)
#define VD_Y(V) pasuli_calctype yv = (V)
#define VD_Z(V) pasuli_calctype zv = (V)
#define VD_OP(O) O
#else
#define VD_X(V)
#define VD_Y(V)
#define VD_Z(V)
#define VD_OP(O)
#endif
#endif
// Macros for Normal vector
#if (PASULIOBJECT_N != 0)
#define N_X(V) pO->n[0] = (V)
#define N_Y(V) pO->n[1] = (V)
#define N_Z(V) pO->n[2] = (V)
#define NORMAL_OP(O) O
#else
#define N_X(V)
#define N_Y(V)
#define N_Z(V)
#define NORMAL_OP(O)
#endif
#define MULTIPLY_NORMAL_BY_MINUS_ONE \
pO->n[0] = -pO->n[0]; \
pO->n[1] = -pO->n[1]; \
pO->n[2] = -pO->n[2];
// Macros for 2.nd derivative with respect to U
#if (PASULIOBJECT_UUD != 0)
#define UUD_X(V) pO->uud[0] = V
#define UUD_Y(V) pO->uud[1] = V
#define UUD_Z(V) pO->uud[2] = V
#define UUD_ALL(V) \
pO->uud[0] = V; \
pO->uud[1] = V; \
pO->uud[2] = V
#define UUD_OP(O) O
#else
#define UUD_X(V)
#define UUD_Y(V)
#define UUD_Z(V)
#define UUD_ALL(V)
#define UUD_OP(O)
#endif
// Macros for 2.nd derivative with respect to U and V
#if (PASULIOBJECT_UVD != 0)
#define UVD_X(V) pO->uvd[0] = V
#define UVD_Y(V) pO->uvd[1] = V
#define UVD_Z(V) pO->uvd[2] = V
#define UVD_ALL(V) \
pO->uvd[0] = V; \
pO->uvd[1] = V; \
pO->uvd[2] = V;
#define UVD_OP(O) O
#else
#define UVD_X(V)
#define UVD_Y(V)
#define UVD_Z(V)
#define UVD_ALL(V)
#define UVD_OP(O)
#endif
// Macros for 2.nd derivative with respect to V
#if (PASULIOBJECT_VVD != 0)
#define VVD_X(V) pO->vvd[0] = V
#define VVD_Y(V) pO->vvd[1] = V
#define VVD_Z(V) pO->vvd[2] = V
#define VVD_ALL(V) \
pO->vvd[0] = V; \
pO->vvd[1] = V; \
pO->vvd[2] = V;
#define VVD_OP(O) O
#else
#define VVD_X(V)
#define VVD_Y(V)
#define VVD_Z(V)
#define VVD_ALL(V)
#define VVD_OP(O)
#endif
#if ((PASULIOBJECT_POS != 0) && (USE_INITCONST == 0))
#define P_X_CONST(V) pO->pos[0] = V
#define P_Y_CONST(V) pO->pos[1] = V
#define P_Z_CONST(V) pO->pos[2] = V
#else
#define P_X_CONST(V)
#define P_Y_CONST(V)
#define P_Z_CONST(V)
#endif
#if ((PASULIOBJECT_UD != 0) && (USE_INITCONST == 0))
#define UD_X_CONST(V) pO->ud[0] = V
#define UD_Y_CONST(V) pO->ud[1] = V
#define UD_Z_CONST(V) pO->ud[2] = V
#else
#define UD_X_CONST(V)
#define UD_Y_CONST(V)
#define UD_Z_CONST(V)
#endif
#if ((PASULIOBJECT_VD != 0) && (USE_INITCONST == 0))
#define VD_X_CONST(V) pO->vd[0] = V
#define VD_Y_CONST(V) pO->vd[1] = V
#define VD_Z_CONST(V) pO->vd[2] = V
#else
#define VD_X_CONST(V)
#define VD_Y_CONST(V)
#define VD_Z_CONST(V)
#endif
#if ((PASULIOBJECT_N != 0) && (USE_INITCONST == 0))
#define N_X_CONST(V) pO->n[0] = V
#define N_Y_CONST(V) pO->n[1] = V
#define N_Z_CONST(V) pO->n[2] = V
#else
#define N_X_CONST(V)
#define N_Y_CONST(V)
#define N_Z_CONST(V)
#endif
#if ((PASULIOBJECT_UUD != 0) && (USE_INITCONST == 0))
#define UUD_X_CONST(V) pO->uud[0] = V
#define UUD_Y_CONST(V) pO->uud[1] = V
#define UUD_Z_CONST(V) pO->uud[2] = V
#define UUD_CONST_ALL(V) \
pO->uud[0] = V; \
pO->uud[1] = V; \
pO->uud[2] = V
#else
#define UUD_X_CONST(V)
#define UUD_Y_CONST(V)
#define UUD_Z_CONST(V)
#define UUD_CONST_ALL(V)
#endif
#if ((PASULIOBJECT_UVD != 0) && (USE_INITCONST == 0))
#define UVD_X_CONST(V) pO->uvd[0] = V
#define UVD_Y_CONST(V) pO->uvd[1] = V
#define UVD_Z_CONST(V) pO->uvd[2] = V
#define UVD_CONST_ALL(V) \
pO->uvd[0] = V; \
pO->uvd[1] = V; \
pO->uvd[2] = V
#else
#define UVD_X_CONST(V)
#define UVD_Y_CONST(V)
#define UVD_Z_CONST(V)
#define UVD_CONST_ALL(V)
#endif
#if ((PASULIOBJECT_VVD != 0) && (USE_INITCONST == 0))
#define VVD_X_CONST(V) pO->vvd[0] = V
#define VVD_Y_CONST(V) pO->vvd[1] = V
#define VVD_Z_CONST(V) pO->vvd[2] = V
#define VVD_CONST_ALL(V) \
pO->vvd[0] = V; \
pO->vvd[1] = V; \
pO->vvd[2] = V
#else
#define VVD_X_CONST(V)
#define VVD_Y_CONST(V)
#define VVD_Z_CONST(V)
#define VVD_CONST_ALL(V)
#endif
#if (PASULIOBJECT_POS != 0)
#define PASULI_COND_COPY_POS_X(D) (pO->pos[0])
#define PASULI_COND_COPY_POS_Y(D) (pO->pos[1])
#define PASULI_COND_COPY_POS_Z(D) (pO->pos[2])
#else
#define PASULI_COND_COPY_POS_X(D) (D)
#define PASULI_COND_COPY_POS_Y(D) (D)
#define PASULI_COND_COPY_POS_Z(D) (D)
#endif
#if (PASULIOBJECT_UD != 0)
#define PASULI_COND_COPY_UD_X(D) (pO->ud[0])
#define PASULI_COND_COPY_UD_Y(D) (pO->ud[1])
#define PASULI_COND_COPY_UD_Z(D) (pO->ud[2])
#else
#define PASULI_COND_COPY_UD_X(D) (D)
#define PASULI_COND_COPY_UD_Y(D) (D)
#define PASULI_COND_COPY_UD_Z(D) (D)
#endif
#if (PASULIOBJECT_VD != 0)
#define PASULI_COND_COPY_VD_X(D) (pO->vd[0])
#define PASULI_COND_COPY_VD_Y(D) (pO->vd[1])
#define PASULI_COND_COPY_VD_Z(D) (pO->vd[2])
#else
#define PASULI_COND_COPY_VD_X(D) (D)
#define PASULI_COND_COPY_VD_Y(D) (D)
#define PASULI_COND_COPY_VD_Z(D) (D)
#endif
#if (PASULIOBJECT_N != 0)
#define PASULI_COND_COPY_N_X(D) (pO->n[0])
#define PASULI_COND_COPY_N_Y(D) (pO->n[1])
#define PASULI_COND_COPY_N_Z(D) (pO->n[2])
#else
#define PASULI_COND_COPY_N_X(D) (D)
#define PASULI_COND_COPY_N_Y(D) (D)
#define PASULI_COND_COPY_N_Z(D) (D)
#endif
#if (PASULIOBJECT_UUD != 0)
#define PASULI_COND_COPY_UUD_X(D) (pO->uud[0])
#define PASULI_COND_COPY_UUD_Y(D) (pO->uud[1])
#define PASULI_COND_COPY_UUD_Z(D) (pO->uud[2])
#else
#define PASULI_COND_COPY_UUD_X(D) (D)
#define PASULI_COND_COPY_UUD_Y(D) (D)
#define PASULI_COND_COPY_UUD_Z(D) (D)
#endif
#if (PASULIOBJECT_UVD != 0)
#define PASULI_COND_COPY_UVD_X(D) (pO->uvd[0])
#define PASULI_COND_COPY_UVD_Y(D) (pO->uvd[1])
#define PASULI_COND_COPY_UVD_Z(D) (pO->uvd[2])
#else
#define PASULI_COND_COPY_UVD_X(D) (D)
#define PASULI_COND_COPY_UVD_Y(D) (D)
#define PASULI_COND_COPY_UVD_Z(D) (D)
#endif
#if (PASULIOBJECT_VVD != 0)
#define PASULI_COND_COPY_VVD_X(D) (pO->vvd[0])
#define PASULI_COND_COPY_VVD_Y(D) (pO->vvd[1])
#define PASULI_COND_COPY_VVD_Z(D) (pO->vvd[2])
#else
#define PASULI_COND_COPY_VVD_X(D) (D)
#define PASULI_COND_COPY_VVD_Y(D) (D)
#define PASULI_COND_COPY_VVD_Z(D) (D)
#endif
#define PASULI_CALC_NORMAL_FROM_UD_VD \
N_X(yu * zv - zu * yv); \
N_Y(xu * zv - zu * xv); \
N_Z(xu * yv - yu * xv);
#define PASULI_2ND_DERIVATIVES_START \
if (1 == 1) \
{
#define PASULI_2ND_DERIVATIVES_END }
#endif