summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/runtriple.cc
blob: 2383d6d2c7d28802be38bfa23a0a22591dcb5b8d (plain)
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
/***** Autogenerated from runtriple.in; changes will be overwritten *****/

#line 1 "runtimebase.in"
/*****
 * runtimebase.in
 * Andy Hammerlindl  2009/07/28
 *
 * Common declarations needed for all code-generating .in files.
 *
 *****/


#line 1 "runtriple.in"
/*****
 * runtriple.in
 *
 * Runtime functions for triple operations.
 *
 *****/

#line 1 "runtimebase.in"
#include "stack.h"
#include "types.h"
#include "builtin.h"
#include "entry.h"
#include "errormsg.h"
#include "array.h"
#include "triple.h"
#include "callable.h"
#include "opsymbols.h"

using vm::stack;
using vm::error;
using vm::array;
using vm::read;
using vm::callable;
using types::formal;
using types::function;
using camp::triple;

#define PRIMITIVE(name,Name,asyName) using types::prim##Name;
#include <primitives.h>
#undef PRIMITIVE

typedef double real;

void unused(void *);

namespace run {
array *copyArray(array *a);
array *copyArray2(array *a);
array *copyArray3(array *a);

inline size_t checkdimension(const array *a, size_t dim)
{
  size_t size=checkArray(a);
  if(dim && size != dim) {
    ostringstream buf;
    buf << "array of length " << dim << " expected";
    error(buf);
  }
  return size;
}

template<class T>
void copyArrayC(T* &dest, const array *a, size_t dim=0,
                GCPlacement placement=NoGC)
{
  size_t size=checkdimension(a,dim);
  dest=(placement == NoGC) ? new T[size] : new(placement) T[size];
  for(size_t i=0; i < size; i++) 
    dest[i]=read<T>(a,i);
}

template<class T>
void copyArray2C(T* &dest, const array *a, bool square=true, size_t dim2=0,
                 GCPlacement placement=NoGC)
{
  size_t n=checkArray(a);
  size_t m=(square || n == 0) ? n : checkArray(read<array*>(a,0));
  if(n > 0 && dim2 && m != dim2) {
    ostringstream buf;
    buf << "second matrix dimension must be " << dim2;
    error(buf);
  }
  
  dest=(placement == NoGC) ? new T[n*m] : new(placement) T[n*m];
  for(size_t i=0; i < n; i++) {
    array *ai=read<array*>(a,i);
    size_t aisize=checkArray(ai);
    if(aisize == m) {
      T *desti=dest+i*m;
      for(size_t j=0; j < m; j++) 
        desti[j]=read<T>(ai,j);
    } else
      error(square ? "matrix must be square" : "matrix must be rectangular");
  }
}

double *copyTripleArray2Components(array *a, bool square=true, size_t dim2=0,
                                   GCPlacement placement=NoGC);
}

function *realRealFunction();

#define CURRENTPEN processData().currentpen

#line 10 "runtriple.in"
#include "triple.h"
#include "path3.h"

using namespace camp;

// Autogenerated routines:



#include "runtriple.symbols.h"

namespace run {
#line 18 "runtriple.in"
void tripleZero(stack *Stack)
{
#line 19 "runtriple.in"
  static triple zero;
  {Stack->push<triple>(zero); return;}
}

#line 24 "runtriple.in"
void realRealRealToTriple(stack *Stack)
{
  real z=vm::pop<real>(Stack);
  real y=vm::pop<real>(Stack);
  real x=vm::pop<real>(Stack);
#line 25 "runtriple.in"
  {Stack->push<triple>(triple(x,y,z)); return;}
}

#line 29 "runtriple.in"
// real xpart(triple v);
void tripleXPart(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 30 "runtriple.in"
  {Stack->push<real>(v.getx()); return;}
}

#line 34 "runtriple.in"
// real ypart(triple v);
void tripleYPart(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 35 "runtriple.in"
  {Stack->push<real>(v.gety()); return;}
}

#line 39 "runtriple.in"
// real zpart(triple v);
void tripleZPart(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 40 "runtriple.in"
  {Stack->push<real>(v.getz()); return;}
}

#line 44 "runtriple.in"
// triple *(real x, triple v);
void gen_runtriple5(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
  real x=vm::pop<real>(Stack);
#line 45 "runtriple.in"
  {Stack->push<triple>(x*v); return;}
}

#line 49 "runtriple.in"
// triple *(triple v, real x);
void gen_runtriple6(stack *Stack)
{
  real x=vm::pop<real>(Stack);
  triple v=vm::pop<triple>(Stack);
#line 50 "runtriple.in"
  {Stack->push<triple>(v*x); return;}
}

#line 54 "runtriple.in"
// triple /(triple v, real x);
void gen_runtriple7(stack *Stack)
{
  real x=vm::pop<real>(Stack);
  triple v=vm::pop<triple>(Stack);
#line 55 "runtriple.in"
  {Stack->push<triple>(v/x); return;}
}

#line 59 "runtriple.in"
// real length(triple v);
void gen_runtriple8(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 60 "runtriple.in"
  {Stack->push<real>(v.length()); return;}
}

#line 64 "runtriple.in"
// real abs(triple v);
void gen_runtriple9(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 65 "runtriple.in"
  {Stack->push<real>(v.length()); return;}
}

#line 69 "runtriple.in"
// real polar(triple v, bool warn=true);
void gen_runtriple10(stack *Stack)
{
  bool warn=vm::pop<bool>(Stack,true);
  triple v=vm::pop<triple>(Stack);
#line 70 "runtriple.in"
  if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) {Stack->push<real>(0.0); return;}
  {Stack->push<real>(v.polar()); return;}
}

