summaryrefslogtreecommitdiff
path: root/graphics/asymptote/runpicture.in
blob: 696e303ace688d4c965ef03e42d936c73e8d33b9 (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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
/*****
 * runpicture.in
 *
 * Runtime functions for picture operations.
 *
 *****/

pen      => primPen()
pair     => primPair()
triple   => primTriple()
path     => primPath()
path3     => primPath3()
picture* => primPicture()
Intarray*  => IntArray()
Intarray2*  => IntArray2()
realarray* => realArray()
realarray2* => realArray2()
patharray* => pathArray()
penarray* => penArray()
penarray2* => penArray2()
pairarray* => pairArray()
pairarray2* => pairArray2()
triplearray* => tripleArray()
triplearray2* => tripleArray2()
transform => primTransform()
callablePen* => penFunction()

#include "picture.h"
#include "drawelement.h"
#include "path.h"
#include "array.h"
#include "arrayop.h"
#include "drawpath.h"
#include "drawfill.h"
#include "drawclipbegin.h"
#include "drawclipend.h"
#include "drawgsave.h"
#include "drawgrestore.h"
#include "drawgroup.h"
#include "drawverbatim.h"
#include "drawlabel.h"
#include "drawlayer.h"
#include "drawimage.h"
#include "drawpath3.h"
#include "drawsurface.h"

using namespace camp;
using namespace settings;
using namespace vm;

typedef array Intarray;
typedef array Intarray2;
typedef array realarray;
typedef array realarray2;
typedef array pairarray;
typedef array pairarray2;
typedef array triplearray;
typedef array triplearray2;
typedef array patharray;
typedef array penarray;
typedef array penarray2;

typedef callable callablePen;

using types::IntArray;
using types::IntArray2;
using types::realArray;
using types::realArray2;
using types::pairArray;
using types::pairArray2;
using types::tripleArray;
using types::tripleArray2;
using types::pathArray;
using types::penArray;
using types::penArray2;

static transform ZeroTransform=transform(0.0,0.0,0.0,0.0,0.0,0.0);

transform getTransform(xmap_t &xmap, picture::nodelist::iterator p)
{
  string s=(*p)->KEY;
  transform t;
  // Don't apply xmap without an explicit corresponding key
  size_t n=s.length();
  if(n == 0 || s.substr(n-1) != "1") return t;

  xmap_t::iterator q=xmap.find(s.substr(0,n-2));
  if(q != xmap.end()) {
    xtransform_t& v=q->second;
    if(!v.empty()) {
      t=v.front();
      v.pop_front();
    }
  }
  return t;
}


function *transformFunction()
{
  return new function(primTransform());
}

function *penFunction()
{
  return new function(primPen(),primInt(),primInt());
}

// Ignore unclosed begingroups but not spurious endgroups.
const char *nobegin="endgroup without matching begingroup";

array *emptyarray=new array(0);

array *nop(array *a)
{
  return a;
}

triple Zero;

string defaultformat3="prc";

// Autogenerated routines:


picture* :newPicture()
{
  return new picture();
}

bool empty(picture *f)
{
  return f->null();
}

void erase(picture *f)
{
  f->nodes.clear();
}

pair min(picture *f)
{
  return f->bounds().Min();
}

pair max(picture *f)
{
  return f->bounds().Max();
}

pair size(picture *f)
{
  bbox b=f->bounds();
  return b.Max()-b.Min();
}

void _draw(picture *f, path g, pen p)
{
  f->append(new drawPath(g,p));
}

void fill(picture *f, patharray *g, pen p=CURRENTPEN, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawFill(*copyarray(g),false,p));
}

void latticeshade(picture *f, patharray *g, bool stroke=false,
                  pen fillrule=CURRENTPEN, penarray2 *p, transform t=identity,
                  bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawLatticeShade(*copyarray(g),stroke,fillrule,*copyarray(p),
                                 t));
}

void axialshade(picture *f, patharray *g, bool stroke=false, pen pena, pair a,
                bool extenda=true, pen penb, pair b, bool extendb=true,
                bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawAxialShade(*copyarray(g),stroke,pena,a,extenda,penb,b,
                               extendb));
}

