home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fractint / fras1611.zip / ZOOM.C < prev   
Text File  |  1991-07-07  |  18KB  |  521 lines

  1. /*
  2.     zoom.c - routines for zoombox manipulation and for panning
  3.  
  4. */
  5.  
  6. #include <float.h>
  7. #include "fractint.h"
  8.  
  9. /* screen dimensions here are (1.0,1.0) corresponding to (xdots-1,ydots-1) */
  10. extern double zbx,zby;           /* topleft of unrotated zoombox  */
  11. extern double zwidth,zdepth,zskew; /* zoombox size & shape        */
  12. extern int zrotate;           /* * 2.5 degree increments        */
  13. extern int boxcount,boxx[],boxy[]; /* co-ords of each zoombox pixel */
  14. extern int xdots,ydots,sxdots,sydots,sxoffs,syoffs;
  15. extern double dxsize,dysize;       /* xdots-1, ydots-1            */
  16. extern double xxmin,yymin,xxmax,yymax,xx3rd,yy3rd;
  17. extern double sxmin,symin,sxmax,symax,sx3rd,sy3rd;
  18. /* top      left    corner of screen is (xxmin,yymax) */
  19. /* bottom left    corner of screen is (xx3rd,yy3rd) */
  20. /* bottom right corner of screen is (xxmax,yymin) */
  21. extern double plotmx1,plotmx2,plotmy1,plotmy2;
  22.  
  23. extern int  calc_status;       /* status of calculations */
  24. extern int  fractype;           /* fractal type */
  25. extern char stdcalcmode;       /* '1', '2', 'g', 'b' */
  26. extern int  num_worklist;       /* resume worklist for standard engine */
  27. extern struct workliststuff worklist[MAXCALCWORK];
  28. extern char dstack[4096];       /* common temp, used for get_line/put_line */
  29. extern int  StandardFractal();
  30. extern int  calcmand();
  31. extern int  potflag;
  32. extern int  pot16bit;
  33. extern float finalaspectratio;
  34.  
  35. struct coords {
  36.     int x,y;
  37.     };
  38.  
  39. #define PIXELROUND 0.00001
  40.  
  41. static void _fastcall drawlines(struct coords, struct coords, int, int);
  42. static void _fastcall addbox(struct coords);
  43. static void _fastcall zmo_calc(double, double, double *, double *);
  44. static int  check_pan();
  45. static void fix_worklist();
  46. static void _fastcall move_row(int fromrow,int torow,int col);
  47.  
  48. void drawbox(int drawit)
  49. {   struct coords tl,bl,tr,br; /* dot addr of topleft, botleft, etc */
  50.     double tmpx,tmpy,dx,dy,rotcos,rotsin,ftemp1,ftemp2;
  51.     double fxwidth,fxskew,fydepth,fyskew,fxadj;
  52.  
  53.     if (zwidth==0) { /* no box to draw */
  54.     if (boxcount!=0) { /* remove the old box from display */
  55.         clearbox();   /* asm routine */
  56.         boxcount = 0; }
  57.     reset_zoom_corners();
  58.     return; }
  59.  
  60.     ftemp1 = PI*zrotate/72; /* convert to radians */
  61.     rotcos = cos(ftemp1);   /* sin & cos of rotation */
  62.     rotsin = sin(ftemp1);
  63.  
  64.     /* do some calcs just once here to reduce fp work a bit */
  65.     fxwidth = sxmax-sx3rd;
  66.     fxskew  = sx3rd-sxmin;
  67.     fydepth = sy3rd-symax;
  68.     fyskew  = symin-sy3rd;
  69.     fxadj   = zwidth*zskew;
  70.  
  71.     /* calc co-ords of topleft & botright corners of box */
  72.     tmpx = zwidth/-2+fxadj; /* from zoombox center as origin, on xdots scale */
  73.     tmpy = zdepth*finalaspectratio/2;
  74.     dx = (rotcos*tmpx - rotsin*tmpy) - tmpx; /* delta x to rotate topleft */
  75.     dy = tmpy - (rotsin*tmpx + rotcos*tmpy); /* delta y to rotate topleft */
  76.     /* calc co-ords of topleft */
  77.     ftemp1 = zbx + dx + fxadj;
  78.     ftemp2 = zby + dy/finalaspectratio;
  79.     tl.x   = ftemp1*(dxsize+PIXELROUND); /* screen co-ords */
  80.     tl.y   = ftemp2*(dysize+PIXELROUND);
  81.     xxmin  = sxmin + ftemp1*fxwidth + ftemp2*fxskew; /* real co-ords */
  82.     yymax  = symax + ftemp2*fydepth + ftemp1*fyskew;
  83.     /* calc co-ords of bottom right */
  84.     ftemp1 = zbx + zwidth - dx - fxadj;
  85.     ftemp2 = zby - dy/finalaspectratio + zdepth;
  86.     br.x   = ftemp1*(dxsize+PIXELROUND);
  87.     br.y   = ftemp2*(dysize+PIXELROUND);
  88.     xxmax  = sxmin + ftemp1*fxwidth + ftemp2*fxskew;
  89.     yymin  = symax + ftemp2*fydepth + ftemp1*fyskew;
  90.  
  91.     /* do the same for botleft & topright */
  92.     tmpx = zwidth/-2 - fxadj;
  93.     tmpy = 0.0-tmpy;
  94.     dx = (rotcos*tmpx - rotsin*tmpy) - tmpx;
  95.     dy = tmpy - (rotsin*tmpx + rotcos*tmpy);
  96.     ftemp1 = zbx + dx - fxadj;
  97.     ftemp2 = zby + dy/finalaspectratio + zdepth;
  98.     bl.x   = ftemp1*(dxsize+PIXELROUND);
  99.     bl.y   = ftemp2*(dysize+PIXELROUND);
  100.     xx3rd  = sxmin + ftemp1*fxwidth + ftemp2*fxskew;
  101.     yy3rd  = symax + ftemp2*fydepth + ftemp1*fyskew;
  102.     ftemp1 = zbx + zwidth - dx + fxadj;
  103.     ftemp2 = zby - dy/finalaspectratio;
  104.     tr.x   = ftemp1*(dxsize+PIXELROUND);
  105.     tr.y   = ftemp2*(dysize+PIXELROUND);
  106.  
  107.     if (boxcount!=0) { /* remove the old box from display */
  108.     clearbox();   /* asm routine */
  109.     boxcount = 0; }
  110.  
  111.     if (drawit) { /* caller wants box drawn as well as co-ords calc'd */
  112.     /* build the list of zoom box pixels */
  113.     addbox(tl); addbox(tr);           /* corner pixels */
  114.     addbox(bl); addbox(br);
  115.     drawlines(tl,tr,bl.x-tl.x,bl.y-tl.y); /* top & bottom lines */
  116.     drawlines(tl,bl,tr.x-tl.x,tr.y-tl.y); /* left & right lines */
  117.     dispbox();                  /* asm routine to paint it */
  118.     }
  119.     }
  120.  
  121. static void _fastcall drawlines(struct coords fr, struct coords to,
  122.                 int dx, int dy)
  123. {   int xincr,yincr,ctr;
  124.     int altctr,altdec,altinc;
  125.     struct coords tmpp,line1,line2;
  126.  
  127.     if (abs(to.x-fr.x) > abs(to.y-fr.y)) { /* delta.x > delta.y */
  128.     if (fr.x>to.x) { /* swap so from.x is < to.x */
  129.         tmpp = fr; fr = to; to = tmpp; }
  130.     xincr = (to.x-fr.x)*4/sxdots+1; /* do every 1st, 2nd, 3rd, or 4th dot */
  131.     ctr = (to.x-fr.x-1)/xincr;
  132.     altdec = abs(to.y-fr.y)*xincr;
  133.     altinc = to.x-fr.x;
  134.     altctr = altinc/2;
  135.     yincr = (to.y>fr.y)?1:-1;
  136.     line2.x = (line1.x = fr.x) + dx;
  137.     line2.y = (line1.y = fr.y) + dy;
  138.     while (--ctr>=0) {
  139.         line1.x += xincr;
  140.         line2.x += xincr;
  141.         altctr -= altdec;
  142.         while (altctr<0) {
  143.         altctr    += altinc;
  144.         line1.y += yincr;
  145.         line2.y += yincr;
  146.         }
  147.         addbox(line1);
  148.         addbox(line2);
  149.         }
  150.     }
  151.  
  152.     else { /* delta.y > delta.x */
  153.     if (fr.y>to.y) { /* swap so from.y is < to.y */
  154.         tmpp = fr; fr = to; to = tmpp; }
  155.     yincr = (to.y-fr.y)*4/sydots+1; /* do every 1st, 2nd, 3rd, or 4th dot */
  156.     ctr = (to.y-fr.y-1)/yincr;
  157.     altdec = abs(to.x-fr.x)*yincr;
  158.     altinc = to.y-fr.y;
  159.     altctr = altinc/2;
  160.     xincr = (to.x>fr.x) ? 1 : -1;
  161.     line2.x = (line1.x = fr.x) + dx;
  162.     line2.y = (line1.y = fr.y) + dy;
  163.     while (--ctr>=0) {
  164.         line1.y += yincr;
  165.         line2.y += yincr;
  166.         altctr  -= altdec;
  167.         while (altctr<0) {
  168.         altctr    += altinc;
  169.         line1.x += xincr;
  170.         line2.x += xincr;
  171.         }
  172.         addbox(line1);
  173.         addbox(line2);
  174.         }
  175.     }
  176.     }
  177.  
  178. static void _fastcall addbox(struct coords point)
  179. {
  180.     point.x += sxoffs;
  181.     point.y += syoffs;
  182.     if (point.x >= 0 && point.x < sxdots && point.y >= 0 && point.y < sydots) {
  183.     boxx[boxcount] = point.x;
  184.     boxy[boxcount] = point.y;
  185.     ++boxcount;
  186.     }
  187.     }
  188.  
  189. void moveboxf(double dx, double dy)
  190. {   int align,row,col;
  191.     align = check_pan();
  192.     if (dx!=0.0) {
  193.     if ((zbx += dx) + zwidth/2 < 0)  /* center must stay onscreen */
  194.         zbx = zwidth/-2;
  195.     if (zbx + zwidth/2 > 1)
  196.         zbx = 1.0 - zwidth/2;
  197.     if (align != 0
  198.       && ((col = zbx*(dxsize+PIXELROUND)) & (align-1)) != 0) {
  199.         if (dx > 0) col += align;
  200.         col -= col & (align-1); /* adjust col to pass alignment */
  201.         zbx = (double)col/dxsize; }
  202.     }
  203.     if (dy!=0.0) {
  204.     if ((zby += dy) + zdepth/2 < 0)
  205.         zby = zdepth/-2;
  206.     if (zby + zdepth/2 > 1)
  207.         zby = 1.0 - zdepth/2;
  208.     if (align != 0
  209.       && ((row = zby*(dysize+PIXELROUND)) & (align-1)) != 0) {
  210.         if (dy > 0) row += align;
  211.         row -= row & (align-1);
  212.         zby = (double)row/dysize; }
  213.     }
  214.     }
  215.  
  216. static void _fastcall chgboxf(double dwidth, double ddepth)
  217. {
  218.     if (zwidth+dwidth > 1)
  219.     dwidth = 1.0-zwidth;
  220.     if (zwidth+dwidth < 0.05)
  221.     dwidth = 0.05-zwidth;
  222.     zwidth += dwidth;
  223.     if (zdepth+ddepth > 1)
  224.     ddepth = 1.0-zdepth;
  225.     if (zdepth+ddepth < 0.05)
  226.     ddepth = 0.05-zdepth;
  227.     zdepth += ddepth;
  228.     moveboxf(dwidth/-2,ddepth/-2); /* keep it centered & check limits */
  229.     }
  230.  
  231. void resizebox(int steps)
  232. {
  233.     double deltax,deltay;
  234.     if (zdepth*SCREENASPECT > zwidth) { /* box larger on y axis */
  235.     deltay = steps * 0.036 / SCREENASPECT;
  236.     deltax = zwidth * deltay / zdepth;
  237.     }
  238.     else {                /* box larger on x axis */
  239.     deltax = steps * 0.036;
  240.     deltay = zdepth * deltax / zwidth;
  241.     }
  242.     chgboxf(deltax,deltay);
  243.     }
  244.  
  245. void chgboxi(int dw, int dd)
  246. {   /* change size by pixels */
  247.     chgboxf( (double)dw/dxsize, (double)dd/dysize );
  248.     }
  249.  
  250. #ifdef C6
  251. #pragma optimize("e",off)  /* MSC 6.00A messes up next rtn with "e" on */
  252. #endif
  253.  
  254. void zoomout() /* for ctl-enter, calc corners for zooming out */
  255. {   double savxxmin,savyymax,ftemp;
  256.     /* (xxmin,yymax), etc, are already set to zoombox corners;
  257.        (sxmin,symax), etc, are still the screen's corners;
  258.        use the same logic as plot_orbit stuff to first calculate current screen
  259.        corners relative to the zoombox, as if the zoombox were a square with
  260.        upper left (0,0) and width/depth 1; ie calc the current screen corners
  261.        as if plotting them from the zoombox;
  262.        then extend these co-ords from current real screen corners to get
  263.        new actual corners
  264.        */
  265.     ftemp = (yymin-yy3rd)*(xx3rd-xxmin) - (xxmax-xx3rd)*(yy3rd-yymax);
  266.     plotmx1 = (xx3rd-xxmin) / ftemp; /* reuse the plotxxx vars is safe */
  267.     plotmx2 = (yy3rd-yymax) / ftemp;
  268.     plotmy1 = (yymin-yy3rd) / ftemp;
  269.     plotmy2 = (xxmax-xx3rd) / ftemp;
  270.     savxxmin = xxmin; savyymax = yymax;
  271.     zmo_calc(sxmin-savxxmin,symax-savyymax,&xxmin,&yymax); /* new xxmin/xxmax */
  272.     zmo_calc(sxmax-savxxmin,symin-savyymax,&xxmax,&yymin);
  273.     zmo_calc(sx3rd-savxxmin,sy3rd-savyymax,&xx3rd,&yy3rd);
  274.     }
  275.  
  276. #ifdef C6
  277. #pragma optimize("e",on)  /* back to normal */
  278. #endif
  279.  
  280. static void _fastcall zmo_calc(double dx, double dy, double *newx, double *newy)
  281. {   double tempx,tempy;
  282.     /* calc cur screen corner relative to zoombox, when zoombox co-ords
  283.        are taken as (0,0) topleft thru (1,1) bottom right */
  284.     tempx = dy * plotmx1 - dx * plotmx2;
  285.     tempy = dx * plotmy1 - dy * plotmy2;
  286.     /* calc new corner by extending from current screen corners */
  287.     *newx = sxmin + tempx*(sxmax-sx3rd) + tempy*(sx3rd-sxmin);
  288.     *newy = symax + tempy*(sy3rd-symax) + tempx*(symin-sy3rd);
  289.     }
  290.  
  291. void aspectratio_crop(float oldaspect,float newaspect)
  292. {
  293.    double ftemp,xmargin,ymargin;
  294.    if (newaspect > oldaspect) { /* new ratio is taller, crop x */
  295.       ftemp = (1.0 - oldaspect / newaspect) / 2;
  296.       xmargin = (xxmax - xx3rd) * ftemp;
  297.       ymargin = (yymin - yy3rd) * ftemp;
  298.       xx3rd += xmargin;
  299.       yy3rd += ymargin;
  300.       }
  301.    else               { /* new ratio is wider, crop y */
  302.       ftemp = (1.0 - newaspect / oldaspect) / 2;
  303.       xmargin = (xx3rd - xxmin) * ftemp;
  304.       ymargin = (yy3rd - yymax) * ftemp;
  305.       xx3rd -= xmargin;
  306.       yy3rd -= ymargin;
  307.       }
  308.    xxmin += xmargin;
  309.    yymax += ymargin;
  310.    xxmax -= xmargin;
  311.    yymin -= ymargin;
  312. }
  313.  
  314. static int check_pan() /* return 0 if can't, alignment requirement if can */
  315. {   int i,j;
  316.     if (calc_status != 2 && calc_status != 4)
  317.     return(0); /* not resumable, not complete */
  318.     if ( curfractalspecific->calctype != StandardFractal
  319.       && curfractalspecific->calctype != calcmand)
  320.     return(0); /* not a worklist-driven type */
  321.     if (zwidth != 1.0 || zdepth != 1.0 || zskew != 0.0 || zrotate != 0.0)
  322.     return(0); /* not a full size unrotated unskewed zoombox */
  323.     /* can pan if we get this far */
  324.     if (calc_status == 4)
  325.     return(1); /* image completed, align on any pixel */
  326.     if (potflag && pot16bit)
  327.     return(1); /* 1 pass forced so align on any pixel */
  328.     if (stdcalcmode == 'b')
  329.     return(1); /* btm, align on any pixel */
  330.     if (stdcalcmode != 'g' || (curfractalspecific->flags&NOGUESS)) {
  331.     if (stdcalcmode == '2') /* align on even pixel for 2pass */
  332.        return(2);
  333.     return(1); /* assume 1pass */
  334.     }
  335.     /* solid guessing */
  336.     start_resume();
  337.     get_resume(sizeof(int),&num_worklist,sizeof(worklist),worklist,0);
  338.     /* don't do end_resume! we're just looking */
  339.     i = 9;
  340.     for (j=0; j<num_worklist; ++j) /* find lowest pass in any pending window */
  341.     if (worklist[j].pass < i)
  342.         i = worklist[j].pass;
  343.     j = ssg_blocksize(); /* worst-case alignment requirement */
  344.     while (--i >= 0)
  345.     j = j>>1; /* reduce requirement */
  346.     return(j);
  347.     }
  348.  
  349. static void _fastcall move_row(int fromrow,int torow,int col)
  350. /* move a row on the screen */
  351. {   int startcol,endcol,tocol;
  352.     memset(dstack,0,xdots); /* use dstack as a temp for the row; clear it */
  353.     if (fromrow >= 0 && fromrow < ydots) {
  354.     tocol = startcol = 0;
  355.     endcol = xdots-1;
  356.     if (col < 0) {
  357.         tocol -= col;
  358.         endcol += col; }
  359.     if (col > 0)
  360.         startcol += col;
  361.     get_line(fromrow,startcol,endcol,&dstack[tocol]);
  362.     }
  363.     put_line(torow,0,xdots-1,dstack);
  364.     }
  365.  
  366. int init_pan_or_recalc(zoomout) /* decide to recalc, or to chg worklist & pan */
  367. {   int i,j,row,col,y,alignmask,listfull;
  368.     if (zwidth == 0.0)
  369.     return(0); /* no zoombox, leave calc_status as is */
  370.     /* got a zoombox */
  371.     if ((alignmask=check_pan()-1) < 0) {
  372.     calc_status = 0; /* can't pan, trigger recalc */
  373.     return(0); }
  374.     if (zbx == 0.0 && zby == 0.0) {
  375.     clearbox();
  376.     return(0); } /* box is full screen, leave calc_status as is */
  377.     col = zbx*(dxsize+PIXELROUND); /* calc dest col,row of topleft pixel */
  378.     row = zby*(dysize+PIXELROUND);
  379.     if (zoomout) { /* invert row and col */
  380.     row = 0-row;
  381.     col = 0-col; }
  382.     if ((row&alignmask) != 0 || (col&alignmask) != 0) {
  383.     calc_status = 0; /* not on useable pixel alignment, trigger recalc */
  384.     return(0); }
  385.     /* pan */
  386.     num_worklist = 0;
  387.     if (calc_status == 2) {
  388.        start_resume();
  389.        get_resume(sizeof(int),&num_worklist,sizeof(worklist),worklist,0);
  390.        } /* don't do end_resume! we might still change our mind */
  391.     /* adjust existing worklist entries */
  392.     for (i=0; i<num_worklist; ++i) {
  393.     worklist[i].yystart -= row;
  394.     worklist[i].yystop  -= row;
  395.     worklist[i].yybegin -= row;
  396.     worklist[i].xxstart -= col;
  397.     worklist[i].xxstop  -= col;
  398.     }
  399.     /* add worklist entries for the new edges */
  400.     listfull = i = 0;
  401.     j = ydots-1;
  402.     if (row < 0) {
  403.     listfull |= add_worklist(0,xdots-1,0,0-row-1,0,0,0);
  404.     i = 0 - row; }
  405.     if (row > 0) {
  406.     listfull |= add_worklist(0,xdots-1,ydots-row,ydots-1,ydots-row,0,0);
  407.     j = ydots - row - 1; }
  408.     if (col < 0)
  409.     listfull |= add_worklist(0,0-col-1,i,j,i,0,0);
  410.     if (col > 0)
  411.     listfull |= add_worklist(xdots-col,xdots-1,i,j,i,0,0);
  412.     if (listfull != 0) {
  413.     static char far msg[] = {"\
  414. Tables full, can't pan current image.\n\
  415. Cancel resumes old image, continue pans and calculates a new one."};
  416.     if (stopmsg(2,msg)) {
  417.         zwidth = 0; /* cancel the zoombox */
  418.         drawbox(1); }
  419.     else
  420.         calc_status = 0; /* trigger recalc */
  421.     return(0); }
  422.     /* now we're committed */
  423.     calc_status = 2;
  424.     clearbox();
  425.     if (row > 0) /* move image up */
  426.     for (y=0; y<ydots; ++y) move_row(y+row,y,col);
  427.     else     /* move image down */
  428.     for (y=ydots; --y>=0;)    move_row(y+row,y,col);
  429.     fix_worklist(); /* fixup any out of bounds worklist entries */
  430.     alloc_resume(sizeof(worklist)+10,1); /* post the new worklist */
  431.     put_resume(sizeof(int),&num_worklist,sizeof(worklist),worklist,0);
  432.     return(0);
  433.     }
  434.  
  435. static void _fastcall restart_window(int wknum)
  436. /* force a worklist entry to restart */
  437. {   int yfrom,yto,xfrom,xto;
  438.     if ((yfrom = worklist[wknum].yystart) < 0) yfrom = 0;
  439.     if ((xfrom = worklist[wknum].xxstart) < 0) xfrom = 0;
  440.     if ((yto = worklist[wknum].yystop) >= ydots) yto = ydots - 1;
  441.     if ((xto = worklist[wknum].xxstop) >= xdots) xto = xdots - 1;
  442.     memset(dstack,0,xdots); /* use dstack as a temp for the row; clear it */
  443.     while (yfrom <= yto)
  444.     put_line(yfrom++,xfrom,xto,dstack);
  445.     worklist[wknum].sym = worklist[wknum].pass = 0;
  446.     worklist[wknum].yybegin = worklist[wknum].yystart;
  447. }
  448.  
  449. static void fix_worklist() /* fix out of bounds and symmetry related stuff */
  450. {   int i,j,k;
  451.     struct workliststuff *wk;
  452.     for (i=0; i<num_worklist; ++i) {
  453.     wk = &worklist[i];
  454.     if ( wk->yystart >= ydots || wk->yystop < 0
  455.       || wk->xxstart >= xdots || wk->xxstop < 0) { /* offscreen, delete */
  456.         for (j=i+1; j<num_worklist; ++j)
  457.         worklist[j-1] = worklist[j];
  458.         --num_worklist;
  459.         --i;
  460.         continue; }
  461.     if (wk->yystart < 0) /* partly off top edge */
  462.         if ((wk->sym&1) == 0) /* no sym, easy */
  463.         wk->yystart = 0;
  464.         else { /* xaxis symmetry */
  465.         if ((j = wk->yystop + wk->yystart) > 0
  466.           && num_worklist < MAXCALCWORK) { /* split the sym part */
  467.             worklist[num_worklist] = worklist[i];
  468.             worklist[num_worklist].yystart = 0;
  469.             worklist[num_worklist++].yystop = j;
  470.             wk->yystart = j+1; }
  471.         else
  472.             wk->yystart = 0;
  473.         restart_window(i); /* restart the no-longer sym part */
  474.         }
  475.     if (wk->yystop >= ydots) { /* partly off bottom edge */
  476.        j = ydots-1;
  477.        if ((wk->sym&1) != 0) { /* uses xaxis symmetry */
  478.           if ((k = wk->yystart + (wk->yystop - j)) < j)
  479.          if (num_worklist >= MAXCALCWORK) /* no room to split */
  480.             restart_window(i);
  481.          else { /* split it */
  482.             worklist[num_worklist] = worklist[i];
  483.             worklist[num_worklist].yystart = k;
  484.             worklist[num_worklist++].yystop = j;
  485.             j = k-1; }
  486.           wk->sym &= -1 - 1; }
  487.        wk->yystop = j; }
  488.     if (wk->xxstart < 0) /* partly off left edge */
  489.         if ((wk->sym&2) == 0) /* no sym, easy */
  490.         wk->xxstart = 0;
  491.         else { /* yaxis symmetry */
  492.         if ((j = wk->xxstop + wk->xxstart) > 0
  493.           && num_worklist < MAXCALCWORK) { /* split the sym part */
  494.             worklist[num_worklist] = worklist[i];
  495.             worklist[num_worklist].xxstart = 0;
  496.             worklist[num_worklist++].xxstop = j;
  497.             wk->xxstart = j+1; }
  498.         else
  499.             wk->xxstart = 0;
  500.         restart_window(i); /* restart the no-longer sym part */
  501.         }
  502.     if (wk->xxstop >= xdots) { /* partly off right edge */
  503.        j = xdots-1;
  504.        if ((wk->sym&2) != 0) { /* uses xaxis symmetry */
  505.           if ((k = wk->xxstart + (wk->xxstop - j)) < j)
  506.          if (num_worklist >= MAXCALCWORK) /* no room to split */
  507.             restart_window(i);
  508.          else { /* split it */
  509.             worklist[num_worklist] = worklist[i];
  510.             worklist[num_worklist].xxstart = k;
  511.             worklist[num_worklist++].xxstop = j;
  512.             j = k-1; }
  513.           wk->sym &= -1 - 2; }
  514.        wk->xxstop = j; }
  515.     if (wk->yybegin < wk->yystart) wk->yybegin = wk->yystart;
  516.     if (wk->yybegin > wk->yystop)  wk->yybegin = wk->yystop;
  517.     }
  518.     tidy_worklist(); /* combine where possible, re-sort */
  519. }
  520.  
  521.