#line 75 "runtriple.in"
// real azimuth(triple v, bool warn=true);
void gen_runtriple11(stack *Stack)
{
  bool warn=vm::pop<bool>(Stack,true);
  triple v=vm::pop<triple>(Stack);
#line 76 "runtriple.in"
  if(!warn && v.getx() == 0.0 && v.gety() == 0.0) {Stack->push<real>(0.0); return;}
  {Stack->push<real>(v.azimuth()); return;}
}

#line 81 "runtriple.in"
// real colatitude(triple v, bool warn=true);
void gen_runtriple12(stack *Stack)
{
  bool warn=vm::pop<bool>(Stack,true);
  triple v=vm::pop<triple>(Stack);
#line 82 "runtriple.in"
  if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) {Stack->push<real>(0.0); return;}
  {Stack->push<real>(degrees(v.polar())); return;}
}

#line 87 "runtriple.in"
// real latitude(triple v, bool warn=true);
void gen_runtriple13(stack *Stack)
{
  bool warn=vm::pop<bool>(Stack,true);
  triple v=vm::pop<triple>(Stack);
#line 88 "runtriple.in"
  if(!warn && v.getx() == 0.0 && v.gety() == 0.0 && v.getz() == 0.0) {Stack->push<real>(0.0); return;}
  {Stack->push<real>(90.0-degrees(v.polar())); return;}
}

// Return the longitude of v in [0,360).
#line 94 "runtriple.in"
// real longitude(triple v, bool warn=true);
void gen_runtriple14(stack *Stack)
{
  bool warn=vm::pop<bool>(Stack,true);
  triple v=vm::pop<triple>(Stack);
#line 95 "runtriple.in"
  if(!warn && v.getx() == 0.0 && v.gety() == 0.0) {Stack->push<real>(0.0); return;}
  {Stack->push<real>(principalBranch(degrees(v.azimuth()))); return;}
}

#line 100 "runtriple.in"
// triple unit(triple v);
void gen_runtriple15(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
#line 101 "runtriple.in"
  {Stack->push<triple>(unit(v)); return;}
}

#line 105 "runtriple.in"
// real dot(triple u, triple v);
void gen_runtriple16(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
  triple u=vm::pop<triple>(Stack);
#line 106 "runtriple.in"
  {Stack->push<real>(dot(u,v)); return;}
}

#line 110 "runtriple.in"
// triple cross(triple u, triple v);
void gen_runtriple17(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
  triple u=vm::pop<triple>(Stack);
#line 111 "runtriple.in"
  {Stack->push<triple>(cross(u,v)); return;}
}

#line 115 "runtriple.in"
// triple dir(explicit triple z);
void gen_runtriple18(stack *Stack)
{
  triple z=vm::pop<triple>(Stack);
#line 116 "runtriple.in"
  {Stack->push<triple>(unit(z)); return;}
}

#line 120 "runtriple.in"
// triple expi(real polar, real azimuth);
void gen_runtriple19(stack *Stack)
{
  real azimuth=vm::pop<real>(Stack);
  real polar=vm::pop<real>(Stack);
#line 121 "runtriple.in"
  {Stack->push<triple>(expi(polar,azimuth)); return;}
}

#line 125 "runtriple.in"
// triple dir(real colatitude, real longitude);
void gen_runtriple20(stack *Stack)
{
  real longitude=vm::pop<real>(Stack);
  real colatitude=vm::pop<real>(Stack);
#line 126 "runtriple.in"
  {Stack->push<triple>(expi(radians(colatitude),radians(longitude))); return;}
}

