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