void radialshade(picture *f, patharray *g, bool stroke=false, pen pena,
                 pair a, real ra, bool extenda=true, pen penb, pair b, real rb,
                 bool extendb=true, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawRadialShade(*copyarray(g),stroke,pena,a,ra,extenda,
                                penb,b,rb,extendb));
}

void gouraudshade(picture *f, patharray *g, bool stroke=false,
                  pen fillrule=CURRENTPEN, penarray *p, pairarray *z,
                  Intarray *edges, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  checkArrays(p,z);
  checkArrays(z,edges);
  f->append(new drawGouraudShade(*copyarray(g),stroke,fillrule,*copyarray(p),
                                 *copyarray(z),*copyarray(edges)));
}

void gouraudshade(picture *f, patharray *g, bool stroke=false,
                  pen fillrule=CURRENTPEN, penarray *p, Intarray *edges,
                  bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  size_t n=checkArrays(p,edges);
  size_t m=checkArray(g);
  array *z=new array(n);
  Int k=0;
  Int in=(Int) n;
  for(size_t j=0; j < m; ++j) {
    path *P=read<path *>(g,j);
    assert(P);
    Int stop=Min(P->size(),in-k);
    mem::vector<solvedKnot>& nodes=P->Nodes();
    for(Int i=0; i < stop; ++i)
      (*z)[k++]=nodes[i].point;
  }
  checkArrays(p,z);

  f->append(new drawGouraudShade(*copyarray(g),stroke,fillrule,*copyarray(p),
                                 *z,*copyarray(edges)));
}

void tensorshade(picture *f, patharray *g, bool stroke=false,
                 pen fillrule=CURRENTPEN, penarray2 *p, patharray *b=NULL,
                 pairarray2 *z=emptyarray, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  array *(*copyarray2)(array *a)=copy ? copyArray2 : nop;
  size_t n=checkArrays(p,b ? b : g);
  array& G=*copyarray(g);
  array& B=b ? *copyarray(b) : G;
  size_t nz=checkArray(z);
  if(nz != 0)
    checkEqual(nz,n);
  f->append(new drawTensorShade(G,stroke,fillrule,*copyarray2(p),B,
                                *copyarray2(z)));
}

void functionshade(picture *f, patharray *g, bool stroke=false,
                   pen fillrule=CURRENTPEN, string shader=emptystring,
                   bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawFunctionShade(*copyarray(g),stroke,fillrule,shader));
}

// Clip a picture to a superpath using the given fill rule.
// Subsequent additions to the picture will not be affected by the clipping.
void clip(picture *f, patharray *g, bool stroke=false,
          pen fillrule=CURRENTPEN, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  drawClipBegin *begin=new drawClipBegin(*copyarray(g),stroke,fillrule,true);
  f->enclose(begin,new drawClipEnd(true,begin));
}

void beginclip(picture *f, patharray *g, bool stroke=false,
               pen fillrule=CURRENTPEN, bool copy=true)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  f->append(new drawClipBegin(*copyarray(g),stroke,fillrule,false));
}

void endclip(picture *f)
{
  f->append(new drawClipEnd(false));
}

void gsave(picture *f)
{
  f->append(new drawGsave());
}

void grestore(picture *f)
{
  f->append(new drawGrestore());
}

void begingroup(picture *f)
{
  f->append(new drawBegin());
}

void endgroup(picture *f)
{
  f->append(new drawEnd());
}

void _begingroup3(picture *f, string name, real compression,
                  real granularity, bool closed, bool tessellate,
                  bool dobreak, bool nobreak, triple center, Int interaction)
{
  f->append(new drawBegin3(name,compression,granularity,
                           closed,tessellate,dobreak,nobreak,
                           center,(Interaction) intcast(interaction)));
}

void endgroup3(picture *f)
{
  f->append(new drawEnd3());
}

void add(picture *dest, picture *src)
{
  dest->add(*src);
}

void prepend(picture *dest, picture *src)
{
  dest->prepend(*src);
}

void postscript(picture *f, string s)
{
  f->append(new drawVerbatim(PostScript,s));
}

void tex(picture *f, string s)
{
  f->append(new drawVerbatim(TeX,s));
}

void postscript(picture *f, string s, pair min, pair max)
{
  f->append(new drawVerbatim(PostScript,s,min,max));
}

void tex(picture *f, string s, pair min, pair max)
{
  f->append(new drawVerbatim(TeX,s,min,max));
}

