Code coverage tests

This page documents the degree to which the PARI/GP source code is tested by our public test suite, distributed with the source distribution in directory src/test/. This is measured by the gcov utility; we then process gcov output using the lcov frond-end.

We test a few variants depending on Configure flags on the pari.math.u-bordeaux.fr machine (x86_64 architecture), and agregate them in the final report:

The target is 90% coverage for all mathematical modules (given that branches depending on DEBUGLEVEL or DEBUGMEM are not covered). This script is run to produce the results below.

LCOV - code coverage report
Current view: top level - graph - plotport.c (source / functions) Hit Total Coverage
Test: PARI/GP v2.10.0 lcov report (development 21739-44c3c17) Lines: 1021 1227 83.2 %
Date: 2018-01-20 06:18:48 Functions: 83 104 79.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Copyright (C) 2000  The PARI group.
       2             : 
       3             : This file is part of the PARI/GP package.
       4             : 
       5             : PARI/GP is free software; you can redistribute it and/or modify it under the
       6             : terms of the GNU General Public License as published by the Free Software
       7             : Foundation. It is distributed in the hope that it will be useful, but WITHOUT
       8             : ANY WARRANTY WHATSOEVER.
       9             : 
      10             : Check the License for details. You should have received a copy of it, along
      11             : with the package; see the file 'COPYING'. If not, write to the Free Software
      12             : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
      13             : 
      14             : /*******************************************************************/
      15             : /*                                                                 */
      16             : /*                         PLOT ROUTINES                           */
      17             : /*                                                                 */
      18             : /*******************************************************************/
      19             : #include "pari.h"
      20             : #include "paripriv.h"
      21             : #include "rect.h"
      22             : 
      23             : static void (*pari_get_plot)(PARI_plot *);
      24             : 
      25             : /* no need for THREAD: OK to share this */
      26             : static hashtable *rgb_colors = NULL;
      27             : 
      28             : THREAD PariRect rectgraph[18]; /*NUMRECT*/
      29             : static THREAD long current_color[18]; /*NUMRECT*/
      30             : 
      31             : static long plotpoint_itype = 0, rectline_itype  = 0;
      32             : 
      33             : const long NUMRECT = 18;
      34             : const long RECUR_MAXDEPTH = 10;
      35             : const double RECUR_PREC = 0.001;
      36             : const long DEFAULT_COLOR = 1, AXIS_COLOR = 2;
      37             : 
      38             : enum {
      39             :   ROt_MV = 1, /* Move */
      40             :   ROt_PT,  /* Point */
      41             :   ROt_LN,  /* Line */
      42             :   ROt_BX,  /* Box */
      43             :   ROt_FBX, /* Filled Box */
      44             :   ROt_MP,  /* Multiple point */
      45             :   ROt_ML,  /* Multiple lines */
      46             :   ROt_ST,  /* String */
      47             :   ROt_PTT,  /* Point type change */
      48             :   ROt_LNT,  /* Line type change */
      49             :   ROt_PTS,  /* Point size change */
      50             :   ROt_NULL, /* To be the start of the chain */
      51             : };
      52             : 
      53             : INLINE long
      54       47450 : DTOL(double t) { return (long)(t + 0.5); }
      55             : 
      56             : static const long PS_WIDTH = 1120 - 60; /* 1400 - 60 for hi-res */
      57             : static const long PS_HEIGH = 800 - 40; /* 1120 - 60 for hi-res */
      58             : 
      59             : static void
      60          58 : _psdraw_scale(PARI_plot *T, GEN w, GEN x, GEN y)
      61             : {
      62          58 :   pari_sp av = avma;
      63          58 :   FILE *F = fopen(current_psfile, "a");
      64          58 :   if (!F) pari_err_FILE("postscript file",current_psfile);
      65          58 :   fputs(rect2ps(w,x,y,T), F);
      66          58 :   fclose(F); avma = av;
      67          58 : }
      68             : static void
      69           0 : _psdraw(PARI_plot *T, GEN w, GEN x, GEN y)
      70           0 : { (void)T; _psdraw_scale(NULL,w,x,y); }
      71             : static void
      72          58 : pari_get_psplot(PARI_plot *T, long scale)
      73             : {
      74          58 :   T->width = PS_WIDTH;
      75          58 :   T->height= PS_HEIGH;
      76          58 :   T->fheight= 15;
      77          58 :   T->fwidth = 6;
      78          58 :   T->hunit = 5;
      79          58 :   T->vunit = 5;
      80          58 :   T->draw = scale? &_psdraw: &_psdraw_scale;
      81          58 : }
      82             : 
      83             : /********************************************************************/
      84             : /**                                                                **/
      85             : /**                      RECTPLOT FUNCTIONS                        **/
      86             : /**                                                                **/
      87             : /********************************************************************/
      88             : static void
      89           0 : get_plot_null(PARI_plot *T)
      90           0 : { (void)T; pari_err(e_MISC,"high resolution graphics disabled"); }
      91             : 
      92             : void
      93        1519 : pari_init_graphics(void) { pari_get_plot = &get_plot_null; }
      94             : 
      95             : void
      96        1517 : pari_set_plot_engine(void (*plot)(PARI_plot *))
      97             : {
      98             :   long n;
      99        1517 :   pari_get_plot = plot;
     100       28823 :   for (n = 0; n < NUMRECT; n++)
     101             :   {
     102       27306 :     PariRect *e = &rectgraph[n];
     103       27306 :     e->head = e->tail = NULL;
     104       27306 :     e->sizex = e->sizey = 0;
     105       27306 :     current_color[n] = DEFAULT_COLOR;
     106             :   }
     107        1517 : }
     108             : 
     109             : void
     110        1517 : pari_kill_plot_engine(void)
     111             : {
     112             :   int i;
     113       28823 :   for (i=0; i<NUMRECT; i++)
     114             :   {
     115       27306 :     PariRect *e = &rectgraph[i];
     116       27306 :     if (RHead(e)) plotkill(i);
     117             :   }
     118        1517 :   if (rgb_colors)
     119             :   {
     120          11 :     pari_free((void*)rgb_colors->table);
     121          11 :     pari_free((void*)rgb_colors);
     122             :   }
     123        1517 :   if (GP_DATA->colormap) pari_free(GP_DATA->colormap);
     124        1517 :   if (GP_DATA->graphcolors) pari_free(GP_DATA->graphcolors);
     125        1517 : }
     126             : 
     127             : static PariRect *
     128       22128 : check_rect(long ne)
     129             : {
     130       22128 :   const char *f = "graphic function";
     131       22128 :   const long m = NUMRECT-1;
     132       22128 :   if (ne < 0) pari_err_DOMAIN(f, "rectwindow", "<", gen_0, stoi(ne));
     133       22120 :   if (ne > m) pari_err_DOMAIN(f, "rectwindow", ">", stoi(m), stoi(ne));
     134       22116 :   return &rectgraph[ne];
     135             : }
     136             : 
     137             : static PariRect *
     138       21949 : check_rect_init(long ne)
     139             : {
     140       21949 :   PariRect *e = check_rect(ne);
     141       21941 :   if (!RHead(e)) pari_err_TYPE("graphic function [use plotinit()]", stoi(ne));
     142       21941 :   return e;
     143             : }
     144             : static void
     145       27961 : Rchain(PariRect *e, RectObj *z)
     146             : {
     147       27961 :   if (!RHead(e)) RHead(e) = z; else RoNext(RTail(e)) = z;
     148       27961 :   RTail(e) = z;
     149       27961 :   RoNext(z) = NULL;
     150       27961 : }
     151             : 
     152             : static void
     153         171 : initrect_i(long ne, long x, long y)
     154             : {
     155             :   PariRect *e;
     156             :   RectObj *z;
     157             : 
     158         171 :   if (x <= 1) pari_err_DOMAIN("plotinit", "x", "<=", gen_1, stoi(x));
     159         171 :   if (y <= 1) pari_err_DOMAIN("plotinit", "y", "<=", gen_1, stoi(y));
     160         171 :   e = check_rect(ne); if (RHead(e)) plotkill(ne);
     161             : 
     162         167 :   z = (RectObj*) pari_malloc(sizeof(RectObj));
     163         167 :   RoType(z) = ROt_NULL;
     164         167 :   Rchain(e, z);
     165         167 :   RXsize(e) = x; RXcursor(e) = 0; RXscale(e) = 1; RXshift(e) = 0;
     166         167 :   RYsize(e) = y; RYcursor(e) = 0; RYscale(e) = 1; RYshift(e) = 0;
     167         167 : }
     168             : static long
     169         106 : initrect_get_arg(GEN x, long dft)
     170             : {
     171         106 :   if (!x) return dft;
     172          50 :   if (typ(x) != t_INT) pari_err_TYPE("plotinit",x);
     173          50 :   return itos(x);
     174             : }
     175             : void
     176          53 : plotinit(long ne, GEN x, GEN y, long flag)
     177             : {
     178          53 :   const long m = NUMRECT-3;
     179             :   long xi, yi;
     180             :   PARI_plot T;
     181             : 
     182          53 :   if (flag)
     183             :   {
     184           0 :     pari_get_plot(&T);
     185           0 :     xi = T.width -1; if (x) xi = DTOL(xi * gtodouble(x));
     186           0 :     yi = T.height-1; if (y) yi = DTOL(yi * gtodouble(y));
     187             :   }
     188             :   else
     189             :   {
     190          53 :     if (!x || !y) pari_get_plot(&T);
     191          53 :     xi = initrect_get_arg(x, T.width -1);
     192          53 :     yi = initrect_get_arg(y, T.height-1);
     193             :   }
     194          53 :   if (ne > m) pari_err_DOMAIN("plotinit", "rectwindow", ">", stoi(m), stoi(ne));
     195          49 :   initrect_i(ne, xi, yi);
     196          45 : }
     197             : 
     198             : GEN
     199          47 : plotcursor(long ne)
     200             : {
     201          47 :   PariRect *e = check_rect_init(ne);
     202          47 :   return mkvec2s((long)RXcursor(e), (long)RYcursor(e));
     203             : }
     204             : 
     205             : static void
     206          72 : plotscale0(long ne, double x1, double x2, double y1, double y2)
     207             : {
     208          72 :   PariRect *e = check_rect_init(ne);
     209             :   double x, y;
     210             : 
     211          72 :   x = RXshift(e) + RXscale(e) * RXcursor(e);
     212          72 :   y = RYshift(e) + RYscale(e) * RYcursor(e);
     213          72 :   RXscale(e) = RXsize(e)/(x2-x1); RXshift(e) = -x1*RXscale(e);
     214          72 :   RYscale(e) = RYsize(e)/(y1-y2); RYshift(e) = -y2*RYscale(e);
     215          72 :   RXcursor(e) = (x - RXshift(e)) / RXscale(e);
     216          72 :   RYcursor(e) = (y - RYshift(e)) / RYscale(e);
     217          72 : }
     218             : void
     219          11 : plotscale(long ne, GEN x1, GEN x2, GEN y1, GEN y2)
     220          11 : { plotscale0(ne, gtodouble(x1), gtodouble(x2), gtodouble(y1), gtodouble(y2)); }
     221             : 
     222             : static void
     223         501 : plotmove0(long ne, double x, double y, long relative)
     224             : {
     225         501 :   PariRect *e = check_rect_init(ne);
     226         493 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj1P));
     227             : 
     228         493 :   if (relative) { RXcursor(e) += x; RYcursor(e) += y; }
     229         482 :   else          { RXcursor(e) = x; RYcursor(e) = y; }
     230         493 :   RoType(z) = ROt_MV;
     231         493 :   RoMVx(z) = RXcursor(e) * RXscale(e) + RXshift(e);
     232         493 :   RoMVy(z) = RYcursor(e) * RYscale(e) + RYshift(e);
     233         493 :   Rchain(e, z);
     234         493 : }
     235             : void
     236          77 : plotmove(long ne, GEN x, GEN y)
     237          77 : { plotmove0(ne,gtodouble(x),gtodouble(y),0); }
     238             : void
     239          11 : plotrmove(long ne, GEN x, GEN y)
     240          11 : { plotmove0(ne,gtodouble(x),gtodouble(y),1); }
     241             : 
     242             : /* ROt_MV/ROt_PT */
     243             : static void
     244          22 : plotpoint0(long ne, double x, double y,long relative)
     245             : {
     246          22 :   PariRect *e = check_rect_init(ne);
     247          22 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj1P));
     248             : 
     249          22 :   if (relative) { RXcursor(e) += x; RYcursor(e) += y; }
     250          11 :   else          { RXcursor(e) = x; RYcursor(e) = y; }
     251          22 :   RoPTx(z) = RXcursor(e)*RXscale(e) + RXshift(e);
     252          22 :   RoPTy(z) = RYcursor(e)*RYscale(e) + RYshift(e);
     253          22 :   RoType(z) = ( DTOL(RoPTx(z)) < 0
     254          22 :                 || DTOL(RoPTy(z)) < 0 || DTOL(RoPTx(z)) > RXsize(e)
     255          22 :                 || DTOL(RoPTy(z)) > RYsize(e) ) ? ROt_MV : ROt_PT;
     256          22 :   Rchain(e, z);
     257          22 :   RoCol(z) = current_color[ne];
     258          22 : }
     259             : static void
     260          11 : plotpoint(long ne, GEN x, GEN y)
     261          11 : { plotpoint0(ne,gtodouble(x),gtodouble(y),0); }
     262             : void
     263          11 : plotrpoint(long ne, GEN x, GEN y)
     264          11 : { plotpoint0(ne,gtodouble(x),gtodouble(y),1); }
     265             : 
     266             : void
     267           8 : plotcolor(long ne, long c)
     268             : {
     269           8 :   long n = lg(GP_DATA->colormap)-2;
     270           8 :   check_rect(ne);
     271           8 :   if (c < 0) pari_err_DOMAIN("plotcolor", "color", "<", gen_0, stoi(c));
     272           8 :   if (c > n) pari_err_DOMAIN("plotcolor", "color", ">", stoi(n), stoi(c));
     273           8 :   current_color[ne] = c;
     274           8 : }
     275             : 
     276             : /* ROt_MV/ROt_LN */
     277             : static void
     278         130 : rectline0(long ne, double gx2, double gy2, long relative)
     279             : {
     280             :   double dx, dy, dxy, xmin, xmax, ymin, ymax, x1, y1, x2, y2;
     281         130 :   PariRect *e = check_rect_init(ne);
     282         130 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj2P));
     283         130 :   const double c = 1 + 1e-10;
     284             : 
     285         130 :   x1 = RXcursor(e)*RXscale(e) + RXshift(e);
     286         130 :   y1 = RYcursor(e)*RYscale(e) + RYshift(e);
     287         130 :   if (relative)
     288          11 :     { RXcursor(e)+=gx2; RYcursor(e)+=gy2; }
     289             :   else
     290         119 :     { RXcursor(e)=gx2; RYcursor(e)=gy2; }
     291         130 :   x2 = RXcursor(e)*RXscale(e) + RXshift(e);
     292         130 :   y2 = RYcursor(e)*RYscale(e) + RYshift(e);
     293         130 :   xmin = maxdd(mindd(x1,x2),0); xmax = mindd(maxdd(x1,x2),RXsize(e));
     294         130 :   ymin = maxdd(mindd(y1,y2),0); ymax = mindd(maxdd(y1,y2),RYsize(e));
     295         130 :   dxy = x1*y2 - y1*x2; dx = x2-x1; dy = y2-y1;
     296         130 :   if (dy)
     297             :   {
     298          76 :     double a = (dxy + RYsize(e)*dx) / dy, b = dxy / dy;
     299          76 :     if (dx*dy < 0)
     300          11 :     { xmin=maxdd(xmin,a); xmax=mindd(xmax,b); }
     301             :     else
     302          65 :     { xmin=maxdd(xmin,b); xmax=mindd(xmax,a); }
     303             :   }
     304         130 :   if (dx)
     305             :   {
     306          76 :     double a = (RXsize(e)*dy - dxy) / dx, b = -dxy / dx;
     307          76 :     if (dx*dy < 0)
     308          11 :     { ymin=maxdd(ymin,a); ymax=mindd(ymax,b); }
     309             :     else
     310          65 :     { ymin=maxdd(ymin,b); ymax=mindd(ymax,a); }
     311             :   }
     312         130 :   RoLNx1(z) = xmin;
     313         130 :   RoLNx2(z) = xmax;
     314         130 :   if (dx*dy < 0) { RoLNy1(z) = ymax; RoLNy2(z) = ymin; }
     315         119 :   else         { RoLNy1(z) = ymin; RoLNy2(z) = ymax; }
     316         130 :   RoType(z) = (xmin>xmax*c || ymin>ymax*c) ? ROt_MV : ROt_LN;
     317         130 :   Rchain(e, z);
     318         130 :   RoCol(z) = current_color[ne];
     319         130 : }
     320             : void
     321          11 : plotline(long ne, GEN gx2, GEN gy2)
     322          11 : { rectline0(ne, gtodouble(gx2), gtodouble(gy2),0); }
     323             : void
     324          11 : plotrline(long ne, GEN gx2, GEN gy2)
     325          11 : { rectline0(ne, gtodouble(gx2), gtodouble(gy2),1); }
     326             : 
     327             : enum {
     328             :   TICKS_CLOCKW   = 1, /* Draw in clockwise direction */
     329             :   TICKS_ACLOCKW  = 2, /* Draw in anticlockwise direction */
     330             :   TICKS_ENDSTOO  = 4, /* Draw at endspoints if needed */
     331             :   TICKS_NODOUBLE = 8  /* Do not draw double-length ticks */
     332             : };
     333             : 
     334             : /* Given coordinates of ends of a line, and labels l1 l2 attached to the
     335             :  * ends, plot ticks where the label coordinate takes "round" values */
     336             : static void
     337         244 : rectticks(PARI_plot *WW, long ne, double dx1, double dy1, double dx2,
     338             :           double dy2, double l1, double l2, long flags)
     339             : {
     340             :   long dx, dy, dxy, dxy1, x1, y1, x2, y2, nticks, n, n1, dn;
     341             :   double minstep, maxstep, step, l_min, l_max, minl, maxl, dl, dtx, dty, x, y;
     342             :   double ddx, ddy;
     343         244 :   const double mult[3] = { 2./1., 5./2., 10./5. };
     344         244 :   PariRect *e = check_rect_init(ne);
     345         244 :   int do_double = !(flags & TICKS_NODOUBLE);
     346             : 
     347         244 :   x1 = DTOL(dx1*RXscale(e) + RXshift(e));
     348         244 :   y1 = DTOL(dy1*RYscale(e) + RYshift(e));
     349         244 :   x2 = DTOL(dx2*RXscale(e) + RXshift(e));
     350         244 :   y2 = DTOL(dy2*RYscale(e) + RYshift(e));
     351         244 :   dx = x2 - x1; if (dx < 0) dx = -dx;
     352         244 :   dy = y2 - y1; if (dy < 0) dy = -dy;
     353         244 :   dxy1 = maxss(dx, dy);
     354         244 :   dx /= WW->hunit;
     355         244 :   dy /= WW->vunit;
     356         244 :   if (dx > 1000 || dy > 1000)
     357           0 :     dxy = 1000; /* avoid overflow */
     358             :   else
     359         244 :     dxy = usqrt(dx*dx + dy*dy);
     360         244 :   nticks = (long) ((dxy + 2.5)/4);
     361         244 :   if (!nticks) return;
     362             : 
     363             :   /* Find nticks (or less) "round" numbers between l1 and l2. For our purpose
     364             :    * round numbers have "last significant" decimal digit either
     365             :    *    - any;
     366             :    *    - even;
     367             :    *    - divisible by 5.
     368             :    * We need to choose which alternative is better. */
     369         244 :   if (l1 < l2)
     370         122 :     l_min = l1, l_max = l2;
     371             :   else
     372         122 :     l_min = l2, l_max = l1;
     373         244 :   minstep = (l_max - l_min)/(nticks + 1);
     374         244 :   maxstep = 2.5*(l_max - l_min);
     375         244 :   step = exp(log(10.) * floor(log10(minstep)));
     376         244 :   if (!(flags & TICKS_ENDSTOO)) {
     377         244 :     double d = 2*(l_max - l_min)/dxy1; /* Two pixels off */
     378         244 :     l_min += d;
     379         244 :     l_max -= d;
     380             :   }
     381         740 :   for (n = 0; ; n++)
     382             :   {
     383         740 :     if (step >= maxstep) return;
     384             : 
     385         740 :     if (step >= minstep) {
     386         244 :       minl = ceil(l_min/step);
     387         244 :       maxl = floor(l_max/step);
     388         244 :       if (minl <= maxl && maxl - minl + 1 <= nticks) {
     389         244 :         nticks = (long) (maxl - minl + 1);
     390         244 :         l_min = minl * step;
     391         244 :         l_max = maxl * step; break;
     392             :       }
     393             :     }
     394         496 :     step *= mult[ n % 3 ];
     395         496 :   }
     396             :   /* Where to position doubleticks. Variants:
     397             :    * small: each 5, double: each 10  ; n=2 mod 3
     398             :    * small: each 2, double: each 10  ; n=1 mod 3
     399             :    * small: each 1, double: each  5 */
     400         244 :   dn = (n % 3 == 2)? 2: 5;
     401         244 :   n1 = ((long)minl) % dn; /* unused if do_double = FALSE */
     402             : 
     403             :   /* now l_min and l_max keep min/max values of l with ticks, and nticks is
     404             :      the number of ticks to draw. */
     405         244 :   if (nticks == 1) ddx = ddy = 0; /* -Wall */
     406             :   else {
     407         244 :     dl = (l_max - l_min)/(nticks - 1);
     408         244 :     ddx = (dx2 - dx1) * dl / (l2 - l1);
     409         244 :     ddy = (dy2 - dy1) * dl / (l2 - l1);
     410             :   }
     411         244 :   x = dx1 + (dx2 - dx1) * (l_min - l1) / (l2 - l1);
     412         244 :   y = dy1 + (dy2 - dy1) * (l_min - l1) / (l2 - l1);
     413             :   /* assume hunit and vunit form a square. For clockwise ticks: */
     414         244 :   dtx = WW->hunit * dy/dxy * (y2 > y1 ? 1 : -1); /* y-coord runs down */
     415         244 :   dty = WW->vunit * dx/dxy * (x2 > x1 ? 1 : -1);
     416        6776 :   for (n = 0; n < nticks; n++, x += ddx, y += ddy) {
     417        6532 :     RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj2P));
     418        6532 :     double lunit = WW->hunit > 1 ? 1.5 : 2;
     419        6532 :     double l = (do_double && (n + n1) % dn == 0) ? lunit: 1;
     420             :     double x1, x2, y1, y2;
     421        6532 :     x1 = x2 = x*RXscale(e) + RXshift(e);
     422        6532 :     y1 = y2 = y*RYscale(e) + RYshift(e);
     423        6532 :     if (flags & TICKS_CLOCKW)  { x1 += dtx*l; y1 -= dty*l; }
     424        6532 :     if (flags & TICKS_ACLOCKW) { x2 -= dtx*l; y2 += dty*l; }
     425        6532 :     RoLNx1(z) = x1; RoLNy1(z) = y1;
     426        6532 :     RoLNx2(z) = x2; RoLNy2(z) = y2;
     427        6532 :     RoType(z) = ROt_LN;
     428        6532 :     Rchain(e, z);
     429        6532 :     RoCol(z) = current_color[ne];
     430             :   }
     431             : }
     432             : 
     433             : static void
     434          83 : rectbox0(long ne, double gx2, double gy2, long relative, long filled)
     435             : {
     436             :   double xx, yy, x1, y1, x2, y2, xmin, ymin, xmax, ymax;
     437          83 :   PariRect *e = check_rect_init(ne);
     438          83 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj2P));
     439             : 
     440          83 :   x1 = RXcursor(e)*RXscale(e) + RXshift(e);
     441          83 :   y1 = RYcursor(e)*RYscale(e) + RYshift(e);
     442          83 :   if (relative)
     443          11 :   { xx = RXcursor(e)+gx2; yy = RYcursor(e)+gy2; }
     444             :   else
     445          72 :   {  xx = gx2; yy = gy2; }
     446          83 :   x2 = xx*RXscale(e) + RXshift(e);
     447          83 :   y2 = yy*RYscale(e) + RYshift(e);
     448          83 :   xmin = maxdd(mindd(x1,x2),0); xmax = mindd(maxdd(x1,x2),RXsize(e));
     449          83 :   ymin = maxdd(mindd(y1,y2),0); ymax = mindd(maxdd(y1,y2),RYsize(e));
     450             : 
     451          83 :   RoType(z) = filled ? ROt_FBX: ROt_BX;
     452          83 :   RoBXx1(z) = xmin; RoBXy1(z) = ymin;
     453          83 :   RoBXx2(z) = xmax; RoBXy2(z) = ymax;
     454          83 :   Rchain(e, z);
     455          83 :   RoCol(z) = current_color[ne];
     456          83 : }
     457             : void
     458          11 : plotbox(long ne, GEN gx2, GEN gy2, long f)
     459          11 : { rectbox0(ne, gtodouble(gx2), gtodouble(gy2), 0, f); }
     460             : void
     461          11 : plotrbox(long ne, GEN gx2, GEN gy2, long f)
     462          11 : { rectbox0(ne, gtodouble(gx2), gtodouble(gy2), 1, f); }
     463             : 
     464             : static void
     465       28281 : freeobj(RectObj *z) {
     466       28281 :   switch(RoType(z)) {
     467             :     case ROt_MP: case ROt_ML:
     468       10095 :       pari_free(RoMPxs(z));
     469       10095 :       pari_free(RoMPys(z)); break;
     470             :     case ROt_ST:
     471         306 :       pari_free(RoSTs(z)); break;
     472             :   }
     473       28281 :   pari_free(z);
     474       28281 : }
     475             : 
     476             : void
     477         167 : plotkill(long ne)
     478             : {
     479             :   RectObj *z, *t;
     480         167 :   PariRect *e = check_rect_init(ne);
     481             : 
     482         167 :   current_color[ne]=DEFAULT_COLOR;
     483         167 :   z=RHead(e);
     484         167 :   RHead(e) = RTail(e) = NULL;
     485         167 :   RXsize(e) = RYsize(e) = 0;
     486         167 :   RXcursor(e) = RYcursor(e) = 0;
     487         167 :   RXscale(e) = RYscale(e) = 1;
     488         167 :   RXshift(e) = RYshift(e) = 0;
     489         167 :   while (z) { t = RoNext(z); freeobj(z); z = t; }
     490         167 : }
     491             : 
     492             : /* ROt_MP */
     493             : static void
     494          22 : plotpoints0(long ne, double *X, double *Y, long lx)
     495             : {
     496             :   double *px, *py;
     497          22 :   long i, cp=0;
     498          22 :   PariRect *e = check_rect_init(ne);
     499          22 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObjMP));
     500             : 
     501          22 :   RoMPxs(z) = px = (double*) pari_malloc(lx*sizeof(double));
     502          22 :   RoMPys(z) = py = (double*) pari_malloc(lx*sizeof(double));
     503        2836 :   for (i=0; i<lx; i++)
     504             :   {
     505        2814 :     double x = RXscale(e)*X[i] + RXshift(e);
     506        2814 :     double y = RYscale(e)*Y[i] + RYshift(e);
     507        2814 :     if (x >= 0 && y >= 0 && x <= RXsize(e) && y <= RYsize(e))
     508             :     {
     509        2813 :       px[cp] = x; py[cp] = y; cp++;
     510             :     }
     511             :   }
     512          22 :   RoType(z) = ROt_MP;
     513          22 :   RoMPcnt(z) = cp;
     514          22 :   Rchain(e, z);
     515          22 :   RoCol(z) = current_color[ne];
     516          22 : }
     517             : void
     518          22 : plotpoints(long ne, GEN X, GEN Y)
     519             : {
     520          22 :   pari_sp av = avma;
     521             :   double *px, *py;
     522             :   long i, lx;
     523             : 
     524          22 :   if (!is_vec_t(typ(X)) || !is_vec_t(typ(Y))) { plotpoint(ne, X, Y); return; }
     525          11 :   lx = lg(X); if (lg(Y) != lx) pari_err_DIM("plotpoints");
     526          11 :   lx--; if (!lx) return;
     527             : 
     528          11 :   px = (double*)stack_malloc_align(lx*sizeof(double), sizeof(double)); X++;
     529          11 :   py = (double*)stack_malloc_align(lx*sizeof(double), sizeof(double)); Y++;
     530         121 :   for (i=0; i<lx; i++)
     531             :   {
     532         110 :     px[i] = gtodouble(gel(X,i));
     533         110 :     py[i] = gtodouble(gel(Y,i));
     534             :   }
     535          11 :   plotpoints0(ne,px,py,lx); avma = av;
     536             : }
     537             : 
     538             : /* ROt_ML */
     539             : static void
     540       10033 : rectlines0(long ne, double *x, double *y, long lx, long flag)
     541             : {
     542             :   long i,I;
     543             :   double *ptx,*pty;
     544       10033 :   PariRect *e = check_rect_init(ne);
     545       10033 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObj2P));
     546             : 
     547       10033 :   I = flag ? lx+1 : lx;
     548       10033 :   ptx = (double*) pari_malloc(I*sizeof(double));
     549       10033 :   pty = (double*) pari_malloc(I*sizeof(double));
     550      168116 :   for (i=0; i<lx; i++)
     551             :   {
     552      158083 :     ptx[i] = RXscale(e)*x[i] + RXshift(e);
     553      158083 :     pty[i] = RYscale(e)*y[i] + RYshift(e);
     554             :   }
     555       10033 :   if (flag)
     556             :   {
     557           0 :     ptx[i] = RXscale(e)*x[0] + RXshift(e);
     558           0 :     pty[i] = RYscale(e)*y[0] + RYshift(e);
     559             :   }
     560       10033 :   Rchain(e, z);
     561       10033 :   RoType(z) = ROt_ML;
     562       10033 :   RoMLcnt(z) = lx;
     563       10033 :   RoMLxs(z) = ptx;
     564       10033 :   RoMLys(z) = pty;
     565       10033 :   RoCol(z) = current_color[ne];
     566       10033 : }
     567             : void
     568          22 : plotlines(long ne, GEN X, GEN Y, long flag)
     569             : {
     570          22 :   pari_sp av = avma;
     571             :   double *x, *y;
     572             :   long i, lx;
     573             : 
     574          22 :   if (!is_vec_t(typ(X)) || !is_vec_t(typ(Y))) { plotline(ne, X, Y); return; }
     575          11 :   lx = lg(X); if (lg(Y) != lx) pari_err_DIM("plotlines");
     576          11 :   lx--; if (!lx) return;
     577             : 
     578          11 :   x = (double*)stack_malloc_align(lx*sizeof(double), sizeof(double)); X++;
     579          11 :   y = (double*)stack_malloc_align(lx*sizeof(double), sizeof(double)); Y++;
     580          66 :   for (i=0; i<lx; i++)
     581             :   {
     582          55 :     x[i] = gtodouble(gel(X,i));
     583          55 :     y[i] = gtodouble(gel(Y,i));
     584             :   }
     585          11 :   rectlines0(ne,x,y,lx,flag); avma = av;
     586             : }
     587             : 
     588             : /* ROt_ST */
     589             : void
     590         266 : plotstring(long ne, char *str, long dir)
     591             : {
     592         266 :   PariRect *e = check_rect_init(ne);
     593         266 :   RectObj *z = (RectObj*) pari_malloc(sizeof(RectObjST));
     594         266 :   long l = strlen(str);
     595         266 :   char *s = (char *) pari_malloc(l+1);
     596             : 
     597         266 :   memcpy(s,str,l+1);
     598         266 :   RoType(z) = ROt_ST;
     599         266 :   RoSTl(z) = l;
     600         266 :   RoSTs(z) = s;
     601         266 :   RoSTx(z) = RXscale(e)*RXcursor(e)+RXshift(e);
     602         266 :   RoSTy(z) = RYscale(e)*RYcursor(e)+RYshift(e);
     603         266 :   RoSTdir(z) = dir;
     604         266 :   Rchain(e, z);
     605         266 :   RoCol(z) = current_color[ne];
     606         266 : }
     607             : 
     608             : /* ROt_PTT */
     609             : void
     610          11 : plotpointtype(long ne, long type)
     611             : {
     612          11 :  if (ne == -1) plotpoint_itype = type;
     613             :  else {
     614          11 :    PariRect *e = check_rect_init(ne);
     615          11 :    RectObj *z = (RectObj*) pari_malloc(sizeof(RectObjPN));
     616          11 :    RoType(z) = ROt_PTT;
     617          11 :    RoPTTpen(z) = type;
     618          11 :    Rchain(e, z);
     619             :  }
     620          11 : }
     621             : 
     622             : /* ROt_PTS. FIXME: this function is a noop, since no graphic driver implement
     623             :  * this code. ne == -1 (change globally). */
     624             : void
     625           0 : plotpointsize(long ne, GEN size)
     626             : {
     627           0 :  if (ne == -1) { /*do nothing*/ }
     628             :  else {
     629           0 :    PariRect *e = check_rect_init(ne);
     630           0 :    RectObj *z = (RectObj*) pari_malloc(sizeof(RectObjPS));
     631           0 :    RoType(z) = ROt_PTS;
     632           0 :    RoPTSsize(z) = gtodouble(size);
     633           0 :    Rchain(e, z);
     634             :  }
     635           0 : }
     636             : 
     637             : void
     638       10202 : plotlinetype(long ne, long type)
     639             : {
     640       10202 :  if (ne == -1) rectline_itype = type;
     641             :  else {
     642       10202 :    PariRect *e = check_rect_init(ne);
     643       10202 :    RectObj *z = (RectObj*) pari_malloc(sizeof(RectObjPN));
     644       10202 :    RoType(z) = ROt_LNT;
     645       10202 :    RoLNTpen(z) = type;
     646       10202 :    Rchain(e, z);
     647             :  }
     648       10202 : }
     649             : 
     650             : static double*
     651           0 : cpd(double* R, size_t t)
     652           0 : { void *o = pari_malloc(t * sizeof(double)); memcpy(o,R,t); return (double*)o; }
     653             : static void*
     654         460 : cp(void* R, size_t t)
     655         460 : { void *o = pari_malloc(t); memcpy(o,R,t); return o; }
     656             : void
     657          36 : plotcopy(long source, long dest, GEN xoff, GEN yoff, long flag)
     658             : {
     659          36 :   PariRect *s = check_rect_init(source), *d = check_rect_init(dest);
     660          36 :   RectObj *R, *tail = RTail(d);
     661             :   long i, x, y;
     662          36 :   if (flag & RECT_CP_RELATIVE) {
     663          32 :     double xd = gtodouble(xoff), yd = gtodouble(yoff);
     664             :     PARI_plot T;
     665          32 :     if (xd > 1) pari_err_DOMAIN("plotcopy","dx",">",gen_1,xoff);
     666          28 :     if (xd < 0) pari_err_DOMAIN("plotcopy","dx","<",gen_0,xoff);
     667          24 :     if (yd > 1) pari_err_DOMAIN("plotcopy","dy",">",gen_1,yoff);
     668          20 :     if (yd < 0) pari_err_DOMAIN("plotcopy","dy","<",gen_0,yoff);
     669          16 :     pari_get_plot(&T);
     670          16 :     x = DTOL(xd * (T.width-1));
     671          16 :     y = DTOL(yd * (T.height-1));
     672             :   } else {
     673           4 :     if (typ(xoff) != t_INT) pari_err_TYPE("plotcopy",xoff);
     674           4 :     if (typ(yoff) != t_INT) pari_err_TYPE("plotcopy",yoff);
     675           4 :     x = itos(xoff);
     676           4 :     y = itos(yoff);
     677             :   }
     678          20 :   switch (flag & ~RECT_CP_RELATIVE)
     679             :   {
     680           8 :     case RECT_CP_NW: break;
     681           4 :     case RECT_CP_SW: y = RYsize(d) - RYsize(s) - y; break;
     682           4 :     case RECT_CP_SE: y = RYsize(d) - RYsize(s) - y; /* fall through */
     683           8 :     case RECT_CP_NE: x = RXsize(d) - RXsize(s) - x; break;
     684             :   }
     685         360 :   for (R = RHead(s); R; R = RoNext(R))
     686             :   {
     687             :     RectObj *o;
     688         340 :     switch(RoType(R))
     689             :     {
     690             :       case ROt_PT:
     691          40 :         o = (RectObj*)cp(R, sizeof(RectObj1P));
     692          40 :         RoPTx(o) += x; RoPTy(o) += y;
     693          40 :         break;
     694             :       case ROt_LN: case ROt_BX: case ROt_FBX:
     695          80 :         o = (RectObj*)cp(R, sizeof(RectObj2P));
     696          80 :         RoLNx1(o) += x; RoLNy1(o) += y;
     697          80 :         RoLNx2(o) += x; RoLNy2(o) += y;
     698          80 :         break;
     699             :       case ROt_MP: case ROt_ML:
     700          40 :         o = (RectObj*)cp(R, sizeof(RectObjMP));
     701          40 :         RoMPxs(o) = (double*)cp(RoMPxs(R), sizeof(double)*RoMPcnt(o));
     702          40 :         RoMPys(o) = (double*)cp(RoMPys(R), sizeof(double)*RoMPcnt(o));
     703          40 :         for (i=0; i<RoMPcnt(o); i++) { RoMPxs(o)[i] += x; RoMPys(o)[i] += y; }
     704          40 :         break;
     705             :       case ROt_ST:
     706          40 :         o = (RectObj*)cp(R, sizeof(RectObjST));
     707          40 :         RoSTs(o) = (char*)cp(RoSTs(R),RoSTl(R)+1);
     708          40 :         RoSTx(o) += x; RoSTy(o) += y;
     709          40 :         break;
     710             :       default: /* ROt_PTT, ROt_LNT, ROt_PTS */
     711         140 :         o = (RectObj*)cp(R, sizeof(RectObjPN));
     712         140 :         break;
     713             :     }
     714         340 :     RoNext(tail) = o; tail = o;
     715             :   }
     716          20 :   RoNext(tail) = NULL; RTail(d) = tail;
     717          20 : }
     718             : 
     719             : enum {CLIPLINE_NONEMPTY = 1, CLIPLINE_CLIP_1 = 2, CLIPLINE_CLIP_2 = 4};
     720             : /* A simpler way is to clip by 4 half-planes */
     721             : static int
     722         120 : clipline(double xmin, double xmax, double ymin, double ymax,
     723             :          double *x1p, double *y1p, double *x2p, double *y2p)
     724             : {
     725         120 :   int xy_exch = 0, rc = CLIPLINE_NONEMPTY;
     726             :   double t, sl;
     727             :   double xi, xmn, xmx;
     728             :   double yi, ymn, ymx;
     729             :   int x1_is_ymn, x1_is_xmn;
     730         120 :   double x1 = *x1p, x2 = *x2p, y1 = *y1p, y2 = *y2p;
     731             : 
     732         120 :   if ((x1 < xmin &&  x2 < xmin) || (x1 > xmax && x2 > xmax))
     733          40 :     return 0;
     734          80 :   if (fabs(x1 - x2) < fabs(y1 - y2)) { /* Exchange x and y */
     735          24 :     xy_exch = 1;
     736          24 :     dswap(xmin, ymin); dswap(x1, y1);
     737          24 :     dswap(xmax, ymax); dswap(x2, y2);
     738             :   }
     739             : 
     740             :   /* Build y as a function of x */
     741          80 :   xi = x1;
     742          80 :   yi = y1;
     743          80 :   sl = x1==x2? 0: (y2 - yi)/(x2 - xi);
     744             : 
     745          80 :   if (x1 > x2) {
     746          24 :     x1_is_xmn = 0;
     747          24 :     xmn = x2;
     748          24 :     xmx = x1;
     749             :   } else {
     750          56 :     x1_is_xmn = 1;
     751          56 :     xmn = x1;
     752          56 :     xmx = x2;
     753             :   }
     754             : 
     755          80 :   if (xmn < xmin) {
     756           8 :     xmn = xmin;
     757           8 :     rc |= x1_is_xmn? CLIPLINE_CLIP_1: CLIPLINE_CLIP_2;
     758             :   }
     759          80 :   if (xmx > xmax) {
     760          12 :     xmx = xmax;
     761          12 :     rc |= x1_is_xmn? CLIPLINE_CLIP_2: CLIPLINE_CLIP_1;
     762             :   }
     763          80 :   if (xmn > xmx) return 0;
     764             : 
     765          80 :   ymn = yi + (xmn - xi)*sl;
     766          80 :   ymx = yi + (xmx - xi)*sl;
     767             : 
     768          80 :   if (sl < 0) t = ymn, ymn = ymx, ymx = t;
     769          80 :   if (ymn > ymax || ymx < ymin) return 0;
     770             : 
     771          80 :   if (rc & CLIPLINE_CLIP_1) x1 = x1_is_xmn? xmn: xmx;
     772          80 :   if (rc & CLIPLINE_CLIP_2) x2 = x1_is_xmn? xmx: xmn;
     773             : 
     774             :   /* Now we know there is an intersection, need to move x1 and x2 */
     775          80 :   x1_is_ymn = ((sl >= 0) == (x1 < x2));
     776          80 :   if (ymn < ymin) {
     777           4 :     double x = (ymin - yi)/sl + xi; /* slope != 0  ! */
     778           4 :     if (x1_is_ymn) x1 = x, rc |= CLIPLINE_CLIP_1;
     779           0 :     else           x2 = x, rc |= CLIPLINE_CLIP_2;
     780             :   }
     781          80 :   if (ymx > ymax) {
     782           4 :     double x = (ymax - yi)/sl + xi; /* slope != 0  ! */
     783           4 :     if (x1_is_ymn) x2 = x, rc |= CLIPLINE_CLIP_2;
     784           0 :     else           x1 = x, rc |= CLIPLINE_CLIP_1;
     785             :   }
     786          80 :   if (rc & CLIPLINE_CLIP_1) y1 = yi + (x1 - xi)*sl;
     787          80 :   if (rc & CLIPLINE_CLIP_2) y2 = yi + (x2 - xi)*sl;
     788          80 :   if (xy_exch) /* Exchange x and y */
     789          24 :     *x1p = y1, *x2p = y2, *y1p = x1, *y2p = x2;
     790             :   else
     791          56 :     *x1p = x1, *x2p = x2, *y1p = y1, *y2p = y2;
     792          80 :   return rc;
     793             : }
     794             : 
     795             : void
     796          20 : plotclip(long rect)
     797             : {
     798          20 :   PariRect *s = check_rect_init(rect);
     799          20 :   RectObj *next, *R = RHead(s), **prevp = &RHead(s);
     800          20 :   double xmin = 0, xmax = RXsize(s);
     801          20 :   double ymin = 0, ymax = RYsize(s);
     802             : 
     803         380 :   for (; R; R = next) {
     804         360 :     int did_clip = 0;
     805             : #define REMOVE() { *prevp = next; freeobj(R); break; }
     806             : #define NEXT() { prevp = &RoNext(R); break; }
     807             : 
     808         360 :     next = RoNext(R);
     809         360 :     switch(RoType(R)) {
     810             :       case ROt_PT:
     811          40 :         if ( DTOL(RoPTx(R)) < xmin || DTOL(RoPTx(R)) > xmax
     812          24 :           || DTOL(RoPTy(R)) < ymin || DTOL(RoPTy(R)) > ymax) REMOVE();
     813          24 :         NEXT();
     814             :       case ROt_BX: case ROt_FBX:
     815          40 :         if (RoLNx1(R) < xmin) RoLNx1(R) = xmin, did_clip = 1;
     816          40 :         if (RoLNx2(R) < xmin) RoLNx2(R) = xmin, did_clip = 1;
     817          40 :         if (RoLNy1(R) < ymin) RoLNy1(R) = ymin, did_clip = 1;
     818          40 :         if (RoLNy2(R) < ymin) RoLNy2(R) = ymin, did_clip = 1;
     819          40 :         if (RoLNx1(R) > xmax) RoLNx1(R) = xmax, did_clip = 1;
     820          40 :         if (RoLNx2(R) > xmax) RoLNx2(R) = xmax, did_clip = 1;
     821          40 :         if (RoLNy1(R) > ymax) RoLNy1(R) = ymax, did_clip = 1;
     822          40 :         if (RoLNy2(R) > ymax) RoLNy2(R) = ymax, did_clip = 1;
     823             :         /* Remove zero-size clipped boxes */
     824          40 :         if (did_clip && RoLNx1(R) == RoLNx2(R)
     825           8 :                      && RoLNy1(R) == RoLNy2(R)) REMOVE();
     826          36 :         NEXT();
     827             :       case ROt_LN:
     828          40 :         if (!clipline(xmin, xmax, ymin, ymax,
     829             :                       &RoLNx1(R), &RoLNy1(R),
     830           8 :                       &RoLNx2(R), &RoLNy2(R))) REMOVE();
     831          32 :         NEXT();
     832             :       case ROt_MP: {
     833          20 :         int c = RoMPcnt(R), f = 0, t = 0;
     834             : 
     835         240 :         while (f < c) {
     836         200 :           if ( DTOL(RoMPxs(R)[f]) >= xmin && DTOL(RoMPxs(R)[f]) <= xmax
     837         120 :             && DTOL(RoMPys(R)[f]) >= ymin && DTOL(RoMPys(R)[f]) <= ymax) {
     838         120 :             if (t != f) {
     839           0 :               RoMPxs(R)[t] = RoMPxs(R)[f];
     840           0 :               RoMPys(R)[t] = RoMPys(R)[f];
     841             :             }
     842         120 :             t++;
     843             :           }
     844         200 :           f++;
     845             :         }
     846          20 :         if (t == 0) REMOVE();
     847          12 :         RoMPcnt(R) = t;
     848          12 :         NEXT();
     849             :       }
     850             :       case ROt_ML: {
     851             :         /* Hard case. Break a multiline into several pieces
     852             :          * if some part is clipped. */
     853          20 :         int c = RoMPcnt(R) - 1;
     854          20 :         int f = 0, t = 0, had_lines = 0, had_hole = 0, rc;
     855          20 :         double ox = RoMLxs(R)[0], oy = RoMLys(R)[0], oxn, oyn;
     856             : 
     857         120 :         while (f < c) {
     858             :         /* Endpoint of this segment is startpoint of next one: need to
     859             :          * preserve it if it is clipped. */
     860          80 :           oxn = RoMLxs(R)[f+1];
     861          80 :           oyn = RoMLys(R)[f+1];
     862         160 :           rc = clipline(xmin, xmax, ymin, ymax,
     863             :                   &ox, &oy, /* &RoMLxs(R)[f], &RoMLys(R)[f], */
     864         160 :                   &RoMLxs(R)[f+1], &RoMLys(R)[f+1]);
     865          80 :           RoMLxs(R)[f] = ox; ox = oxn;
     866          80 :           RoMLys(R)[f] = oy; oy = oyn;
     867          80 :           if (!rc) {
     868          32 :             if (had_lines) had_hole = 1;
     869          32 :             f++; continue;
     870             :           }
     871             : 
     872          48 :           if (!had_lines || (!(rc & CLIPLINE_CLIP_1) && !had_hole) ) {
     873             :             /* Continuous */
     874          48 :             had_lines = 1;
     875          48 :             if (t != f) {
     876           0 :               if (t == 0) {
     877           0 :                 RoMPxs(R)[t] = RoMPxs(R)[f];
     878           0 :                 RoMPys(R)[t] = RoMPys(R)[f];
     879             :               }
     880           0 :               RoMPxs(R)[t+1] = RoMPxs(R)[f+1];
     881           0 :               RoMPys(R)[t+1] = RoMPys(R)[f+1];
     882             :             }
     883          48 :             t++;
     884          48 :             f++;
     885          48 :             if (rc & CLIPLINE_CLIP_2) had_hole = 1, RoMLcnt(R) = t+1;
     886          48 :             continue;
     887             :           }
     888             :           /* Is not continuous, automatically R is not pari_free()ed.  */
     889           0 :           t++;
     890           0 :           RoMLcnt(R) = t;
     891           0 :           if (rc & CLIPLINE_CLIP_2) { /* Needs separate entry */
     892           0 :             RectObj *n = (RectObj*) pari_malloc(sizeof(RectObj2P));
     893           0 :             RoType(n) = ROt_LN;
     894           0 :             RoCol(n) = RoCol(R);
     895           0 :             RoLNx1(n) = RoMLxs(R)[f];   RoLNy1(n) = RoMLys(R)[f];
     896           0 :             RoLNx2(n) = RoMLxs(R)[f+1]; RoLNy2(n) = RoMLys(R)[f+1];
     897           0 :             RoNext(n) = next;
     898           0 :             RoNext(R) = n;
     899             :             /* Restore the unclipped value: */
     900           0 :             RoMLxs(R)[f+1] = oxn; RoMLys(R)[f+1] = oyn;
     901           0 :             f++;
     902           0 :             prevp = &RoNext(n);
     903             :           }
     904           0 :           if (f + 1 < c) { /* Are other lines */
     905           0 :             RectObj *n = (RectObj*) pari_malloc(sizeof(RectObjMP));
     906           0 :             RoType(n) = ROt_ML;
     907           0 :             RoCol(n) = RoCol(R);
     908           0 :             RoMLcnt(n) = c - f;
     909           0 :             RoMLxs(n) = cpd(RoMPxs(R) + f, c-f);
     910           0 :             RoMLys(n) = cpd(RoMPys(R) + f, c-f);
     911           0 :             RoMPxs(n)[0] = oxn;
     912           0 :             RoMPys(n)[0] = oyn;
     913           0 :             RoNext(n) = next;
     914           0 :             RoNext(R) = n;
     915           0 :             next = n;
     916             :           }
     917           0 :           break;
     918             :         }
     919          20 :         if (t == 0) REMOVE();
     920          12 :         NEXT();
     921             :       }
     922             :     }
     923             : #undef REMOVE
     924             : #undef NEXT
     925             :   }
     926          20 : }
     927             : 
     928             : /********************************************************************/
     929             : /**                                                                **/
     930             : /**                        HI-RES PLOT                             **/
     931             : /**                                                                **/
     932             : /********************************************************************/
     933             : static void
     934      137976 : Appendx(dblPointList *f, dblPointList *l,double x)
     935             : {
     936      137976 :   (l->d)[l->nb++]=x;
     937      137976 :   if (x < f->xsml) f->xsml = x;
     938      137976 :   if (x > f->xbig) f->xbig = x;
     939      137976 : }
     940             : 
     941             : static void
     942      164976 : Appendy(dblPointList *f, dblPointList *l,double y)
     943             : {
     944      164976 :   (l->d)[l->nb++]=y;
     945      164976 :   if (y < f->ysml) f->ysml = y;
     946      164976 :   if (y > f->ybig) f->ybig = y;
     947      164976 : }
     948             : 
     949             : static void
     950      138192 : get_xy(long cplx, GEN t, double *x, double *y)
     951             : {
     952      138192 :   if (cplx)
     953             :   {
     954           0 :     if (typ(t) == t_VEC)
     955             :     {
     956           0 :       if (lg(t) != 2) pari_err_DIM("get_xy");
     957           0 :       t = gel(t,1);
     958             :     }
     959           0 :     *x = gtodouble( real_i(t) );
     960           0 :     *y = gtodouble( imag_i(t) );
     961             :   }
     962             :   else
     963             :   {
     964      138192 :     if (typ(t) != t_VEC || lg(t) != 3) pari_err_DIM("get_xy");
     965      138192 :     *x = gtodouble( gel(t,1) );
     966      138192 :     *y = gtodouble( gel(t,2) );
     967             :   }
     968      138192 : }
     969             : /* t a t_VEC (possibly a scalar if cplx), get next (x,y) coordinate starting
     970             :  * at index *i [update i] */
     971             : static void
     972        8056 : get_xy_from_vec(long cplx, GEN t, long *i, double *x, double *y)
     973             : {
     974        8056 :   if (cplx)
     975             :   {
     976             :     GEN z;
     977           0 :     if (typ(t) == t_VEC) z = gel(t,(*i)++); else { z = t; (*i)++; }
     978           0 :     *x = gtodouble( real_i(z) );
     979           0 :     *y = gtodouble( imag_i(z) );
     980             :   }
     981             :   else
     982             :   {
     983        8056 :     *x = gtodouble( gel(t, (*i)++) );
     984        8056 :     *y = gtodouble( gel(t, (*i)++) );
     985             :   }
     986        8056 : }
     987             : /* X,Y t_VEC, get next (x,y) coordinate starting at index i
     988             :  * Y ignored if (cplx) */
     989             : static void
     990        6712 : get_xy_from_vec2(long cplx, GEN X, GEN Y, long i, double *x, double *y)
     991             : {
     992        6712 :   if (cplx)
     993             :   {
     994           0 :     GEN z = gel(X,i);
     995           0 :     *x = gtodouble( real_i(z) );
     996           0 :     *y = gtodouble( imag_i(z) );
     997             :   }
     998             :   else
     999             :   {
    1000        6712 :     *x = gtodouble( gel(X, i) );
    1001        6712 :     *y = gtodouble( gel(Y, i) );
    1002             :   }
    1003        6712 : }
    1004             : 
    1005             : /* Convert data from GEN to double before we call plotrecthrawin. */
    1006             : static dblPointList*
    1007          19 : gtodblList(GEN data, long flags)
    1008             : {
    1009             :   dblPointList *l;
    1010             :   double xsml, xbig, ysml, ybig;
    1011          19 :   long nl=lg(data)-1, lx1, i, j;
    1012          19 :   const long param = (flags & (PLOT_PARAMETRIC|PLOT_COMPLEX));
    1013          19 :   const long cplx = (flags & PLOT_COMPLEX);
    1014             : 
    1015          19 :   if (! is_vec_t(typ(data))) pari_err_TYPE("gtodblList",data);
    1016          19 :   if (!nl) return NULL;
    1017          19 :   lx1 = lg(gel(data,1));
    1018          19 :   if (!param && lx1 == 1) return NULL;
    1019             : 
    1020          19 :   if (nl == 1 && !cplx) pari_err_DIM("gtodblList");
    1021             :   /* Allocate memory, then convert coord. to double */
    1022          19 :   l = (dblPointList*)pari_malloc((cplx? 2*nl: nl)*sizeof(dblPointList));
    1023          38 :   for (i=0; i<nl; i += (cplx? 1: 2))
    1024             :   {
    1025          19 :     dblPointList *LX = l + i, *LY = l + (i+1);
    1026          19 :     GEN x = gel(data,i+1), y;
    1027          19 :     long lx = lg(x);
    1028          19 :     if (!is_vec_t(typ(x))) pari_err_TYPE("gtodblList",x);
    1029          19 :     if (cplx) y = NULL;
    1030             :     else
    1031             :     {
    1032          19 :       y = gel(data,i+2);
    1033          19 :       if (!is_vec_t(typ(y))) pari_err_TYPE("gtodblList",y);
    1034          19 :       if (lg(y) != lx || (!param && lx != lx1)) pari_err_DIM("gtodblList");
    1035             :     }
    1036             : 
    1037          19 :     lx--;
    1038          19 :     LX->d = (double*)pari_malloc(lx*sizeof(double));
    1039          19 :     LY->d = (double*)pari_malloc(lx*sizeof(double));
    1040        6731 :     for (j=1; j<=lx; j++)
    1041             :     {
    1042             :       double xx, yy;
    1043        6712 :       get_xy_from_vec2(cplx, x,y, j, &xx,&yy);
    1044        6712 :       LX->d[j-1] = xx;
    1045        6712 :       LY->d[j-1] = yy;
    1046             :     }
    1047          19 :     LX->nb = LY->nb = lx;
    1048             :   }
    1049             : 
    1050             :   /* Now compute extremas */
    1051          19 :   if (param)
    1052             :   {
    1053          19 :     l[0].nb = cplx? nl: nl/2;
    1054          19 :     for (i=0; i < l[0].nb; i+=2)
    1055          19 :       if (l[i+1].nb) break;
    1056          19 :     if (i >= l[0].nb) { pari_free(l); return NULL; }
    1057          19 :     xsml = xbig = l[i  ].d[0];
    1058          19 :     ysml = ybig = l[i+1].d[0];
    1059          38 :     for (; i < l[0].nb; i+=2)
    1060             :     {
    1061          19 :       dblPointList *LX = l + i, *LY = l + (i+1);
    1062        6731 :       for (j=0; j < LY->nb; j++)
    1063             :       {
    1064        6712 :         double x = LX->d[j], y = LY->d[j];
    1065        6712 :         if (x < xsml) xsml = x; else if (x > xbig) xbig = x;
    1066        6712 :         if (y < ysml) ysml = y; else if (y > ybig) ybig = y;
    1067             :       }
    1068             :     }
    1069             :   }
    1070             :   else
    1071             :   {
    1072           0 :     l[0].nb = nl-1;
    1073           0 :     xsml = xbig = l[0].d[0];
    1074           0 :     ysml = ybig = l[1].d[0];
    1075           0 :     for (j=0; j < l[1].nb; j++)
    1076             :     {
    1077           0 :       double x = l[0].d[j];
    1078           0 :       if (x < xsml) xsml = x; else if (x > xbig) xbig = x;
    1079             :     }
    1080           0 :     for (i=1; i <= l[0].nb; i++)
    1081           0 :       for (j=0; j < l[i].nb; j++)
    1082             :       {
    1083           0 :         double y = l[i].d[j];
    1084           0 :         if (y < ysml) ysml = y; else if (y > ybig) ybig = y;
    1085             :       }
    1086             :   }
    1087          19 :   l[0].xsml = xsml; l[0].xbig = xbig;
    1088          19 :   l[0].ysml = ysml; l[0].ybig = ybig; return l;
    1089             : }
    1090             : 
    1091             : /* (x+y)/2 */
    1092             : static GEN
    1093      208940 : rmiddle(GEN x, GEN y) { GEN z = addrr(x,y); shiftr_inplace(z,-1); return z; }
    1094             : 
    1095             : static void
    1096       91404 : single_recursion(void *E, GEN(*eval)(void*,GEN), dblPointList *pl,
    1097             :                  GEN xleft,double yleft, GEN xright,double yright,long depth)
    1098             : {
    1099             :   GEN xx;
    1100       91404 :   pari_sp av = avma;
    1101       91404 :   double yy, dy=pl[0].ybig - pl[0].ysml;
    1102             : 
    1103       91404 :   if (depth==RECUR_MAXDEPTH) return;
    1104             : 
    1105       83124 :   xx = rmiddle(xleft,xright);
    1106       83124 :   yy = gtodouble(eval(E,xx));
    1107             : 
    1108       83124 :   if (dy && fabs(yleft+yright-2*yy)< dy*RECUR_PREC) return;
    1109       43708 :   single_recursion(E,eval, pl,xleft,yleft, xx,yy, depth+1);
    1110             : 
    1111       43708 :   Appendx(&pl[0],&pl[0],rtodbl(xx));
    1112       43708 :   Appendy(&pl[0],&pl[1],yy);
    1113             : 
    1114       43708 :   single_recursion(E,eval, pl,xx,yy, xright,yright, depth+1);
    1115       43708 :   avma = av;
    1116             : }
    1117             : 
    1118             : static void
    1119      138104 : param_recursion(void *E,GEN(*eval)(void*,GEN), long cplx, dblPointList *pl,
    1120             :   GEN tleft,double xleft, double yleft,
    1121             :   GEN tright,double xright,double yright, long depth)
    1122             : {
    1123             :   GEN tt, p1;
    1124      138104 :   pari_sp av=avma;
    1125      138104 :   double xx, dy=pl[0].ybig - pl[0].ysml;
    1126      138104 :   double yy, dx=pl[0].xbig - pl[0].xsml;
    1127             : 
    1128      210348 :   if (depth==RECUR_MAXDEPTH) return;
    1129             : 
    1130      125816 :   tt = rmiddle(tleft,tright);
    1131      125816 :   p1 = eval(E,tt);
    1132      125816 :   get_xy(cplx, p1, &xx,&yy);
    1133             : 
    1134      125816 :   if (dx && dy && fabs(xleft+xright-2*xx) < dx*RECUR_PREC
    1135       62848 :                && fabs(yleft+yright-2*yy) < dy*RECUR_PREC) return;
    1136       65860 :   param_recursion(E,eval, cplx, pl, tleft,xleft,yleft, tt,xx,yy, depth+1);
    1137             : 
    1138       65860 :   Appendx(&pl[0],&pl[0],xx);
    1139       65860 :   Appendy(&pl[0],&pl[1],yy);
    1140             : 
    1141       65860 :   param_recursion(E,eval,cplx, pl, tt,xx,yy, tright,xright,yright, depth+1);
    1142       65860 :   avma = av;
    1143             : }
    1144             : 
    1145             : /* Graph 'code' for parameter values in [a,b], using 'N' sample points
    1146             :  * (0 = use a default value); code is either a t_CLOSURE or a t_POL or a
    1147             :  * t_VEC of two t_POLs from rectsplines. Returns a dblPointList of
    1148             :  * (absolute) coordinates. */
    1149             : static dblPointList *
    1150       10034 : plotrecthin(void *E, GEN(*eval)(void*, GEN), GEN a, GEN b, ulong flags,
    1151             :             long N, long prec)
    1152             : {
    1153       10034 :   const double INF = 1.0/0.0;
    1154       10034 :   const long param = flags & (PLOT_PARAMETRIC|PLOT_COMPLEX);
    1155       10034 :   const long recur = flags & PLOT_RECURSIVE;
    1156       10034 :   const long cplx = flags & PLOT_COMPLEX;
    1157             :   GEN t,dx,x;
    1158             :   dblPointList *pl;
    1159       10034 :   long tx, i, j, sig, nc, nl, ncoords, nbpoints, non_vec = 0;
    1160       10034 :   pari_sp av = avma;
    1161             : 
    1162       10034 :   sig = gcmp(b,a); if (!sig) return NULL;
    1163       10034 :   if (sig < 0) swap(a, b);
    1164       10034 :   if (N == 1)
    1165           4 :     pari_err_DOMAIN("ploth", "#points", "<", gen_2, stoi(N));
    1166       10030 :   if (!N) N = recur? 8: (param? 1500: 1000);
    1167             :   /* compute F(a) to determine nc = #curves; nl = #coord. lists */
    1168       10030 :   x = gtofp(a, prec);
    1169       10030 :   t = eval(E, x); tx = typ(t);
    1170       10030 :   if (param)
    1171             :   {
    1172        6015 :     if (cplx) nc = nl = (tx == t_VEC)? lg(t)-1: 1;
    1173             :     else
    1174             :     {
    1175        6015 :       if (tx != t_VEC)
    1176           4 :         pari_err_TYPE("ploth [not a t_VEC with PLOT_PARAMETRIC]", t);
    1177        6011 :       nl = lg(t)-1;
    1178        6011 :       nc = nl/2;
    1179        6011 :       if (odd(nl))
    1180           0 :         pari_err_TYPE("ploth [parametric plot with odd # of components]",t);
    1181             :     }
    1182             :   }
    1183             :   else
    1184             :   {
    1185        4015 :     if (!is_matvec_t(tx)) { nl = 2; non_vec = 1; }
    1186             :     else
    1187             :     {
    1188           8 :       if (tx != t_VEC) pari_err_TYPE("ploth [not a t_VEC]",t);
    1189           8 :       nl = lg(t);
    1190             :     }
    1191        4015 :     nc = nl-1;
    1192             :   }
    1193       10026 :   if (!nc) { avma = av; return NULL; }
    1194       10026 :   if (recur && nc > 1)
    1195           4 :     pari_err_TYPE("ploth [multi-curves cannot be plot recursively]",t);
    1196             : 
    1197       10022 :   ncoords = cplx? 2*nl: nl;
    1198       10022 :   nbpoints = recur? N << RECUR_MAXDEPTH: N;
    1199       10022 :   pl=(dblPointList*) pari_malloc(ncoords*sizeof(dblPointList));
    1200             :   /* set [xy]sml,[xy]big to default values */
    1201       10022 :   if (param)
    1202             :   {
    1203        6011 :     pl[0].xsml = INF;
    1204        6011 :     pl[0].xbig =-INF;
    1205             :   } else {
    1206        4011 :     pl[0].xsml = gtodouble(a);
    1207        4011 :     pl[0].xbig = gtodouble(b);
    1208             :   }
    1209       10022 :   pl[0].ysml = INF;
    1210       10022 :   pl[0].ybig =-INF;
    1211       30070 :   for (i = 0; i < ncoords; i++)
    1212             :   {
    1213       20048 :     pl[i].d = (double*)pari_malloc((nbpoints+1)*sizeof(double));
    1214       20048 :     pl[i].nb=0;
    1215             :   }
    1216       10022 :   dx = divru(gtofp(gsub(b,a),prec), N-1);
    1217       10022 :   if (recur) /* recursive plot */
    1218             :   {
    1219        9980 :     double yleft, yright = 0;
    1220        9980 :     if (param)
    1221             :     {
    1222        5992 :       GEN tleft = cgetr(prec), tright = cgetr(prec);
    1223        5992 :       double xleft, xright = 0;
    1224        5992 :       pari_sp av2 = avma;
    1225        5992 :       affgr(a,tleft);
    1226        5992 :       t = eval(E, tleft);
    1227        5992 :       get_xy(cplx,t, &xleft,&yleft);
    1228       12376 :       for (i=0; i<N-1; i++, avma = av2)
    1229             :       {
    1230        6384 :         if (i) { affrr(tright,tleft); xleft = xright; yleft = yright; }
    1231        6384 :         addrrz(tleft,dx,tright);
    1232        6384 :         t = eval(E, tright);
    1233        6384 :         get_xy(cplx,t, &xright,&yright);
    1234        6384 :         Appendx(&pl[0],&pl[0],xleft);
    1235        6384 :         Appendy(&pl[0],&pl[1],yleft);
    1236        6384 :         param_recursion(E,eval, cplx, pl, tleft,xleft,yleft, tright,xright,yright, 0);
    1237             :       }
    1238        5992 :       Appendx(&pl[0],&pl[0],xright);
    1239        5992 :       Appendy(&pl[0],&pl[1],yright);
    1240             :     }
    1241             :     else /* single curve */
    1242             :     {
    1243        3988 :       GEN xleft = cgetr(prec), xright = cgetr(prec);
    1244        3988 :       pari_sp av2 = avma;
    1245        3988 :       affgr(a,xleft);
    1246        3988 :       yleft = gtodouble(eval(E,xleft));
    1247        7976 :       for (i=0; i<N-1; i++, avma = av2)
    1248             :       {
    1249        3988 :         addrrz(xleft,dx,xright);
    1250        3988 :         yright = gtodouble(eval(E,xright));
    1251             : 
    1252        3988 :         Appendx(&pl[0],&pl[0],rtodbl(xleft));
    1253        3988 :         Appendy(&pl[0],&pl[1],yleft);
    1254             : 
    1255        3988 :         single_recursion(E,eval, pl,xleft,yleft,xright,yright,0);
    1256        3988 :         affrr(xright,xleft); yleft = yright;
    1257             :       }
    1258        3988 :       Appendx(&pl[0],&pl[0],rtodbl(xright));
    1259        3988 :       Appendy(&pl[0],&pl[1],yright);
    1260             :     }
    1261             :   }
    1262             :   else /* non-recursive plot */
    1263             :   {
    1264          42 :     pari_sp av2 = avma;
    1265          42 :     if (param)
    1266             :     {
    1267        8075 :       for (i=0; i<N; i++, affrr(addrr(x,dx), x), avma = av2)
    1268             :       {
    1269             :         long k, nt;
    1270        8060 :         t = eval(E,x);
    1271        8060 :         if (typ(t) != t_VEC)
    1272             :         {
    1273           4 :           if (cplx) nt = 1;
    1274           4 :           else nt = 0; /* trigger error */
    1275             :         }
    1276             :         else
    1277        8056 :           nt = lg(t)-1;
    1278        8060 :         if (nt != nl) pari_err_DIM("plotrecth");
    1279        8056 :         k = 0; j = 1;
    1280       24168 :         while (j <= nl)
    1281             :         {
    1282             :           double xx, yy;
    1283        8056 :           get_xy_from_vec(cplx, t, &j, &xx, &yy);
    1284        8056 :           Appendx(&pl[0], &pl[k++], xx);
    1285        8056 :           Appendy(&pl[0], &pl[k++], yy);
    1286             :         }
    1287             :       }
    1288             :     }
    1289          23 :     else if (non_vec)
    1290       19019 :       for (i=0; i<N; i++, affrr(addrr(x,dx), x), avma = av2)
    1291             :       {
    1292       19000 :         t = eval(E,x);
    1293       19000 :         pl[0].d[i] = gtodouble(x);
    1294       19000 :         Appendy(&pl[0],&pl[1], gtodouble(t));
    1295             :       }
    1296             :     else /* vector of non-parametric curves */
    1297        4004 :       for (i=0; i<N; i++, affrr(addrr(x,dx), x), avma = av2)
    1298             :       {
    1299        4000 :         t = eval(E,x);
    1300        4000 :         if (typ(t) != t_VEC || lg(t) != nl) pari_err_DIM("plotrecth");
    1301        4000 :         pl[0].d[i] = gtodouble(x);
    1302        4000 :         for (j=1; j<nl; j++) Appendy(&pl[0],&pl[j], gtodouble(gel(t,j)));
    1303             :       }
    1304             :   }
    1305       10018 :   pl[0].nb = nc; avma = av; return pl;
    1306             : }
    1307             : 
    1308             : static GEN
    1309      234176 : spline_eval(void* E, GEN x) { return gsubst((GEN)E,0,x); }
    1310             : 
    1311             : /* Uses highlevel plotting functions to implement splines as
    1312             :    a low-level plotting function. */
    1313             : static void
    1314           8 : rectsplines(long ne, double *x, double *y, long lx, long flag)
    1315             : {
    1316             :   long i, j;
    1317           8 :   pari_sp av0 = avma;
    1318           8 :   GEN X = pol_x(0), xa = cgetg(lx+1, t_VEC), ya = cgetg(lx+1, t_VEC);
    1319             :   GEN tas, pol3;
    1320           8 :   long param = flag & PLOT_PARAMETRIC;
    1321           8 :   const long fl = param | PLOT_RECURSIVE | PLOT_NO_RESCALE | PLOT_NO_FRAME
    1322             :                         | PLOT_NO_AXE_Y | PLOT_NO_AXE_X;
    1323             : 
    1324           8 :   if (lx < 4) pari_err(e_MISC, "Too few points (%ld) for spline plot", lx);
    1325       10008 :   for (i = 1; i <= lx; i++) {
    1326       10000 :     gel(xa,i) = dbltor(x[i-1]);
    1327       10000 :     gel(ya,i) = dbltor(y[i-1]);
    1328             :   }
    1329           8 :   if (param) {
    1330           4 :     tas = new_chunk(4);
    1331           4 :     for (j = 1; j <= 4; j++) gel(tas,j-1) = utoipos(j);
    1332           4 :     pol3 = cgetg(3, t_VEC);
    1333             :   }
    1334             :   else
    1335           4 :     tas = pol3 = NULL; /* gcc -Wall */
    1336        9984 :   for (i = 0; i <= lx - 4; i++) {
    1337        9976 :     pari_sp av = avma;
    1338             : 
    1339        9976 :     xa++; ya++;
    1340        9976 :     if (param) {
    1341        5988 :       gel(pol3,1) = polint_i(tas, xa, X, 4, NULL);
    1342        5988 :       gel(pol3,2) = polint_i(tas, ya, X, 4, NULL);
    1343             :     } else {
    1344        3988 :       pol3 = polint_i(xa, ya, X, 4, NULL);
    1345        3988 :       tas = xa;
    1346             :     }
    1347             :     /* Start with 3 points */
    1348       19952 :     plotrecth((void*)pol3, &spline_eval, ne,
    1349             :                i== 0 ? gel(tas,0) : gel(tas,1),
    1350        9976 :                i==lx-4 ? gel(tas,3) : gel(tas,2),
    1351             :                fl, 2, DEFAULTPREC);
    1352        9976 :     avma = av;
    1353             :   }
    1354           8 :   avma = av0;
    1355           8 : }
    1356             : 
    1357             : static void
    1358         244 : put_label(long ne, long x, long y, double d, long dir)
    1359             : {
    1360             :   char c[16];
    1361         244 :   sprintf(c,"%.5g", d);
    1362         244 :   plotmove0(ne,(double)x,(double)y,0);
    1363         244 :   plotstring(ne, c, dir);
    1364         244 : }
    1365             : static void
    1366       20074 : set_range(double m, double M, double *sml, double *big)
    1367             : {
    1368       20074 :   if (M - m < 1.e-9)
    1369             :   {
    1370           0 :     double d = fabs(m)/10; if (!d) d = 0.1;
    1371           0 :     M += d; m -= d;
    1372             :   }
    1373       20074 :   *sml = m; *big = M;
    1374       20074 : }
    1375             : /* Plot a dblPointList. Complete with axes, bounding box, etc.
    1376             :  *
    1377             :  * data is an array of structs. Its meaning depends on flags :
    1378             :  *
    1379             :  * + data[0] contains global extremas, the number of curves to plot
    1380             :  *   (data[0].nb) and a list of doubles (first set of x-coordinates).
    1381             :  *
    1382             :  * + data[i].nb (i>0) contains the number of points in the list
    1383             :  *   data[i].d (hopefully, data[2i].nb=data[2i+1].nb when i>0...)
    1384             :  *
    1385             :  * + If flags contain PLOT_PARAMETRIC, the array length should be
    1386             :  *   even, and successive pairs (data[2i].d, data[2i+1].d) represent
    1387             :  *   curves to plot.
    1388             :  *
    1389             :  * + If there is no such flag, the first element is an array with
    1390             :  *   x-coordinates and the following ones contain y-coordinates.
    1391             :  * If grect >= 0, output to this rectwindow. Otherwise draw immediately to
    1392             :  * screen (grect=-1) or to PS file (grect=-2), using two drawing rectangles:
    1393             :  * one for labels, another for graphs.*/
    1394             : static GEN
    1395       10037 : plotrecthrawin(PARI_plot *W, long grect, dblPointList *data, long flags)
    1396             : {
    1397       10037 :   const long param = flags & (PLOT_PARAMETRIC|PLOT_COMPLEX);
    1398       10037 :   const long max_graphcolors = lg(GP_DATA->graphcolors)-1;
    1399       10037 :   const pari_sp av = avma;
    1400             :   dblPointList x, y;
    1401             :   double xsml, xbig, ysml, ybig;
    1402             :   long ltype, i, nc, w[3], wx[3], wy[3];
    1403             : 
    1404       10037 :   if (!data) return cgetg(1,t_VEC);
    1405       10037 :   x = data[0]; nc = x.nb;
    1406       10037 :   set_range(x.xsml, x.xbig, &xsml, &xbig);
    1407       10037 :   set_range(x.ysml, x.ybig, &ysml, &ybig);
    1408       10037 :   if (W)
    1409             :   { /* actual output; else output to rectwindow: no labels */
    1410          61 :     const long srect = NUMRECT-2;
    1411             :     long lm, rm, tm, bm;
    1412             :     /* left/right/top/bottom margin */
    1413          61 :     lm = W->fwidth*10;
    1414          61 :     rm = W->hunit-1;
    1415          61 :     tm = W->vunit-1;
    1416          61 :     bm = W->vunit+W->fheight-1;
    1417          61 :     w[0] = wx[0] = wy[0] = evaltyp(t_VECSMALL) | evallg(3);
    1418          61 :     w[1] = srect; wx[1] = 0;  wy[1] = 0;
    1419          61 :     w[2] = grect; wx[2] = lm; wy[2] = tm;
    1420             :    /* Window (width x height) is given in pixels, correct pixels are 0..n-1,
    1421             :     * whereas rect functions work with windows whose pixel range is [0,n] */
    1422          61 :     initrect_i(srect, W->width - 1, W->height - 1);
    1423          61 :     current_color[srect] = DEFAULT_COLOR;
    1424          61 :     initrect_i(grect, W->width - (lm+rm) - 1, W->height - (tm+bm) - 1);
    1425             :     /* draw labels on srect */
    1426          61 :     put_label(srect, lm, 0, ybig, RoSTdirRIGHT|RoSTdirHGAP|RoSTdirTOP);
    1427          61 :     put_label(srect, lm, W->height-bm, ysml, RoSTdirRIGHT|RoSTdirHGAP|RoSTdirVGAP);
    1428          61 :     put_label(srect, lm, W->height - bm, xsml, RoSTdirLEFT|RoSTdirTOP);
    1429          61 :     put_label(srect, W->width-rm-1, W->height-bm, xbig, RoSTdirRIGHT|RoSTdirTOP);
    1430             :   }
    1431       10037 :   if (!(flags & PLOT_NO_RESCALE))
    1432          61 :     plotscale0(grect, xsml, xbig, ysml, ybig);
    1433             : 
    1434       10037 :   if (!(flags & PLOT_NO_FRAME))
    1435             :   {
    1436          61 :     int do_double = (flags & PLOT_NODOUBLETICK) ? TICKS_NODOUBLE : 0;
    1437             :     PARI_plot T, *pl;
    1438          61 :     if (W) pl = W; else { pl = &T; pari_get_plot(pl); }
    1439             : 
    1440          61 :     plotlinetype(grect, -2); /* Frame. */
    1441          61 :     current_color[grect] = DEFAULT_COLOR;
    1442          61 :     plotmove0(grect,xsml,ysml,0);
    1443          61 :     rectbox0(grect,xbig,ybig,0,0);
    1444          61 :     if (!(flags & PLOT_NO_TICK_X)) {
    1445          61 :       rectticks(pl, grect, xsml, ysml, xbig, ysml, xsml, xbig,
    1446          61 :         TICKS_CLOCKW | do_double);
    1447          61 :       rectticks(pl, grect, xbig, ybig, xsml, ybig, xbig, xsml,
    1448          61 :         TICKS_CLOCKW | do_double);
    1449             :     }
    1450          61 :     if (!(flags & PLOT_NO_TICK_Y)) {
    1451          61 :       rectticks(pl, grect, xbig, ysml, xbig, ybig, ysml, ybig,
    1452          61 :         TICKS_CLOCKW | do_double);
    1453          61 :       rectticks(pl, grect, xsml, ybig, xsml, ysml, ybig, ysml,
    1454          61 :         TICKS_CLOCKW | do_double);
    1455             :     }
    1456             :   }
    1457             : 
    1458       10037 :   if (!(flags & PLOT_NO_AXE_Y) && (xsml<=0 && xbig >=0))
    1459             :   {
    1460          54 :     plotlinetype(grect, -1); /* Axes. */
    1461          54 :     current_color[grect] = AXIS_COLOR;
    1462          54 :     plotmove0(grect,0.0,ysml,0);
    1463          54 :     rectline0(grect,0.0,ybig,0);
    1464             :   }
    1465             : 
    1466       10037 :   if (!(flags & PLOT_NO_AXE_X) && (ysml<=0 && ybig >=0))
    1467             :   {
    1468          54 :     plotlinetype(grect, -1); /* Axes. */
    1469          54 :     current_color[grect] = AXIS_COLOR;
    1470          54 :     plotmove0(grect,xsml,0.0,0);
    1471          54 :     rectline0(grect,xbig,0.0,0);
    1472             :   }
    1473             : 
    1474       10037 :   if (param) {
    1475        6026 :     i = 0;
    1476        6026 :     flags |= PLOT_PARAMETRIC;
    1477        6026 :     flags &= (~PLOT_COMPLEX); /* turn COMPLEX to PARAMETRIC*/
    1478        4011 :   } else i = 1;
    1479       20078 :   for (ltype = 0; ltype < nc; ltype++)
    1480             :   {
    1481       10041 :     current_color[grect] = GP_DATA->graphcolors[1+(ltype%max_graphcolors)];
    1482       10041 :     if (param) x = data[i++];
    1483             : 
    1484       10041 :     y = data[i++];
    1485       10041 :     if (flags & (PLOT_POINTS_LINES|PLOT_POINTS)) {
    1486          11 :       plotlinetype(grect, plotpoint_itype + ltype); /* Graphs */
    1487          11 :       plotpointtype(grect,plotpoint_itype + ltype); /* Graphs */
    1488          11 :       plotpoints0(grect, x.d, y.d, y.nb);
    1489          11 :       if (!(flags & PLOT_POINTS_LINES)) continue;
    1490             :     }
    1491             : 
    1492       10030 :     if (flags & PLOT_SPLINES) {
    1493             :       /* rectsplines will call us back with ltype == 0 */
    1494           8 :       int old = rectline_itype;
    1495           8 :       rectline_itype = rectline_itype + ltype;
    1496           8 :       rectsplines(grect, x.d, y.d, y.nb, flags);
    1497           8 :       rectline_itype = old;
    1498             :     } else {
    1499       10022 :       plotlinetype(grect, rectline_itype + ltype); /* Graphs */
    1500       10022 :       rectlines0(grect, x.d, y.d, y.nb, 0);
    1501             :     }
    1502             :   }
    1503       10037 :   for (i--; i>=0; i--) pari_free(data[i].d);
    1504       10037 :   pari_free(data);
    1505             : 
    1506       10037 :   if (W)
    1507             :   {
    1508          61 :     W->draw(W, w,wx,wy);
    1509          61 :     plotkill(w[1]);
    1510          61 :     plotkill(w[2]);
    1511             :   }
    1512       10037 :   avma = av;
    1513       10037 :   retmkvec4(dbltor(xsml), dbltor(xbig), dbltor(ysml), dbltor(ybig));
    1514             : }
    1515             : 
    1516             : /*************************************************************************/
    1517             : /*                                                                       */
    1518             : /*                          HI-RES FUNCTIONS                             */
    1519             : /*                                                                       */
    1520             : /*************************************************************************/
    1521             : /* If T != NULL, draw using the attached graphic (using rectwindow ne as a temp)
    1522             :  * Else write to rectwindow 'ne'.
    1523             :  * Graph y=f(x), x=a..b, use n points */
    1524             : static GEN
    1525       10034 : plotrecth_i(void *E, GEN(*f)(void*,GEN), PARI_plot *T, long ne, GEN a,GEN b,
    1526             :             ulong flags,long n, long prec)
    1527             : {
    1528       10034 :   dblPointList *pl = plotrecthin(E,f, a,b, flags, n, prec);
    1529       10018 :   return plotrecthrawin(T, ne, pl, flags);
    1530             : }
    1531             : GEN
    1532        9976 : plotrecth(void *E, GEN(*f)(void*,GEN), long ne, GEN a,GEN b,
    1533             :           ulong flags, long n, long prec)
    1534        9976 : { return plotrecth_i(E,f, NULL, ne, a,b, flags, n, prec); }
    1535             : GEN
    1536           0 : plotrecth0(long ne, GEN a,GEN b,GEN code,ulong flags,long n, long prec)
    1537           0 : { EXPR_WRAP(code, plotrecth(EXPR_ARG, ne, a,b, flags, n, prec)); }
    1538             : GEN
    1539          40 : ploth(void *E, GEN(*f)(void*,GEN), GEN a, GEN b,long flags, long n, long prec)
    1540             : {
    1541          40 :   PARI_plot T; pari_get_plot(&T);
    1542          40 :   return plotrecth_i(E,f, &T, NUMRECT-1, a,b, flags,n, prec);
    1543             : }
    1544             : GEN
    1545          40 : ploth0(GEN a, GEN b, GEN code, long flags,long n, long prec)
    1546          40 : { EXPR_WRAP(code, ploth(EXPR_ARG, a,b,flags,n, prec)); }
    1547             : GEN
    1548          18 : psploth(void *E, GEN(*f)(void*,GEN), GEN a,GEN b, long flags, long n, long prec)
    1549             : {
    1550          18 :   PARI_plot T; pari_get_psplot(&T,0);
    1551          18 :   return plotrecth_i(E,f, &T, NUMRECT-1, a,b, flags,n, prec);
    1552             : }
    1553             : GEN
    1554          18 : psploth0(GEN a, GEN b, GEN code, long flags, long n, long prec)
    1555          18 : { EXPR_WRAP(code, psploth(EXPR_ARG, a, b, flags, n, prec)); }
    1556             : 
    1557             : /* Draw list of points */
    1558             : static GEN
    1559          19 : plotrecthraw_i(PARI_plot *T, long ne, GEN data, long flags)
    1560             : {
    1561          19 :   dblPointList *pl = gtodblList(data,flags);
    1562          19 :   return plotrecthrawin(T, ne, pl, flags);
    1563             : }
    1564             : static GEN
    1565          19 : plothraw_i(PARI_plot *T, GEN X, GEN Y, long flag)
    1566             : {
    1567          19 :   pari_sp av = avma;
    1568          19 :   switch (flag) {
    1569          11 :     case 0: flag = PLOT_PARAMETRIC|PLOT_POINTS; break;
    1570           8 :     case 1: flag = PLOT_PARAMETRIC; break;
    1571           0 :     default: flag |= PLOT_PARAMETRIC; break;
    1572             :   }
    1573          19 :   return gerepileupto(av, plotrecthraw_i(T, NUMRECT-1, mkvec2(X,Y), flag));
    1574             : }
    1575             : GEN
    1576           8 : plothraw(GEN X, GEN Y, long flags)
    1577           8 : { PARI_plot T; pari_get_plot(&T); return plothraw_i(&T, X, Y, flags); }
    1578             : GEN
    1579          11 : psplothraw(GEN X, GEN Y, long flags)
    1580          11 : { PARI_plot T; pari_get_psplot(&T,0); return plothraw_i(&T, X, Y, flags); }
    1581             : GEN
    1582           0 : plotrecthraw(long ne, GEN data, long flags)
    1583           0 : { return plotrecthraw_i(NULL, ne, data, flags); }
    1584             : 
    1585             : GEN
    1586           4 : plothsizes(long flag)
    1587             : {
    1588           4 :   GEN vect = cgetg(1+6,t_VEC);
    1589             :   PARI_plot T;
    1590             : 
    1591           4 :   pari_get_plot(&T);
    1592           4 :   gel(vect,1) = stoi(T.width);
    1593           4 :   gel(vect,2) = stoi(T.height);
    1594           4 :   if (flag) {
    1595           0 :     gel(vect,3) = dbltor(T.hunit*1.0/T.width);
    1596           0 :     gel(vect,4) = dbltor(T.vunit*1.0/T.height);
    1597           0 :     gel(vect,5) = dbltor(T.fwidth*1.0/T.width);
    1598           0 :     gel(vect,6) = dbltor(T.fheight*1.0/T.height);
    1599             :   } else {
    1600           4 :     gel(vect,3) = stoi(T.hunit);
    1601           4 :     gel(vect,4) = stoi(T.vunit);
    1602           4 :     gel(vect,5) = stoi(T.fwidth);
    1603           4 :     gel(vect,6) = stoi(T.fheight);
    1604             :   }
    1605           4 :   return vect;
    1606             : }
    1607             : 
    1608             : /*************************************************************************/
    1609             : /*                                                                       */
    1610             : /*                         POSTSCRIPT OUTPUT                             */
    1611             : /*                                                                       */
    1612             : /*************************************************************************/
    1613             : /* if flag is set, rescale wrt T */
    1614             : static void
    1615          57 : gendraw(PARI_plot *T, GEN wxy, long flag)
    1616             : {
    1617             :   long i, n;
    1618             :   GEN W, X, Y;
    1619             : 
    1620          57 :   if (typ(wxy) != t_VEC) pari_err_TYPE("plotdraw",wxy);
    1621         114 :   n = lg(wxy)-1; if (!n) return;
    1622          57 :   if (n%3) pari_err_DIM("plotdraw");
    1623          57 :   n = n/3;
    1624             :   /* malloc mandatory in case T->draw forks then pari_close() */
    1625          57 :   W = cgetalloc(t_VECSMALL, n+1); /* win number */
    1626          57 :   X = cgetalloc(t_VECSMALL, n+1);
    1627          57 :   Y = cgetalloc(t_VECSMALL, n+1); /* (x,y)-offset */
    1628         114 :   for (i=1; i<=n; i++)
    1629             :   {
    1630          57 :     GEN w = gel(wxy,3*i-2), x = gel(wxy,3*i-1), y = gel(wxy,3*i);
    1631          57 :     if (typ(w)!=t_INT) pari_err_TYPE("plotdraw",w);
    1632          57 :     if (flag) {
    1633           0 :       X[i] = DTOL(gtodouble(x)*(T->width - 1));
    1634           0 :       Y[i] = DTOL(gtodouble(y)*(T->height - 1));
    1635             :     } else {
    1636          57 :       X[i] = gtos(x);
    1637          57 :       Y[i] = gtos(y);
    1638             :     }
    1639          57 :     W[i] = itos(w); check_rect_init(W[i]);
    1640             :   }
    1641          57 :   T->draw(T,W,X,Y);
    1642          57 :   pari_free(W);
    1643          57 :   pari_free(X);
    1644          57 :   pari_free(Y);
    1645             : 
    1646             : }
    1647             : void
    1648          29 : psdraw(GEN wxy, long flag)
    1649          29 : { PARI_plot T; pari_get_psplot(&T,flag); gendraw(&T, wxy, flag); }
    1650             : void
    1651          28 : plotdraw(GEN wxy, long flag)
    1652          28 : { PARI_plot T; pari_get_plot(&T); gendraw(&T, wxy, flag); }
    1653             : 
    1654             : /* may be called after pari_close(): don't use the PARI stack */
    1655             : void
    1656          58 : gen_draw(struct plot_eng *eng, GEN w, GEN x, GEN y, double xs, double ys)
    1657             : {
    1658          58 :   void *data = eng->data;
    1659          58 :   long i, j, lw = lg(w);
    1660          58 :   long hgapsize = eng->pl->hunit, fheight = eng->pl->fheight;
    1661          58 :   long vgapsize = eng->pl->vunit,  fwidth = eng->pl->fwidth;
    1662          58 :   long numcolors = lg(GP_DATA->colormap)-1;
    1663         145 :   for(i = 1; i < lw; i++)
    1664             :   {
    1665          87 :     PariRect *e = &rectgraph[w[i]];
    1666             :     RectObj *R;
    1667          87 :     long x0 = x[i], y0 = y[i];
    1668        4812 :     for (R = RHead(e); R; R = RoNext(R))
    1669             :     {
    1670        4725 :       long col = minss(numcolors, RoCol(R));
    1671        4725 :       switch(RoType(R))
    1672             :       {
    1673             :       case ROt_PT:
    1674          29 :         eng->sc(data,col);
    1675          29 :         eng->pt(data, DTOL((RoPTx(R)+x0)*xs), DTOL((RoPTy(R)+y0)*ys));
    1676          29 :         break;
    1677             :       case ROt_LN:
    1678        3917 :         eng->sc(data,col);
    1679       11751 :         eng->ln(data, DTOL((RoLNx1(R)+x0)*xs), DTOL((RoLNy1(R)+y0)*ys),
    1680        7834 :                       DTOL((RoLNx2(R)+x0)*xs), DTOL((RoLNy2(R)+y0)*ys));
    1681        3917 :         break;
    1682             :       case ROt_BX:
    1683          69 :         eng->sc(data,col);
    1684         345 :         eng->bx(data,
    1685          69 :                 DTOL((RoBXx1(R)+x0)*xs),
    1686          69 :                 DTOL((RoBXy1(R)+y0)*ys),
    1687          69 :                 DTOL((RoBXx2(R)-RoBXx1(R))*xs),
    1688          69 :                 DTOL((RoBXy2(R)-RoBXy1(R))*ys));
    1689          69 :         break;
    1690             :       case ROt_FBX:
    1691           0 :         eng->sc(data,col);
    1692           0 :         eng->fb(data,
    1693           0 :                 DTOL((RoBXx1(R)+x0)*xs),
    1694           0 :                 DTOL((RoBXy1(R)+y0)*ys),
    1695           0 :                 DTOL((RoBXx2(R)-RoBXx1(R))*xs),
    1696           0 :                 DTOL((RoBXy2(R)-RoBXy1(R))*ys));
    1697           0 :         break;
    1698             :       case ROt_MP:
    1699             :         {
    1700          25 :           double *ptx = RoMPxs(R);
    1701          25 :           double *pty = RoMPys(R);
    1702          25 :           long     nb = RoMPcnt(R);
    1703          25 :           struct plot_points *points =
    1704          25 :             (struct plot_points *) pari_malloc(sizeof(*points)*nb);
    1705         904 :           for(j=0;j<nb;j++)
    1706             :           {
    1707         879 :             points[j].x = DTOL((ptx[j]+x0)*xs);
    1708         879 :             points[j].y = DTOL((pty[j]+y0)*ys);
    1709             :           }
    1710          25 :           eng->sc(data,col);
    1711          25 :           eng->mp(data, nb, points);
    1712          25 :           pari_free(points);
    1713          25 :           break;
    1714             :         }
    1715             :       case ROt_ML:
    1716             :         {
    1717          40 :           double *ptx = RoMLxs(R);
    1718          40 :           double *pty = RoMLys(R);
    1719          40 :           long     nb = RoMLcnt(R);
    1720          40 :           struct plot_points *points =
    1721          40 :             (struct plot_points *) pari_malloc(sizeof(*points)*nb);
    1722       13834 :           for(j=0;j<nb;j++)
    1723             :           {
    1724       13794 :             points[j].x = DTOL((ptx[j]+x0)*xs);
    1725       13794 :             points[j].y = DTOL((pty[j]+y0)*ys);
    1726             :           }
    1727          40 :           eng->sc(data,col);
    1728          40 :           eng->ml(data, nb, points);
    1729          40 :           pari_free(points);
    1730          40 :           break;
    1731             :         }
    1732             :       case ROt_ST:
    1733             :         {
    1734         138 :           long dir = RoSTdir(R);
    1735         138 :           long hjust = dir & RoSTdirHPOS_mask, hgap  = dir & RoSTdirHGAP;
    1736         138 :           long vjust = dir & RoSTdirVPOS_mask, vgap  = dir & RoSTdirVGAP;
    1737         138 :           char *text = RoSTs(R);
    1738         138 :           long x, y, l = RoSTl(R);
    1739         138 :           long shift = (hjust == RoSTdirLEFT ? 0 :
    1740             :               (hjust == RoSTdirRIGHT ? 2 : 1));
    1741         138 :           if (hgap) hgap = (hjust == RoSTdirLEFT) ? hgapsize : -hgapsize;
    1742         138 :           if (vgap) vgap = (vjust == RoSTdirBOTTOM) ? 2*vgapsize : -2*vgapsize;
    1743         138 :           if (vjust != RoSTdirBOTTOM)
    1744          87 :             vgap -= ((vjust == RoSTdirTOP) ? 2 : 1)*(fheight - 1);
    1745         138 :           x = DTOL((RoSTx(R) + x0 + hgap - (l * fwidth * shift)/2)*xs);
    1746         138 :           y = DTOL((RoSTy(R) + y0 - vgap/2)*ys);
    1747         138 :           eng->sc(data,col);
    1748         138 :           eng->st(data, x, y, text, l);
    1749         138 :           break;
    1750             :         }
    1751             :       default:
    1752         507 :         break;
    1753             :       }
    1754             :     }
    1755             :   }
    1756          58 : }
    1757             : 
    1758             : /*************************************************************************/
    1759             : /*                               SVG                                     */
    1760             : /*************************************************************************/
    1761             : 
    1762             : struct svg_data {
    1763             :   pari_str str;
    1764             :   char hexcolor[8];  /* "#rrggbb\0" */
    1765             : };
    1766             : #define data_str(d) (&((struct svg_data*)(d))->str)
    1767             : #define data_hexcolor(d) (((struct svg_data*)(d))->hexcolor)
    1768             : 
    1769             : static const char hexdigit[] = "0123456789abcdef";
    1770             : 
    1771             : /* Work with precision 1/scale */
    1772             : static const float SVG_SCALE = 1024.0;
    1773             : 
    1774             : static float
    1775           0 : svg_rescale(float x) { return x / SVG_SCALE; }
    1776             : 
    1777             : static void
    1778           0 : svg_point(void *data, long x, long y)
    1779             : {
    1780           0 :   pari_str *S = data_str(data);
    1781             : 
    1782           0 :   str_printf(S, "<circle cx='%.2f' cy='%.2f' r='0.5' ",
    1783           0 :     svg_rescale(x), svg_rescale(y));
    1784           0 :   str_printf(S, "style='fill:%s;stroke:none;'/>", data_hexcolor(data));
    1785           0 : }
    1786             : 
    1787             : static void
    1788           0 : svg_line(void *data, long x1, long y1, long x2, long y2)
    1789             : {
    1790           0 :   pari_str *S = data_str(data);
    1791             : 
    1792           0 :   str_printf(S, "<line x1='%.2f' y1='%.2f' x2='%.2f' y2='%.2f' ",
    1793           0 :     svg_rescale(x1), svg_rescale(y1), svg_rescale(x2), svg_rescale(y2));
    1794           0 :   str_printf(S, "style='fill:none;stroke:%s;'/>", data_hexcolor(data));
    1795           0 : }
    1796             : 
    1797             : static void
    1798           0 : svg_rect(void *data, long x, long y, long w, long h)
    1799             : {
    1800           0 :   pari_str *S = data_str(data);
    1801             : 
    1802           0 :   str_printf(S, "<rect x='%.2f' y='%.2f' width='%.2f' height='%.2f' ",
    1803           0 :     svg_rescale(x), svg_rescale(y), svg_rescale(w), svg_rescale(h));
    1804           0 :   str_printf(S, "style='fill:none;stroke:%s;'/>", data_hexcolor(data));
    1805           0 : }
    1806             : 
    1807             : static void
    1808           0 : svg_fillrect(void *data, long x, long y, long w, long h)
    1809             : {
    1810           0 :   pari_str *S = data_str(data);
    1811           0 :   const char * color = data_hexcolor(data);
    1812           0 :   str_printf(S, "<rect x='%.2f' y='%.2f' width='%.2f' height='%.2f' ",
    1813           0 :     svg_rescale(x), svg_rescale(y), svg_rescale(w), svg_rescale(h));
    1814           0 :   str_printf(S, "style='fill:%s;stroke:%s;'/>", color, color);
    1815           0 : }
    1816             : 
    1817             : static void
    1818           0 : svg_points(void *data, long nb, struct plot_points *p)
    1819             : {
    1820             :   long i;
    1821           0 :   for (i = 0; i < nb; i++)
    1822           0 :     svg_point(data, p[i].x, p[i].y);
    1823           0 : }
    1824             : 
    1825             : static void
    1826           0 : svg_color(void *data, long col)
    1827             : {
    1828             :   int r, g, b;
    1829           0 :   char *hexcolor = data_hexcolor(data);
    1830           0 :   color_to_rgb(gel(GP_DATA->colormap, col+1), &r, &g, &b);
    1831           0 :   hexcolor[0] = '#';
    1832           0 :   hexcolor[1] = hexdigit[r / 16];
    1833           0 :   hexcolor[2] = hexdigit[r & 15];
    1834           0 :   hexcolor[3] = hexdigit[g / 16];
    1835           0 :   hexcolor[4] = hexdigit[g & 15];
    1836           0 :   hexcolor[5] = hexdigit[b / 16];
    1837           0 :   hexcolor[6] = hexdigit[b & 15];
    1838           0 :   hexcolor[7] = '\0';
    1839           0 : }
    1840             : 
    1841             : static void
    1842           0 : svg_lines(void *data, long nb, struct plot_points *p)
    1843             : {
    1844             :   long i;
    1845           0 :   pari_str *S = data_str(data);
    1846             : 
    1847           0 :   str_printf(S, "<polyline points='");
    1848           0 :   for (i = 0; i < nb; i++)
    1849             :   {
    1850           0 :     if (i > 0) str_printf(S, " ");
    1851           0 :     str_printf(S, "%.2f,%.2f", svg_rescale(p[i].x), svg_rescale(p[i].y));
    1852             :   }
    1853           0 :   str_printf(S, "' style='fill:none;stroke:%s;'/>", data_hexcolor(data));
    1854           0 : }
    1855             : 
    1856             : static void
    1857           0 : svg_text(void *data, long x, long y, char *text, long numtext)
    1858             : {
    1859           0 :   pari_str *S = data_str(data);
    1860             :   (void)numtext;
    1861           0 :   str_printf(S, "<text x='%.5f' y='%.5f' font-size='%ld' style='fill:%s;'>%s</text>",
    1862           0 :     svg_rescale(x),svg_rescale(y), 12, data_hexcolor(data), text);
    1863           0 : }
    1864             : 
    1865             : static void
    1866           0 : svg_head(PARI_plot *T, pari_str *S)
    1867             : {
    1868           0 :   str_printf(S, "<svg width='%ld' height='%ld' version='1.1' xmlns='http://www.w3.org/2000/svg'>", T->width, T->height);
    1869           0 : }
    1870             : 
    1871             : static void
    1872           0 : svg_tail(pari_str *S)
    1873             : {
    1874           0 :   str_printf(S, "</svg>");
    1875           0 : }
    1876             : 
    1877             : static void
    1878           0 : pari_get_svgplot(PARI_plot *T)
    1879             : {
    1880           0 :   T->width   = 480;
    1881           0 :   T->height  = 320;
    1882           0 :   T->hunit   = 3;
    1883           0 :   T->vunit   = 3;
    1884           0 :   T->fwidth  = 9;
    1885           0 :   T->fheight = 12;
    1886           0 : }
    1887             : 
    1888             : char *
    1889           0 : rect2svg(GEN w, GEN x, GEN y, PARI_plot *T)
    1890             : {
    1891             :   struct plot_eng pl;
    1892             :   struct svg_data data;
    1893             :   PARI_plot U;
    1894             : 
    1895           0 :   str_init(&data.str, 1);
    1896           0 :   svg_color(&data, 0);
    1897           0 :   if (!T) { T = &U; pari_get_svgplot(T); }
    1898           0 :   pl.data = &data;
    1899           0 :   pl.sc = &svg_color;
    1900           0 :   pl.pt = &svg_point;
    1901           0 :   pl.ln = &svg_line;
    1902           0 :   pl.bx = &svg_rect;
    1903           0 :   pl.fb = &svg_fillrect;
    1904           0 :   pl.mp = &svg_points;
    1905           0 :   pl.ml = &svg_lines;
    1906           0 :   pl.st = &svg_text;
    1907           0 :   pl.pl = T;
    1908             : 
    1909           0 :   svg_head(T, &data.str);
    1910           0 :   gen_draw(&pl, w, x, y, SVG_SCALE, SVG_SCALE);
    1911           0 :   svg_tail(&data.str);
    1912             : 
    1913           0 :   return data.str.string;
    1914             : }
    1915             : 
    1916             : /*************************************************************************/
    1917             : /*                            POSTSCRIPT                                 */
    1918             : /*************************************************************************/
    1919             : static void
    1920        4218 : ps_sc(void *data, long col)
    1921             : {
    1922        4218 :   pari_str *S = (pari_str*)data;
    1923        4218 :   long l = lg(GP_DATA->colormap)-1;
    1924             :   int r, g, b;
    1925        4218 :   if (col >= l)
    1926             :   {
    1927           0 :     pari_warn(warner,"non-existent color: %ld", col);
    1928           0 :     col = l-1;
    1929             :   }
    1930        4218 :   color_to_rgb(gel(GP_DATA->colormap,col+1), &r, &g, &b);
    1931        4218 :   str_printf(S,"%.6f %.6f %.6f setrgbcolor\n", r/255., g/255., b/255.);
    1932        4218 : }
    1933             : 
    1934             : static void
    1935         908 : ps_point(void *data, long x, long y)
    1936             : {
    1937         908 :   pari_str *S = (pari_str*)data;
    1938         908 :   str_printf(S,"%ld %ld p\n",y,x);
    1939         908 : }
    1940             : 
    1941             : static void
    1942        3917 : ps_line(void *data, long x1, long y1, long x2, long y2)
    1943             : {
    1944        3917 :   pari_str *S = (pari_str*)data;
    1945        3917 :   str_printf(S,"%ld %ld m %ld %ld l\n",y1,x1,y2,x2);
    1946        3917 :   str_printf(S,"stroke\n");
    1947        3917 : }
    1948             : 
    1949             : static void
    1950          69 : ps_rect(void *data, long x, long y, long w, long h)
    1951             : {
    1952          69 :   pari_str *S = (pari_str*)data;
    1953          69 :   str_printf(S,"%ld %ld m %ld %ld l %ld %ld l %ld %ld l closepath stroke\n",
    1954             :              y,x, y,x+w, y+h,x+w, y+h,x);
    1955          69 : }
    1956             : 
    1957             : static void
    1958           0 : ps_fillrect(void *data, long x, long y, long w, long h)
    1959             : {
    1960           0 :   pari_str *S = (pari_str*)data;
    1961           0 :   str_printf(S,"%ld %ld m %ld %ld l %ld %ld l %ld %ld l closepath fill\n",
    1962             :              y,x, y,x+w, y+h,x+w, y+h,x);
    1963           0 : }
    1964             : 
    1965             : static void
    1966          25 : ps_points(void *data, long nb, struct plot_points *p)
    1967             : {
    1968             :   long i;
    1969          25 :   for (i=0; i<nb; i++) ps_point(data, p[i].x, p[i].y);
    1970          25 : }
    1971             : 
    1972             : static void
    1973          40 : ps_lines(void *data, long nb, struct plot_points *p)
    1974             : {
    1975          40 :   pari_str *S = (pari_str*)data;
    1976             :   long i;
    1977          40 :   str_printf(S,"%ld %ld m\n",p[0].y,p[0].x);
    1978          40 :   for (i=1; i<nb; i++) str_printf(S, "%ld %ld l\n", p[i].y, p[i].x);
    1979          40 :   str_printf(S,"stroke\n");
    1980          40 : }
    1981             : 
    1982             : static void
    1983         138 : ps_string(void *data, long x, long y, char *s, long length)
    1984             : {
    1985         138 :   pari_str *S = (pari_str*)data;
    1986             :   (void)length;
    1987         138 :   if (strpbrk(s, "(\\)")) {
    1988          11 :     str_printf(S,"(");
    1989          77 :     while (*s) {
    1990          55 :       if ( *s=='(' || *s==')' || *s=='\\' ) str_putc(S,'\\');
    1991          55 :       str_putc(S, *s);
    1992          55 :       s++;
    1993             :     }
    1994             :   } else
    1995         127 :     str_printf(S,"(%s", s);
    1996         138 :   str_printf(S,") %ld %ld m 90 rotate show -90 rotate\n", y, x);
    1997         138 : }
    1998             : 
    1999             : char *
    2000          58 : rect2ps_i(GEN w, GEN x, GEN y, PARI_plot *T, int plotps)
    2001             : {
    2002             :   struct plot_eng pl;
    2003             :   PARI_plot U;
    2004             :   pari_str S;
    2005          58 :   double xs = 0.65, ys = 0.65;
    2006          58 :   if (T) /* res wrt T dimens */
    2007             :   {
    2008          58 :     if (plotps)
    2009           0 :       xs = ys = 1;
    2010             :     else
    2011             :     {
    2012          58 :       xs *= ((double)PS_WIDTH) / T->width;
    2013          58 :       ys *= ((double)PS_HEIGH) / T->height;
    2014             :     }
    2015             :   }
    2016             :   else
    2017             :   {
    2018           0 :     T = &U; pari_get_psplot(T,0);
    2019             :   }
    2020          58 :   str_init(&S, 1);
    2021             :   /* Definitions taken from post terminal of Gnuplot. */
    2022          58 :   str_printf(&S, "%%!\n\
    2023             : 50 50 translate\n\
    2024             : /p {moveto 0 2 rlineto 2 0 rlineto 0 -2 rlineto closepath fill} def\n\
    2025             : /l {lineto} def\n\
    2026             : /m {moveto} def\n"
    2027          58 : "/Times-Roman findfont %ld scalefont setfont\n", DTOL(T->fheight * xs));
    2028             : 
    2029          58 :   pl.sc = &ps_sc;
    2030          58 :   pl.pt = &ps_point;
    2031          58 :   pl.ln = &ps_line;
    2032          58 :   pl.bx = &ps_rect;
    2033          58 :   pl.fb = &ps_fillrect;
    2034          58 :   pl.mp = &ps_points;
    2035          58 :   pl.ml = &ps_lines;
    2036          58 :   pl.st = &ps_string;
    2037          58 :   pl.pl = T;
    2038          58 :   pl.data = (void*)&S;
    2039             : 
    2040          58 :   if (plotps) str_printf(&S,"0 %ld translate -90 rotate\n", T->height - 50);
    2041          58 :   gen_draw(&pl, w, x, y, xs, ys);
    2042          58 :   str_puts(&S,"stroke showpage\n");
    2043          58 :   *S.cur = 0; return S.string;
    2044             : }
    2045             : char *
    2046          58 : rect2ps(GEN w, GEN x, GEN y, PARI_plot *T)
    2047          58 : { return rect2ps_i(w,x,y,T,0); }
    2048             : 
    2049             : void
    2050           0 : pari_plot_by_file(const char *env, const char *suf, const char *img)
    2051             : {
    2052           0 :   const char *cmd, *s = pari_unique_filename_suffix("plotfile", suf);
    2053           0 :   FILE *f = fopen(s, "w");
    2054           0 :   if (!f) pari_err_FILE("image file", s);
    2055           0 :   fputs(img, f); (void)fclose(f);
    2056           0 :   cmd = os_getenv(env);
    2057             : #ifdef GP_MIME_OPEN
    2058           0 :   if (!cmd) cmd = GP_MIME_OPEN;
    2059             : #else
    2060             :   if (!cmd) cmd = "open -W";
    2061             : #endif
    2062           0 :   cmd = pari_sprintf("%s \"%s\" 2>/dev/null", cmd, s);
    2063           0 :   gpsystem(cmd);
    2064           0 :   pari_unlink(s);
    2065           0 :   pari_free((char*)s);
    2066           0 : }
    2067             : 
    2068             : /*************************************************************************/
    2069             : /*                                                                       */
    2070             : /*                           RGB COLORS                                  */
    2071             : /*                                                                       */
    2072             : /*************************************************************************/
    2073             : /* generated from /etc/X11/rgb.txt by the following perl script
    2074             : #!/usr/bin/perl
    2075             : while(<>)
    2076             : {
    2077             :   ($hex, $name) = split(/\t\t/, $_);
    2078             :   $hex =~ s/^ +//; chomp($name); $name =~ s, *,,g;
    2079             :   $hex = sprintf("0x%02x%02x%02x", split(/\s+/, $hex));
    2080             :   $name = lc($name); next if ($done{$name});
    2081             :   $done{$name} = 1;
    2082             :   print "COL(\"$name\", $hex),\n";
    2083             : }
    2084             : */
    2085             : 
    2086             : #define COL(x,y) {(void*)x,(void*)y,0,NULL}
    2087             : static hashentry col_list[] = {
    2088             : COL("", 0x000000),
    2089             : COL("snow", 0xfffafa),
    2090             : COL("ghostwhite", 0xf8f8ff),
    2091             : COL("whitesmoke", 0xf5f5f5),
    2092             : COL("gainsboro", 0xdcdcdc),
    2093             : COL("floralwhite", 0xfffaf0),
    2094             : COL("oldlace", 0xfdf5e6),
    2095             : COL("linen", 0xfaf0e6),
    2096             : COL("antiquewhite", 0xfaebd7),
    2097             : COL("papayawhip", 0xffefd5),
    2098             : COL("blanchedalmond", 0xffebcd),
    2099             : COL("bisque", 0xffe4c4),
    2100             : COL("peachpuff", 0xffdab9),
    2101             : COL("navajowhite", 0xffdead),
    2102             : COL("moccasin", 0xffe4b5),
    2103             : COL("cornsilk", 0xfff8dc),
    2104             : COL("ivory", 0xfffff0),
    2105             : COL("lemonchiffon", 0xfffacd),
    2106             : COL("seashell", 0xfff5ee),
    2107             : COL("honeydew", 0xf0fff0),
    2108             : COL("mintcream", 0xf5fffa),
    2109             : COL("azure", 0xf0ffff),
    2110             : COL("aliceblue", 0xf0f8ff),
    2111             : COL("lavender", 0xe6e6fa),
    2112             : COL("lavenderblush", 0xfff0f5),
    2113             : COL("mistyrose", 0xffe4e1),
    2114             : COL("white", 0xffffff),
    2115             : COL("black", 0x000000),
    2116             : COL("darkslategray", 0x2f4f4f),
    2117             : COL("darkslategrey", 0x2f4f4f),
    2118             : COL("dimgray", 0x696969),
    2119             : COL("dimgrey", 0x696969),
    2120             : COL("slategray", 0x708090),
    2121             : COL("slategrey", 0x708090),
    2122             : COL("lightslategray", 0x778899),
    2123             : COL("lightslategrey", 0x778899),
    2124             : COL("gray", 0xbebebe),
    2125             : COL("grey", 0xbebebe),
    2126             : COL("lightgrey", 0xd3d3d3),
    2127             : COL("lightgray", 0xd3d3d3),
    2128             : COL("midnightblue", 0x191970),
    2129             : COL("navy", 0x000080),
    2130             : COL("navyblue", 0x000080),
    2131             : COL("cornflowerblue", 0x6495ed),
    2132             : COL("darkslateblue", 0x483d8b),
    2133             : COL("slateblue", 0x6a5acd),
    2134             : COL("mediumslateblue", 0x7b68ee),
    2135             : COL("lightslateblue", 0x8470ff),
    2136             : COL("mediumblue", 0x0000cd),
    2137             : COL("royalblue", 0x4169e1),
    2138             : COL("blue", 0x0000ff),
    2139             : COL("dodgerblue", 0x1e90ff),
    2140             : COL("deepskyblue", 0x00bfff),
    2141             : COL("skyblue", 0x87ceeb),
    2142             : COL("lightskyblue", 0x87cefa),
    2143             : COL("steelblue", 0x4682b4),
    2144             : COL("lightsteelblue", 0xb0c4de),
    2145             : COL("lightblue", 0xadd8e6),
    2146             : COL("powderblue", 0xb0e0e6),
    2147             : COL("paleturquoise", 0xafeeee),
    2148             : COL("darkturquoise", 0x00ced1),
    2149             : COL("mediumturquoise", 0x48d1cc),
    2150             : COL("turquoise", 0x40e0d0),
    2151             : COL("cyan", 0x00ffff),
    2152             : COL("lightcyan", 0xe0ffff),
    2153             : COL("cadetblue", 0x5f9ea0),
    2154             : COL("mediumaquamarine", 0x66cdaa),
    2155             : COL("aquamarine", 0x7fffd4),
    2156             : COL("darkgreen", 0x006400),
    2157             : COL("darkolivegreen", 0x556b2f),
    2158             : COL("darkseagreen", 0x8fbc8f),
    2159             : COL("seagreen", 0x2e8b57),
    2160             : COL("mediumseagreen", 0x3cb371),
    2161             : COL("lightseagreen", 0x20b2aa),
    2162             : COL("palegreen", 0x98fb98),
    2163             : COL("springgreen", 0x00ff7f),
    2164             : COL("lawngreen", 0x7cfc00),
    2165             : COL("green", 0x00ff00),
    2166             : COL("chartreuse", 0x7fff00),
    2167             : COL("mediumspringgreen", 0x00fa9a),
    2168             : COL("greenyellow", 0xadff2f),
    2169             : COL("limegreen", 0x32cd32),
    2170             : COL("yellowgreen", 0x9acd32),
    2171             : COL("forestgreen", 0x228b22),
    2172             : COL("olivedrab", 0x6b8e23),
    2173             : COL("darkkhaki", 0xbdb76b),
    2174             : COL("khaki", 0xf0e68c),
    2175             : COL("palegoldenrod", 0xeee8aa),
    2176             : COL("lightgoldenrodyellow", 0xfafad2),
    2177             : COL("lightyellow", 0xffffe0),
    2178             : COL("yellow", 0xffff00),
    2179             : COL("gold", 0xffd700),
    2180             : COL("lightgoldenrod", 0xeedd82),
    2181             : COL("goldenrod", 0xdaa520),
    2182             : COL("darkgoldenrod", 0xb8860b),
    2183             : COL("rosybrown", 0xbc8f8f),
    2184             : COL("indianred", 0xcd5c5c),
    2185             : COL("saddlebrown", 0x8b4513),
    2186             : COL("sienna", 0xa0522d),
    2187             : COL("peru", 0xcd853f),
    2188             : COL("burlywood", 0xdeb887),
    2189             : COL("beige", 0xf5f5dc),
    2190             : COL("wheat", 0xf5deb3),
    2191             : COL("sandybrown", 0xf4a460),
    2192             : COL("tan", 0xd2b48c),
    2193             : COL("chocolate", 0xd2691e),
    2194             : COL("firebrick", 0xb22222),
    2195             : COL("brown", 0xa52a2a),
    2196             : COL("darksalmon", 0xe9967a),
    2197             : COL("salmon", 0xfa8072),
    2198             : COL("lightsalmon", 0xffa07a),
    2199             : COL("orange", 0xffa500),
    2200             : COL("darkorange", 0xff8c00),
    2201             : COL("coral", 0xff7f50),
    2202             : COL("lightcoral", 0xf08080),
    2203             : COL("tomato", 0xff6347),
    2204             : COL("orangered", 0xff4500),
    2205             : COL("red", 0xff0000),
    2206             : COL("hotpink", 0xff69b4),
    2207             : COL("deeppink", 0xff1493),
    2208             : COL("pink", 0xffc0cb),
    2209             : COL("lightpink", 0xffb6c1),
    2210             : COL("palevioletred", 0xdb7093),
    2211             : COL("maroon", 0xb03060),
    2212             : COL("mediumvioletred", 0xc71585),
    2213             : COL("violetred", 0xd02090),
    2214             : COL("magenta", 0xff00ff),
    2215             : COL("violet", 0xee82ee),
    2216             : COL("plum", 0xdda0dd),
    2217             : COL("orchid", 0xda70d6),
    2218             : COL("mediumorchid", 0xba55d3),
    2219             : COL("darkorchid", 0x9932cc),
    2220             : COL("darkviolet", 0x9400d3),
    2221             : COL("blueviolet", 0x8a2be2),
    2222             : COL("purple", 0xa020f0),
    2223             : COL("mediumpurple", 0x9370db),
    2224             : COL("thistle", 0xd8bfd8),
    2225             : COL("snow1", 0xfffafa),
    2226             : COL("snow2", 0xeee9e9),
    2227             : COL("snow3", 0xcdc9c9),
    2228             : COL("snow4", 0x8b8989),
    2229             : COL("seashell1", 0xfff5ee),
    2230             : COL("seashell2", 0xeee5de),
    2231             : COL("seashell3", 0xcdc5bf),
    2232             : COL("seashell4", 0x8b8682),
    2233             : COL("antiquewhite1", 0xffefdb),
    2234             : COL("antiquewhite2", 0xeedfcc),
    2235             : COL("antiquewhite3", 0xcdc0b0),
    2236             : COL("antiquewhite4", 0x8b8378),
    2237             : COL("bisque1", 0xffe4c4),
    2238             : COL("bisque2", 0xeed5b7),
    2239             : COL("bisque3", 0xcdb79e),
    2240             : COL("bisque4", 0x8b7d6b),
    2241             : COL("peachpuff1", 0xffdab9),
    2242             : COL("peachpuff2", 0xeecbad),
    2243             : COL("peachpuff3", 0xcdaf95),
    2244             : COL("peachpuff4", 0x8b7765),
    2245             : COL("navajowhite1", 0xffdead),
    2246             : COL("navajowhite2", 0xeecfa1),
    2247             : COL("navajowhite3", 0xcdb38b),
    2248             : COL("navajowhite4", 0x8b795e),
    2249             : COL("lemonchiffon1", 0xfffacd),
    2250             : COL("lemonchiffon2", 0xeee9bf),
    2251             : COL("lemonchiffon3", 0xcdc9a5),
    2252             : COL("lemonchiffon4", 0x8b8970),
    2253             : COL("cornsilk1", 0xfff8dc),
    2254             : COL("cornsilk2", 0xeee8cd),
    2255             : COL("cornsilk3", 0xcdc8b1),
    2256             : COL("cornsilk4", 0x8b8878),
    2257             : COL("ivory1", 0xfffff0),
    2258             : COL("ivory2", 0xeeeee0),
    2259             : COL("ivory3", 0xcdcdc1),
    2260             : COL("ivory4", 0x8b8b83),
    2261             : COL("honeydew1", 0xf0fff0),
    2262             : COL("honeydew2", 0xe0eee0),
    2263             : COL("honeydew3", 0xc1cdc1),
    2264             : COL("honeydew4", 0x838b83),
    2265             : COL("lavenderblush1", 0xfff0f5),
    2266             : COL("lavenderblush2", 0xeee0e5),
    2267             : COL("lavenderblush3", 0xcdc1c5),
    2268             : COL("lavenderblush4", 0x8b8386),
    2269             : COL("mistyrose1", 0xffe4e1),
    2270             : COL("mistyrose2", 0xeed5d2),
    2271             : COL("mistyrose3", 0xcdb7b5),
    2272             : COL("mistyrose4", 0x8b7d7b),
    2273             : COL("azure1", 0xf0ffff),
    2274             : COL("azure2", 0xe0eeee),
    2275             : COL("azure3", 0xc1cdcd),
    2276             : COL("azure4", 0x838b8b),
    2277             : COL("slateblue1", 0x836fff),
    2278             : COL("slateblue2", 0x7a67ee),
    2279             : COL("slateblue3", 0x6959cd),
    2280             : COL("slateblue4", 0x473c8b),
    2281             : COL("royalblue1", 0x4876ff),
    2282             : COL("royalblue2", 0x436eee),
    2283             : COL("royalblue3", 0x3a5fcd),
    2284             : COL("royalblue4", 0x27408b),
    2285             : COL("blue1", 0x0000ff),
    2286             : COL("blue2", 0x0000ee),
    2287             : COL("blue3", 0x0000cd),
    2288             : COL("blue4", 0x00008b),
    2289             : COL("dodgerblue1", 0x1e90ff),
    2290             : COL("dodgerblue2", 0x1c86ee),
    2291             : COL("dodgerblue3", 0x1874cd),
    2292             : COL("dodgerblue4", 0x104e8b),
    2293             : COL("steelblue1", 0x63b8ff),
    2294             : COL("steelblue2", 0x5cacee),
    2295             : COL("steelblue3", 0x4f94cd),
    2296             : COL("steelblue4", 0x36648b),
    2297             : COL("deepskyblue1", 0x00bfff),
    2298             : COL("deepskyblue2", 0x00b2ee),
    2299             : COL("deepskyblue3", 0x009acd),
    2300             : COL("deepskyblue4", 0x00688b),
    2301             : COL("skyblue1", 0x87ceff),
    2302             : COL("skyblue2", 0x7ec0ee),
    2303             : COL("skyblue3", 0x6ca6cd),
    2304             : COL("skyblue4", 0x4a708b),
    2305             : COL("lightskyblue1", 0xb0e2ff),
    2306             : COL("lightskyblue2", 0xa4d3ee),
    2307             : COL("lightskyblue3", 0x8db6cd),
    2308             : COL("lightskyblue4", 0x607b8b),
    2309             : COL("slategray1", 0xc6e2ff),
    2310             : COL("slategray2", 0xb9d3ee),
    2311             : COL("slategray3", 0x9fb6cd),
    2312             : COL("slategray4", 0x6c7b8b),
    2313             : COL("lightsteelblue1", 0xcae1ff),
    2314             : COL("lightsteelblue2", 0xbcd2ee),
    2315             : COL("lightsteelblue3", 0xa2b5cd),
    2316             : COL("lightsteelblue4", 0x6e7b8b),
    2317             : COL("lightblue1", 0xbfefff),
    2318             : COL("lightblue2", 0xb2dfee),
    2319             : COL("lightblue3", 0x9ac0cd),
    2320             : COL("lightblue4", 0x68838b),
    2321             : COL("lightcyan1", 0xe0ffff),
    2322             : COL("lightcyan2", 0xd1eeee),
    2323             : COL("lightcyan3", 0xb4cdcd),
    2324             : COL("lightcyan4", 0x7a8b8b),
    2325             : COL("paleturquoise1", 0xbbffff),
    2326             : COL("paleturquoise2", 0xaeeeee),
    2327             : COL("paleturquoise3", 0x96cdcd),
    2328             : COL("paleturquoise4", 0x668b8b),
    2329             : COL("cadetblue1", 0x98f5ff),
    2330             : COL("cadetblue2", 0x8ee5ee),
    2331             : COL("cadetblue3", 0x7ac5cd),
    2332             : COL("cadetblue4", 0x53868b),
    2333             : COL("turquoise1", 0x00f5ff),
    2334             : COL("turquoise2", 0x00e5ee),
    2335             : COL("turquoise3", 0x00c5cd),
    2336             : COL("turquoise4", 0x00868b),
    2337             : COL("cyan1", 0x00ffff),
    2338             : COL("cyan2", 0x00eeee),
    2339             : COL("cyan3", 0x00cdcd),
    2340             : COL("cyan4", 0x008b8b),
    2341             : COL("darkslategray1", 0x97ffff),
    2342             : COL("darkslategray2", 0x8deeee),
    2343             : COL("darkslategray3", 0x79cdcd),
    2344             : COL("darkslategray4", 0x528b8b),
    2345             : COL("aquamarine1", 0x7fffd4),
    2346             : COL("aquamarine2", 0x76eec6),
    2347             : COL("aquamarine3", 0x66cdaa),
    2348             : COL("aquamarine4", 0x458b74),
    2349             : COL("darkseagreen1", 0xc1ffc1),
    2350             : COL("darkseagreen2", 0xb4eeb4),
    2351             : COL("darkseagreen3", 0x9bcd9b),
    2352             : COL("darkseagreen4", 0x698b69),
    2353             : COL("seagreen1", 0x54ff9f),
    2354             : COL("seagreen2", 0x4eee94),
    2355             : COL("seagreen3", 0x43cd80),
    2356             : COL("seagreen4", 0x2e8b57),
    2357             : COL("palegreen1", 0x9aff9a),
    2358             : COL("palegreen2", 0x90ee90),
    2359             : COL("palegreen3", 0x7ccd7c),
    2360             : COL("palegreen4", 0x548b54),
    2361             : COL("springgreen1", 0x00ff7f),
    2362             : COL("springgreen2", 0x00ee76),
    2363             : COL("springgreen3", 0x00cd66),
    2364             : COL("springgreen4", 0x008b45),
    2365             : COL("green1", 0x00ff00),
    2366             : COL("green2", 0x00ee00),
    2367             : COL("green3", 0x00cd00),
    2368             : COL("green4", 0x008b00),
    2369             : COL("chartreuse1", 0x7fff00),
    2370             : COL("chartreuse2", 0x76ee00),
    2371             : COL("chartreuse3", 0x66cd00),
    2372             : COL("chartreuse4", 0x458b00),
    2373             : COL("olivedrab1", 0xc0ff3e),
    2374             : COL("olivedrab2", 0xb3ee3a),
    2375             : COL("olivedrab3", 0x9acd32),
    2376             : COL("olivedrab4", 0x698b22),
    2377             : COL("darkolivegreen1", 0xcaff70),
    2378             : COL("darkolivegreen2", 0xbcee68),
    2379             : COL("darkolivegreen3", 0xa2cd5a),
    2380             : COL("darkolivegreen4", 0x6e8b3d),
    2381             : COL("khaki1", 0xfff68f),
    2382             : COL("khaki2", 0xeee685),
    2383             : COL("khaki3", 0xcdc673),
    2384             : COL("khaki4", 0x8b864e),
    2385             : COL("lightgoldenrod1", 0xffec8b),
    2386             : COL("lightgoldenrod2", 0xeedc82),
    2387             : COL("lightgoldenrod3", 0xcdbe70),
    2388             : COL("lightgoldenrod4", 0x8b814c),
    2389             : COL("lightyellow1", 0xffffe0),
    2390             : COL("lightyellow2", 0xeeeed1),
    2391             : COL("lightyellow3", 0xcdcdb4),
    2392             : COL("lightyellow4", 0x8b8b7a),
    2393             : COL("yellow1", 0xffff00),
    2394             : COL("yellow2", 0xeeee00),
    2395             : COL("yellow3", 0xcdcd00),
    2396             : COL("yellow4", 0x8b8b00),
    2397             : COL("gold1", 0xffd700),
    2398             : COL("gold2", 0xeec900),
    2399             : COL("gold3", 0xcdad00),
    2400             : COL("gold4", 0x8b7500),
    2401             : COL("goldenrod1", 0xffc125),
    2402             : COL("goldenrod2", 0xeeb422),
    2403             : COL("goldenrod3", 0xcd9b1d),
    2404             : COL("goldenrod4", 0x8b6914),
    2405             : COL("darkgoldenrod1", 0xffb90f),
    2406             : COL("darkgoldenrod2", 0xeead0e),
    2407             : COL("darkgoldenrod3", 0xcd950c),
    2408             : COL("darkgoldenrod4", 0x8b6508),
    2409             : COL("rosybrown1", 0xffc1c1),
    2410             : COL("rosybrown2", 0xeeb4b4),
    2411             : COL("rosybrown3", 0xcd9b9b),
    2412             : COL("rosybrown4", 0x8b6969),
    2413             : COL("indianred1", 0xff6a6a),
    2414             : COL("indianred2", 0xee6363),
    2415             : COL("indianred3", 0xcd5555),
    2416             : COL("indianred4", 0x8b3a3a),
    2417             : COL("sienna1", 0xff8247),
    2418             : COL("sienna2", 0xee7942),
    2419             : COL("sienna3", 0xcd6839),
    2420             : COL("sienna4", 0x8b4726),
    2421             : COL("burlywood1", 0xffd39b),
    2422             : COL("burlywood2", 0xeec591),
    2423             : COL("burlywood3", 0xcdaa7d),
    2424             : COL("burlywood4", 0x8b7355),
    2425             : COL("wheat1", 0xffe7ba),
    2426             : COL("wheat2", 0xeed8ae),
    2427             : COL("wheat3", 0xcdba96),
    2428             : COL("wheat4", 0x8b7e66),
    2429             : COL("tan1", 0xffa54f),
    2430             : COL("tan2", 0xee9a49),
    2431             : COL("tan3", 0xcd853f),
    2432             : COL("tan4", 0x8b5a2b),
    2433             : COL("chocolate1", 0xff7f24),
    2434             : COL("chocolate2", 0xee7621),
    2435             : COL("chocolate3", 0xcd661d),
    2436             : COL("chocolate4", 0x8b4513),
    2437             : COL("firebrick1", 0xff3030),
    2438             : COL("firebrick2", 0xee2c2c),
    2439             : COL("firebrick3", 0xcd2626),
    2440             : COL("firebrick4", 0x8b1a1a),
    2441             : COL("brown1", 0xff4040),
    2442             : COL("brown2", 0xee3b3b),
    2443             : COL("brown3", 0xcd3333),
    2444             : COL("brown4", 0x8b2323),
    2445             : COL("salmon1", 0xff8c69),
    2446             : COL("salmon2", 0xee8262),
    2447             : COL("salmon3", 0xcd7054),
    2448             : COL("salmon4", 0x8b4c39),
    2449             : COL("lightsalmon1", 0xffa07a),
    2450             : COL("lightsalmon2", 0xee9572),
    2451             : COL("lightsalmon3", 0xcd8162),
    2452             : COL("lightsalmon4", 0x8b5742),
    2453             : COL("orange1", 0xffa500),
    2454             : COL("orange2", 0xee9a00),
    2455             : COL("orange3", 0xcd8500),
    2456             : COL("orange4", 0x8b5a00),
    2457             : COL("darkorange1", 0xff7f00),
    2458             : COL("darkorange2", 0xee7600),
    2459             : COL("darkorange3", 0xcd6600),
    2460             : COL("darkorange4", 0x8b4500),
    2461             : COL("coral1", 0xff7256),
    2462             : COL("coral2", 0xee6a50),
    2463             : COL("coral3", 0xcd5b45),
    2464             : COL("coral4", 0x8b3e2f),
    2465             : COL("tomato1", 0xff6347),
    2466             : COL("tomato2", 0xee5c42),
    2467             : COL("tomato3", 0xcd4f39),
    2468             : COL("tomato4", 0x8b3626),
    2469             : COL("orangered1", 0xff4500),
    2470             : COL("orangered2", 0xee4000),
    2471             : COL("orangered3", 0xcd3700),
    2472             : COL("orangered4", 0x8b2500),
    2473             : COL("red1", 0xff0000),
    2474             : COL("red2", 0xee0000),
    2475             : COL("red3", 0xcd0000),
    2476             : COL("red4", 0x8b0000),
    2477             : COL("debianred", 0xd70751),
    2478             : COL("deeppink1", 0xff1493),
    2479             : COL("deeppink2", 0xee1289),
    2480             : COL("deeppink3", 0xcd1076),
    2481             : COL("deeppink4", 0x8b0a50),
    2482             : COL("hotpink1", 0xff6eb4),
    2483             : COL("hotpink2", 0xee6aa7),
    2484             : COL("hotpink3", 0xcd6090),
    2485             : COL("hotpink4", 0x8b3a62),
    2486             : COL("pink1", 0xffb5c5),
    2487             : COL("pink2", 0xeea9b8),
    2488             : COL("pink3", 0xcd919e),
    2489             : COL("pink4", 0x8b636c),
    2490             : COL("lightpink1", 0xffaeb9),
    2491             : COL("lightpink2", 0xeea2ad),
    2492             : COL("lightpink3", 0xcd8c95),
    2493             : COL("lightpink4", 0x8b5f65),
    2494             : COL("palevioletred1", 0xff82ab),
    2495             : COL("palevioletred2", 0xee799f),
    2496             : COL("palevioletred3", 0xcd6889),
    2497             : COL("palevioletred4", 0x8b475d),
    2498             : COL("maroon1", 0xff34b3),
    2499             : COL("maroon2", 0xee30a7),
    2500             : COL("maroon3", 0xcd2990),
    2501             : COL("maroon4", 0x8b1c62),
    2502             : COL("violetred1", 0xff3e96),
    2503             : COL("violetred2", 0xee3a8c),
    2504             : COL("violetred3", 0xcd3278),
    2505             : COL("violetred4", 0x8b2252),
    2506             : COL("magenta1", 0xff00ff),
    2507             : COL("magenta2", 0xee00ee),
    2508             : COL("magenta3", 0xcd00cd),
    2509             : COL("magenta4", 0x8b008b),
    2510             : COL("orchid1", 0xff83fa),
    2511             : COL("orchid2", 0xee7ae9),
    2512             : COL("orchid3", 0xcd69c9),
    2513             : COL("orchid4", 0x8b4789),
    2514             : COL("plum1", 0xffbbff),
    2515             : COL("plum2", 0xeeaeee),
    2516             : COL("plum3", 0xcd96cd),
    2517             : COL("plum4", 0x8b668b),
    2518             : COL("mediumorchid1", 0xe066ff),
    2519             : COL("mediumorchid2", 0xd15fee),
    2520             : COL("mediumorchid3", 0xb452cd),
    2521             : COL("mediumorchid4", 0x7a378b),
    2522             : COL("darkorchid1", 0xbf3eff),
    2523             : COL("darkorchid2", 0xb23aee),
    2524             : COL("darkorchid3", 0x9a32cd),
    2525             : COL("darkorchid4", 0x68228b),
    2526             : COL("purple1", 0x9b30ff),
    2527             : COL("purple2", 0x912cee),
    2528             : COL("purple3", 0x7d26cd),
    2529             : COL("purple4", 0x551a8b),
    2530             : COL("mediumpurple1", 0xab82ff),
    2531             : COL("mediumpurple2", 0x9f79ee),
    2532             : COL("mediumpurple3", 0x8968cd),
    2533             : COL("mediumpurple4", 0x5d478b),
    2534             : COL("thistle1", 0xffe1ff),
    2535             : COL("thistle2", 0xeed2ee),
    2536             : COL("thistle3", 0xcdb5cd),
    2537             : COL("thistle4", 0x8b7b8b),
    2538             : COL("gray0", 0x000000),
    2539             : COL("grey0", 0x000000),
    2540             : COL("gray1", 0x030303),
    2541             : COL("grey1", 0x030303),
    2542             : COL("gray2", 0x050505),
    2543             : COL("grey2", 0x050505),
    2544             : COL("gray3", 0x080808),
    2545             : COL("grey3", 0x080808),
    2546             : COL("gray4", 0x0a0a0a),
    2547             : COL("grey4", 0x0a0a0a),
    2548             : COL("gray5", 0x0d0d0d),
    2549             : COL("grey5", 0x0d0d0d),
    2550             : COL("gray6", 0x0f0f0f),
    2551             : COL("grey6", 0x0f0f0f),
    2552             : COL("gray7", 0x121212),
    2553             : COL("grey7", 0x121212),
    2554             : COL("gray8", 0x141414),
    2555             : COL("grey8", 0x141414),
    2556             : COL("gray9", 0x171717),
    2557             : COL("grey9", 0x171717),
    2558             : COL("gray10", 0x1a1a1a),
    2559             : COL("grey10", 0x1a1a1a),
    2560             : COL("gray11", 0x1c1c1c),
    2561             : COL("grey11", 0x1c1c1c),
    2562             : COL("gray12", 0x1f1f1f),
    2563             : COL("grey12", 0x1f1f1f),
    2564             : COL("gray13", 0x212121),
    2565             : COL("grey13", 0x212121),
    2566             : COL("gray14", 0x242424),
    2567             : COL("grey14", 0x242424),
    2568             : COL("gray15", 0x262626),
    2569             : COL("grey15", 0x262626),
    2570             : COL("gray16", 0x292929),
    2571             : COL("grey16", 0x292929),
    2572             : COL("gray17", 0x2b2b2b),
    2573             : COL("grey17", 0x2b2b2b),
    2574             : COL("gray18", 0x2e2e2e),
    2575             : COL("grey18", 0x2e2e2e),
    2576             : COL("gray19", 0x303030),
    2577             : COL("grey19", 0x303030),
    2578             : COL("gray20", 0x333333),
    2579             : COL("grey20", 0x333333),
    2580             : COL("gray21", 0x363636),
    2581             : COL("grey21", 0x363636),
    2582             : COL("gray22", 0x383838),
    2583             : COL("grey22", 0x383838),
    2584             : COL("gray23", 0x3b3b3b),
    2585             : COL("grey23", 0x3b3b3b),
    2586             : COL("gray24", 0x3d3d3d),
    2587             : COL("grey24", 0x3d3d3d),
    2588             : COL("gray25", 0x404040),
    2589             : COL("grey25", 0x404040),
    2590             : COL("gray26", 0x424242),
    2591             : COL("grey26", 0x424242),
    2592             : COL("gray27", 0x454545),
    2593             : COL("grey27", 0x454545),
    2594             : COL("gray28", 0x474747),
    2595             : COL("grey28", 0x474747),
    2596             : COL("gray29", 0x4a4a4a),
    2597             : COL("grey29", 0x4a4a4a),
    2598             : COL("gray30", 0x4d4d4d),
    2599             : COL("grey30", 0x4d4d4d),
    2600             : COL("gray31", 0x4f4f4f),
    2601             : COL("grey31", 0x4f4f4f),
    2602             : COL("gray32", 0x525252),
    2603             : COL("grey32", 0x525252),
    2604             : COL("gray33", 0x545454),
    2605             : COL("grey33", 0x545454),
    2606             : COL("gray34", 0x575757),
    2607             : COL("grey34", 0x575757),
    2608             : COL("gray35", 0x595959),
    2609             : COL("grey35", 0x595959),
    2610             : COL("gray36", 0x5c5c5c),
    2611             : COL("grey36", 0x5c5c5c),
    2612             : COL("gray37", 0x5e5e5e),
    2613             : COL("grey37", 0x5e5e5e),
    2614             : COL("gray38", 0x616161),
    2615             : COL("grey38", 0x616161),
    2616             : COL("gray39", 0x636363),
    2617             : COL("grey39", 0x636363),
    2618             : COL("gray40", 0x666666),
    2619             : COL("grey40", 0x666666),
    2620             : COL("gray41", 0x696969),
    2621             : COL("grey41", 0x696969),
    2622             : COL("gray42", 0x6b6b6b),
    2623             : COL("grey42", 0x6b6b6b),
    2624             : COL("gray43", 0x6e6e6e),
    2625             : COL("grey43", 0x6e6e6e),
    2626             : COL("gray44", 0x707070),
    2627             : COL("grey44", 0x707070),
    2628             : COL("gray45", 0x737373),
    2629             : COL("grey45", 0x737373),
    2630             : COL("gray46", 0x757575),
    2631             : COL("grey46", 0x757575),
    2632             : COL("gray47", 0x787878),
    2633             : COL("grey47", 0x787878),
    2634             : COL("gray48", 0x7a7a7a),
    2635             : COL("grey48", 0x7a7a7a),
    2636             : COL("gray49", 0x7d7d7d),
    2637             : COL("grey49", 0x7d7d7d),
    2638             : COL("gray50", 0x7f7f7f),
    2639             : COL("grey50", 0x7f7f7f),
    2640             : COL("gray51", 0x828282),
    2641             : COL("grey51", 0x828282),
    2642             : COL("gray52", 0x858585),
    2643             : COL("grey52", 0x858585),
    2644             : COL("gray53", 0x878787),
    2645             : COL("grey53", 0x878787),
    2646             : COL("gray54", 0x8a8a8a),
    2647             : COL("grey54", 0x8a8a8a),
    2648             : COL("gray55", 0x8c8c8c),
    2649             : COL("grey55", 0x8c8c8c),
    2650             : COL("gray56", 0x8f8f8f),
    2651             : COL("grey56", 0x8f8f8f),
    2652             : COL("gray57", 0x919191),
    2653             : COL("grey57", 0x919191),
    2654             : COL("gray58", 0x949494),
    2655             : COL("grey58", 0x949494),
    2656             : COL("gray59", 0x969696),
    2657             : COL("grey59", 0x969696),
    2658             : COL("gray60", 0x999999),
    2659             : COL("grey60", 0x999999),
    2660             : COL("gray61", 0x9c9c9c),
    2661             : COL("grey61", 0x9c9c9c),
    2662             : COL("gray62", 0x9e9e9e),
    2663             : COL("grey62", 0x9e9e9e),
    2664             : COL("gray63", 0xa1a1a1),
    2665             : COL("grey63", 0xa1a1a1),
    2666             : COL("gray64", 0xa3a3a3),
    2667             : COL("grey64", 0xa3a3a3),
    2668             : COL("gray65", 0xa6a6a6),
    2669             : COL("grey65", 0xa6a6a6),
    2670             : COL("gray66", 0xa8a8a8),
    2671             : COL("grey66", 0xa8a8a8),
    2672             : COL("gray67", 0xababab),
    2673             : COL("grey67", 0xababab),
    2674             : COL("gray68", 0xadadad),
    2675             : COL("grey68", 0xadadad),
    2676             : COL("gray69", 0xb0b0b0),
    2677             : COL("grey69", 0xb0b0b0),
    2678             : COL("gray70", 0xb3b3b3),
    2679             : COL("grey70", 0xb3b3b3),
    2680             : COL("gray71", 0xb5b5b5),
    2681             : COL("grey71", 0xb5b5b5),
    2682             : COL("gray72", 0xb8b8b8),
    2683             : COL("grey72", 0xb8b8b8),
    2684             : COL("gray73", 0xbababa),
    2685             : COL("grey73", 0xbababa),
    2686             : COL("gray74", 0xbdbdbd),
    2687             : COL("grey74", 0xbdbdbd),
    2688             : COL("gray75", 0xbfbfbf),
    2689             : COL("grey75", 0xbfbfbf),
    2690             : COL("gray76", 0xc2c2c2),
    2691             : COL("grey76", 0xc2c2c2),
    2692             : COL("gray77", 0xc4c4c4),
    2693             : COL("grey77", 0xc4c4c4),
    2694             : COL("gray78", 0xc7c7c7),
    2695             : COL("grey78", 0xc7c7c7),
    2696             : COL("gray79", 0xc9c9c9),
    2697             : COL("grey79", 0xc9c9c9),
    2698             : COL("gray80", 0xcccccc),
    2699             : COL("grey80", 0xcccccc),
    2700             : COL("gray81", 0xcfcfcf),
    2701             : COL("grey81", 0xcfcfcf),
    2702             : COL("gray82", 0xd1d1d1),
    2703             : COL("grey82", 0xd1d1d1),
    2704             : COL("gray83", 0xd4d4d4),
    2705             : COL("grey83", 0xd4d4d4),
    2706             : COL("gray84", 0xd6d6d6),
    2707             : COL("grey84", 0xd6d6d6),
    2708             : COL("gray85", 0xd9d9d9),
    2709             : COL("grey85", 0xd9d9d9),
    2710             : COL("gray86", 0xdbdbdb),
    2711             : COL("grey86", 0xdbdbdb),
    2712             : COL("gray87", 0xdedede),
    2713             : COL("grey87", 0xdedede),
    2714             : COL("gray88", 0xe0e0e0),
    2715             : COL("grey88", 0xe0e0e0),
    2716             : COL("gray89", 0xe3e3e3),
    2717             : COL("grey89", 0xe3e3e3),
    2718             : COL("gray90", 0xe5e5e5),
    2719             : COL("grey90", 0xe5e5e5),
    2720             : COL("gray91", 0xe8e8e8),
    2721             : COL("grey91", 0xe8e8e8),
    2722             : COL("gray92", 0xebebeb),
    2723             : COL("grey92", 0xebebeb),
    2724             : COL("gray93", 0xededed),
    2725             : COL("grey93", 0xededed),
    2726             : COL("gray94", 0xf0f0f0),
    2727             : COL("grey94", 0xf0f0f0),
    2728             : COL("gray95", 0xf2f2f2),
    2729             : COL("grey95", 0xf2f2f2),
    2730             : COL("gray96", 0xf5f5f5),
    2731             : COL("grey96", 0xf5f5f5),
    2732             : COL("gray97", 0xf7f7f7),
    2733             : COL("grey97", 0xf7f7f7),
    2734             : COL("gray98", 0xfafafa),
    2735             : COL("grey98", 0xfafafa),
    2736             : COL("gray99", 0xfcfcfc),
    2737             : COL("grey99", 0xfcfcfc),
    2738             : COL("gray100", 0xffffff),
    2739             : COL("grey100", 0xffffff),
    2740             : COL("darkgrey", 0xa9a9a9),
    2741             : COL("darkgray", 0xa9a9a9),
    2742             : COL("darkblue", 0x00008b),
    2743             : COL("darkcyan", 0x008b8b),
    2744             : COL("darkmagenta", 0x8b008b),
    2745             : COL("darkred", 0x8b0000),
    2746             : COL("lightgreen", 0x90ee90),
    2747             : COL(NULL,0) /* sentinel */
    2748             : };
    2749             : #undef COL
    2750             : 
    2751             : void
    2752        4218 : colorname_to_rgb(const char *s, int *r, int *g, int *b)
    2753             : {
    2754             :   hashentry *ep;
    2755             :   long rgb;
    2756             : 
    2757        4218 :   if (!rgb_colors) rgb_colors = hashstr_import_static(col_list, 1000);
    2758        4218 :   ep = hash_search(rgb_colors, (void*)s);
    2759        4218 :   if (!ep) pari_err(e_MISC, "unknown color %s", s);
    2760        4218 :   rgb = (long)ep->val;
    2761        4218 :   *b = rgb & 0xff; rgb >>= 8;
    2762        4218 :   *g = rgb & 0xff; rgb >>= 8;
    2763        4218 :   *r = rgb;
    2764        4218 : }
    2765             : 
    2766             : void
    2767        4218 : color_to_rgb(GEN c, int *r, int *g, int *b)
    2768             : {
    2769        4218 :   switch(typ(c))
    2770             :   {
    2771             :     case t_STR:
    2772        4218 :       colorname_to_rgb(GSTR(c), r,g,b);
    2773        4218 :       break;
    2774             :     default: /* t_VECSMALL: */
    2775           0 :       *r = c[1]; *g = c[2]; *b = c[3];
    2776           0 :       break;
    2777             :   }
    2778        4218 : }

Generated by: LCOV version 1.11