#line 130 "runtriple.in"
// triple realmult(triple u, triple v);
void gen_runtriple21(stack *Stack)
{
  triple v=vm::pop<triple>(Stack);
  triple u=vm::pop<triple>(Stack);
#line 131 "runtriple.in"
  {Stack->push<triple>(triple (u.getx()*v.getx(),u.gety()*v.gety(),u.getz()*v.getz())); return;}
}

// Return the component of vector v perpendicular to a unit vector u.
#line 136 "runtriple.in"
// triple perp(triple v, triple u);
void gen_runtriple22(stack *Stack)
{
  triple u=vm::pop<triple>(Stack);
  triple v=vm::pop<triple>(Stack);
#line 137 "runtriple.in"
  {Stack->push<triple>(perp(v,u)); return;}
}

#line 141 "runtriple.in"
// triple bezier(triple a, triple b, triple c, triple d, real t);
void gen_runtriple23(stack *Stack)
{
  real t=vm::pop<real>(Stack);
  triple d=vm::pop<triple>(Stack);
  triple c=vm::pop<triple>(Stack);
  triple b=vm::pop<triple>(Stack);
  triple a=vm::pop<triple>(Stack);
#line 142 "runtriple.in"
  real onemt=1-t;
  real onemt2=onemt*onemt;
  {Stack->push<triple>(onemt2*onemt*a+t*(3.0*(onemt2*b+t*onemt*c)+t*t*d)); return;}
}

#line 148 "runtriple.in"
// triple bezierP(triple a, triple b, triple c, triple d, real t);
void gen_runtriple24(stack *Stack)
{
  real t=vm::pop<real>(Stack);
  triple d=vm::pop<triple>(Stack);
  triple c=vm::pop<triple>(Stack);
  triple b=vm::pop<triple>(Stack);
  triple a=vm::pop<triple>(Stack);
#line 149 "runtriple.in"
  {Stack->push<triple>(3.0*(t*t*(d-a+3.0*(b-c))+t*(2.0*(a+c)-4.0*b)+b-a)); return;}
}

#line 153 "runtriple.in"
// triple bezierPP(triple a, triple b, triple c, triple d, real t);
void gen_runtriple25(stack *Stack)
{
  real t=vm::pop<real>(Stack);
  triple d=vm::pop<triple>(Stack);
  triple c=vm::pop<triple>(Stack);
  triple b=vm::pop<triple>(Stack);
  triple a=vm::pop<triple>(Stack);
#line 154 "runtriple.in"
  {Stack->push<triple>(6.0*(t*(d-a+3.0*(b-c))+a+c-2.0*b)); return;}
}

#line 158 "runtriple.in"
// triple bezierPPP(triple a, triple b, triple c, triple d);
void gen_runtriple26(stack *Stack)
{
  triple d=vm::pop<triple>(Stack);
  triple c=vm::pop<triple>(Stack);
  triple b=vm::pop<triple>(Stack);
  triple a=vm::pop<triple>(Stack);
#line 159 "runtriple.in"
  {Stack->push<triple>(6.0*(d-a+3.0*(b-c))); return;}
}

} // namespace run