void texpreamble(string s)
{
  string t=s+"\n";
  processDataStruct &pd=processData();
  pd.TeXpipepreamble.push_back(t);
  pd.TeXpreamble.push_back(t);
}

void deletepreamble()
{
  if(getSetting<bool>("inlinetex")) {
    unlink(buildname(outname(),"pre").c_str());
  }
}

void _labelpath(picture *f, string s, string size, path g, string justify,
                pair offset, pen p)
{
  f->append(new drawLabelPath(s,size,g,justify,offset,p));
}

void texreset()
{
  processDataStruct &pd=processData();
  pd.TeXpipepreamble.clear();
  pd.TeXpreamble.clear();
  pd.tex.pipeclose();
}

void layer(picture *f)
{
  f->append(new drawLayer());
}

void newpage(picture *f)
{
  f->append(new drawNewPage());
}

void _image(picture *f, realarray2 *data, pair initial, pair final,
            penarray *palette=NULL, transform t=identity, bool copy=true,
            bool antialias=false)
{
  array *(*copyarray)(array *a)=copy ? copyArray : nop;
  array *(*copyarray2)(array *a)=copy ? copyArray2 : nop;
  f->append(new drawPaletteImage(*copyarray2(data),*copyarray(palette),
                                 t*matrix(initial,final),antialias));
}

void _image(picture *f, penarray2 *data, pair initial, pair final,
            transform t=identity, bool copy=true, bool antialias=false)
{
  array *(*copyarray2)(array *a)=copy ? copyArray2 : nop;
  f->append(new drawNoPaletteImage(*copyarray2(data),t*matrix(initial,final),
                                   antialias));
}

void _image(picture *f, callablePen *F, Int width, Int height,
            pair initial, pair final, transform t=identity, bool antialias=false)
{
  f->append(new drawFunctionImage(Stack,F,width,height,
                                  t*matrix(initial,final),antialias));
}

string nativeformat()
{
  return nativeformat();
}

bool latex()
{
  return latex(getSetting<string>("tex"));
}

bool pdf()
{
  return pdf(getSetting<string>("tex"));
}

void _shipout(string prefix=emptystring, picture *f, picture *preamble=NULL,
              string format=emptystring, bool wait=false, bool view=true,
              transform T=identity)
{
  if(prefix.empty()) prefix=outname();

  picture *result=new picture;
  unsigned level=0;

  xmap_t xmap=processData().xmap;
  transform Tinv=inverse(T);

  for(picture::nodelist::iterator p=f->nodes.begin(); p != f->nodes.end();
      ++p) {
    transform t=getTransform(xmap,p);
    bool Delete=(t == ZeroTransform);
    if(!Delete && !t.isIdentity()) t=T*t*Tinv;
    picture *group=new picture;
    assert(*p);
    if((*p)->endgroup()) error(nobegin);
    if((*p)->begingroup()) {
      ++level;
      while(p != f->nodes.end() && level) {
        if(!Delete) {
          drawElement *e=t.isIdentity() ? *p : (*p)->transformed(t);
          group->append(e);
        }
        ++p;
        if(p == f->nodes.end()) break;
        assert(*p);
        if((*p)->begingroup()) ++level;
        if((*p)->endgroup()) {
          if(level) --level;
          else error(nobegin);
        }
      }
    }
    if(p == f->nodes.end()) break;
    assert(*p);
    if(!Delete) {
      drawElement *e=t.isIdentity() ? *p : (*p)->transformed(t);
      group->append(e);
      result->add(*group);
    }
    delete group;
  }

  result->shipout(preamble,prefix,format,wait,view);
  delete result;
}

void shipout3(string prefix, picture *f, string format=emptystring,
              real width, real height, real angle, real zoom,
              triple m, triple M, pair shift, pair margin, realarray2 *t,
              realarray *background, triplearray *lights, realarray2 *diffuse,
              realarray2 *specular, bool view=true)
{
  size_t n=checkArrays(lights,diffuse);
  checkEqual(n,checkArray(specular));

  real *T,*Background,*Diffuse,*Specular;
  triple *Lights;

  copyArray2C(T,t,true,4);
  copyArrayC(Background,background);
  copyArrayC(Lights,lights);
  copyArray2C(Diffuse,diffuse,false,4,UseGC);
  copyArray2C(Specular,specular,false,4,UseGC);

  f->shipout3(prefix,format,width,height,angle,zoom,m,M,shift,margin,T,
              Background,n,Lights,Diffuse,Specular,view);

  delete[] Background;
  delete[] T;
}

