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