namespace trans {

void gen_runtriple_venv(venv &ve)
{
#line 18 "runtriple.in"
  REGISTER_BLTIN(run::tripleZero,"tripleZero");
#line 24 "runtriple.in"
  REGISTER_BLTIN(run::realRealRealToTriple,"realRealRealToTriple");
#line 29 "runtriple.in"
  addFunc(ve, run::tripleXPart, primReal(), SYM(xpart), formal(primTriple(), SYM(v), false, false));
#line 34 "runtriple.in"
  addFunc(ve, run::tripleYPart, primReal(), SYM(ypart), formal(primTriple(), SYM(v), false, false));
#line 39 "runtriple.in"
  addFunc(ve, run::tripleZPart, primReal(), SYM(zpart), formal(primTriple(), SYM(v), false, false));
#line 44 "runtriple.in"
  addFunc(ve, run::gen_runtriple5, primTriple(), SYM_TIMES, formal(primReal(), SYM(x), false, false), formal(primTriple(), SYM(v), false, false));
#line 49 "runtriple.in"
  addFunc(ve, run::gen_runtriple6, primTriple(), SYM_TIMES, formal(primTriple(), SYM(v), false, false), formal(primReal(), SYM(x), false, false));
#line 54 "runtriple.in"
  addFunc(ve, run::gen_runtriple7, primTriple(), SYM_DIVIDE, formal(primTriple(), SYM(v), false, false), formal(primReal(), SYM(x), false, false));
#line 59 "runtriple.in"
  addFunc(ve, run::gen_runtriple8, primReal(), SYM(length), formal(primTriple(), SYM(v), false, false));
#line 64 "runtriple.in"
  addFunc(ve, run::gen_runtriple9, primReal(), SYM(abs), formal(primTriple(), SYM(v), false, false));
#line 69 "runtriple.in"
  addFunc(ve, run::gen_runtriple10, primReal(), SYM(polar), formal(primTriple(), SYM(v), false, false), formal(primBoolean(), SYM(warn), true, false));
#line 75 "runtriple.in"
  addFunc(ve, run::gen_runtriple11, primReal(), SYM(azimuth), formal(primTriple(), SYM(v), false, false), formal(primBoolean(), SYM(warn), true, false));
#line 81 "runtriple.in"
  addFunc(ve, run::gen_runtriple12, primReal(), SYM(colatitude), formal(primTriple(), SYM(v), false, false), formal(primBoolean(), SYM(warn), true, false));
#line 87 "runtriple.in"
  addFunc(ve, run::gen_runtriple13, primReal(), SYM(latitude), formal(primTriple(), SYM(v), false, false), formal(primBoolean(), SYM(warn), true, false));
#line 93 "runtriple.in"
  addFunc(ve, run::gen_runtriple14, primReal(), SYM(longitude), formal(primTriple(), SYM(v), false, false), formal(primBoolean(), SYM(warn), true, false));
#line 100 "runtriple.in"
  addFunc(ve, run::gen_runtriple15, primTriple(), SYM(unit), formal(primTriple(), SYM(v), false, false));
#line 105 "runtriple.in"
  addFunc(ve, run::gen_runtriple16, primReal(), SYM(dot), formal(primTriple(), SYM(u), false, false), formal(primTriple(), SYM(v), false, false));
#line 110 "runtriple.in"
  addFunc(ve, run::gen_runtriple17, primTriple(), SYM(cross), formal(primTriple(), SYM(u), false, false), formal(primTriple(), SYM(v), false, false));
#line 115 "runtriple.in"
  addFunc(ve, run::gen_runtriple18, primTriple(), SYM(dir), formal(primTriple(), SYM(z), false, true));
#line 120 "runtriple.in"
  addFunc(ve, run::gen_runtriple19, primTriple(), SYM(expi), formal(primReal(), SYM(polar), false, false), formal(primReal(), SYM(azimuth), false, false));
#line 125 "runtriple.in"
  addFunc(ve, run::gen_runtriple20, primTriple(), SYM(dir), formal(primReal(), SYM(colatitude), false, false), formal(primReal(), SYM(longitude), false, false));
#line 130 "runtriple.in"
  addFunc(ve, run::gen_runtriple21, primTriple(), SYM(realmult), formal(primTriple(), SYM(u), false, false), formal(primTriple(), SYM(v), false, false));
#line 135 "runtriple.in"
  addFunc(ve, run::gen_runtriple22, primTriple(), SYM(perp), formal(primTriple(), SYM(v), false, false), formal(primTriple(), SYM(u), false, false));
#line 141 "runtriple.in"
  addFunc(ve, run::gen_runtriple23, primTriple(), SYM(bezier), formal(primTriple(), SYM(a), false, false), formal(primTriple(), SYM(b), false, false), formal(primTriple(), SYM(c), false, false), formal(primTriple(), SYM(d), false, false), formal(primReal(), SYM(t), false, false));
#line 148 "runtriple.in"
  addFunc(ve, run::gen_runtriple24, primTriple(), SYM(bezierP), formal(primTriple(), SYM(a), false, false), formal(primTriple(), SYM(b), false, false), formal(primTriple(), SYM(c), false, false), formal(primTriple(), SYM(d), false, false), formal(primReal(), SYM(t), false, false));
#line 153 "runtriple.in"
  addFunc(ve, run::gen_runtriple25, primTriple(), SYM(bezierPP), formal(primTriple(), SYM(a), false, false), formal(primTriple(), SYM(b), false, false), formal(primTriple(), SYM(c), false, false), formal(primTriple(), SYM(d), false, false), formal(primReal(), SYM(t), false, false));
#line 158 "runtriple.in"
  addFunc(ve, run::gen_runtriple26, primTriple(), SYM(bezierPPP), formal(primTriple(), SYM(a), false, false), formal(primTriple(), SYM(b), false, false), formal(primTriple(), SYM(c), false, false), formal(primTriple(), SYM(d), false, false));
}

} // namespace trans