void shipout3(string prefix, picture *f, string format=defaultformat3)
{
  f->shipout3(prefix,format);
}

void xmap(string key, transform t=identity)
{
  processDataStruct *P=&processData();
  xmap_t &xmap=P->xmap;
  xmap_t::iterator p=xmap.find(key);
  if(p != xmap.end())
    p->second.push_back(t);
  else {
    xtransform_t *v=new xtransform_t();
    v->push_back(t);
    xmap[key]=*v;
  }
  P->xmapCount++;
}

void deconstruct(picture *f, picture *preamble=NULL, transform T=identity)
{
  unsigned level=0;
  bool first=pdf(getSetting<string>("tex"));

  string prefix=outname();
  const string xformat="svg";

  openpipeout();

  const string Done="Done";
  const string Error="Error";

  unsigned arg=0;
  xmap_t xmap=processData().xmap;
  transform Tinv=inverse(T);

  picture *F=new picture(true);

  for(picture::nodelist::iterator p=f->nodes.begin(); p != f->nodes.end();) {
    picture *group=new picture;
    transform t=getTransform(xmap,p);
    bool Delete=(t == ZeroTransform);
    if(!Delete && !t.isIdentity()) t=T*t*Tinv;

    assert(*p);
    if((*p)->endgroup()) {
      fprintf(pipeout,"%s\n",Error.c_str());
      fflush(pipeout);
      error(nobegin);
    }
    bool clip=false;
    if((*p)->begingroup()) {
      string key=(*p)->KEY;
      ++level;
      while(p != f->nodes.end() && level) {
        if(!Delete) {
          drawElement *e=t.isIdentity() ? *p : (*p)->transformed(t);
          group->append(e);
          if((*p)->endclip()) clip=true;
        }
        ++p;
        if(p == f->nodes.end()) break;
        assert(*p);
        if((*p)->begingroup()) ++level;
        if((*p)->endgroup()) {
          if(level) --level;
          else {
            fprintf(pipeout,"%s\n",Error.c_str());
            fflush(pipeout);
            error(nobegin);
          }
          if(level == 0)
            (*p)->KEY=key;
        }
      }
    }

    if(p != f->nodes.end()) {
      if(!Delete) {
        drawElement *e=t.isIdentity() ? *p : (*p)->transformed(t);
        group->append(e);
        bbox b=group->bounds();
        if(!b.empty && b.right > b.left && b.top > b.bottom) {
          if((*p)->endclip()) clip=true;

          if(first)
            first=false;
          else
            F->append(new drawNewPage(b));

          F->append(new drawBBox(b));

          for(picture::nodelist::iterator g=group->nodes.begin();
              !(g == group->nodes.end()); ++g)
            F->append(*g);

          fprintf(pipeout,"KEY=%s%d\n",e->KEY.c_str(),clip);

          const char *oldlocale=setlocale(LC_NUMERIC,NULL);
          bool override=oldlocale && strcmp(oldlocale,"C") != 0;
          if(override) {
            oldlocale=StrdupNoGC(oldlocale);
            setlocale(LC_NUMERIC,"C");
          }

          fprintf(pipeout,"%g %g %g %g\n",b.left,b.bottom,b.right,b.top);

          if(override) {
            setlocale(LC_NUMERIC,oldlocale);
            delete[] oldlocale;
          }

          fflush(pipeout);
          ++arg;
        }
      } else {
        drawElement *e=t.isIdentity() ? *p : (*p)->transformed(t);
        fprintf(pipeout,"KEY=%s2\n",e->KEY.c_str());
        fprintf(pipeout,"0 0 0 0\n");
      }

      ++p;
    }
    delete group;
  }

  string outname=buildname(prefix,xformat);
  F->shipout(preamble,outname,xformat,false,false);
  fprintf(pipeout,"%s\n",Done.c_str());
  fflush(pipeout);
  delete F;
}


// Three-dimensional picture and surface operations

// Bezier curve
void _draw(picture *f, path3 g, triple center=Zero, penarray *p,
           real opacity, real shininess, real metallic, real fresnel0,
           Int interaction=0)
{
  size_t n=g.size();
  for(unsigned int i=0; i < n; ++i)
    f->append(new drawPath3(g.subpath((Int) i,Int(i+1)),center,*p,opacity,
                            shininess,metallic,fresnel0,
                            (Interaction) intcast(interaction)));
}

// Bezier patch
void draw(picture *f, triplearray2 *P, triple center, bool straight,
          penarray *p, real opacity, real shininess, real metallic,
          real fresnel0, penarray *colors, Int interaction, Int digits,
          bool primitive=false)
{
  f->append(new drawBezierPatch(*P,center,straight,*p,opacity,shininess,
                                metallic,fresnel0,*colors,
                                (Interaction) intcast(interaction),
                                digits,primitive));
}

// Bezier triangle
void drawbeziertriangle(picture *f, triplearray2 *P, triple center,
                        bool straight, penarray *p, real opacity,
                        real shininess, real metallic, real fresnel0,
                        penarray *colors, Int interaction, Int digits,
                        bool primitive=false)
{
  f->append(new drawBezierTriangle(*P,center,straight,*p,opacity,shininess,
                                   metallic,fresnel0,*colors,
                                   (Interaction) intcast(interaction),
                                   digits,primitive));
}

// General NURBS curve
void draw(picture *f, triplearray *P, realarray *knot,
          realarray *weights=emptyarray, pen p)
{
  f->append(new drawNurbsPath3(*P,knot,weights,p));
}

// General NURBS surface
void draw(picture *f, triplearray2 *P, realarray *uknot, realarray *vknot,
          realarray2 *weights=emptyarray, penarray *p, real opacity,
          real shininess,real metallic, real fresnel0, penarray *colors)
{
  f->append(new drawNurbs(*P,uknot,vknot,weights,*p,opacity,shininess,
                          metallic,fresnel0,*colors));
}

// Sphere primitive
void drawSphere(picture *f, realarray2 *t, bool half=false, penarray *p,
                real opacity, real shininess, real metallic, real fresnel0,
                Int type)
{
  f->append(new drawSphere(*t,half,*p,opacity,shininess,metallic,fresnel0,
                           intcast(type)));
}

// Cylinder primitive
void drawCylinder(picture *f, realarray2 *t, penarray *p, real opacity,
                  real shininess, real metallic, real fresnel0,
                  bool core=false)
{
  f->append(new drawCylinder(*t,*p,opacity,shininess,metallic,fresnel0,core));
}

// Disk primitive
void drawDisk(picture *f, realarray2 *t, penarray *p, real opacity,
              real shininess, real metallic, real fresnel0)
{
  f->append(new drawDisk(*t,*p,opacity,shininess,metallic,fresnel0));
}

// Tube primitive
void drawTube(picture *f, triplearray *g, real width, penarray *p,
              real opacity, real shininess, real metallic, real fresnel0,
              triple min, triple max, bool core=false)
{
  f->append(new drawTube(*g,width,*p,opacity,shininess,metallic,fresnel0,
                         min,max,core));
}

// Draw pixel
void drawpixel(picture *f, triple v, pen p, real width=1.0)
{
  f->append(new drawPixel(v,p,width));
}

// Draw triangles
void draw(picture *f, triplearray *v, Intarray2 *vi, triple center=Zero,
          triplearray *n, Intarray2 *ni,
          penarray *p, real opacity, real shininess,
          real metallic, real fresnel0,
          penarray *c=emptyarray, Intarray2 *ci=emptyarray, Int interaction)
{
  f->append(new drawTriangles(*v,*vi,center,*n,*ni,*p,opacity,shininess,
                              metallic,fresnel0,*c,*ci,
                              (Interaction) intcast(interaction)));
}

triple min3(picture *f)
{
  return f->bounds3().Min();
}

triple max3(picture *f)
{
  return f->bounds3().Max();
}

triple size3(picture *f)
{
  bbox3 b=f->bounds3();
  return b.Max()-b.Min();
}

pair minratio(picture *f)
{
  return f->ratio(::min);
}

pair maxratio(picture *f)
{
  return f->ratio(::max);
}

bool is3D(picture *f)
{
  return f->have3D();
}