home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d056 / mcad.lha / mCAD / tdp / source / hlplot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-02  |  3.1 KB  |  99 lines

  1. /* hlplot.c */
  2. #include "tdp.h"
  3. void hlplot(h, v, nhpts, inc, dir, pass2)
  4. int *h, *v;
  5. short nhpts, inc, dir, pass2;
  6. {
  7.    register short ih,i,     /* CURRENT HORIZ PIXEL, COUNTER           */
  8.    hlast,vlast,hthis,vthis; /* PREV, CURRENT DATA POINTS              */
  9.    short vtry, idh, idv;    /* INTERPOLATED V VALUE, DELTA-H, DELTA-V */
  10.    FFP dh, dv;              /* FFP VERSIONS OF IDH, IDV               */
  11.  
  12.    hlast = (short)*h; vlast = (short)*v;
  13.    
  14.    /*** INIT PEN FOR NEW LINE ***/
  15.    pen(RESET,hlast,RESET,dir);
  16.    if (!pass2) {
  17.       if (vlast >= vhicum[hlast]) {
  18.          if (!vhicum[hlast]) vlocum[hlast] = vlast-1;
  19.          vhicum[hlast] = vlast; pen(DOWN,hlast,DATA,dir,vhicum);
  20.       }
  21.    }
  22.    else {
  23.       if (vlast <= vlocum[hlast])
  24.          {vlocum[hlast] = vlast; pen(DOWN,hlast,DATA,dir,vlocum);}
  25.    }
  26.    
  27.    /*** PLOT V(H) IN "DIR" DIRECTION ***/
  28.    for (i=0; i < nhpts-1; i++) {
  29.       hthis = (short)*(h += inc); vthis = (short)*(v += inc);
  30.       idh = hthis-hlast; idv = vthis-vlast;
  31.  
  32.       /*** THE USUAL CASE: V(H) IS INTERPOLABLE IN [hlast..hthis] ***/
  33.       if (abs(idh) > 2) {
  34.          dv = (FFP)(idv); dh = (FFP)(idh); ih = hlast+dir;
  35.          while (ih != hthis) {
  36.             vtry = vlast + (short)(dv * (FFP)(ih-hlast)/dh);
  37.             if (!pass2) {
  38.                if (vtry >= vhicum[ih]) {
  39.                   if (!vhicum[ih]) vlocum[ih] = vtry-1;
  40.                   vhicum[ih] = vtry; pen(DOWN,ih,INTERP,dir,vhicum);
  41.                }
  42.                else
  43.                   pen(UP,ih,INTERP,dir,vhicum);
  44.             }
  45.             else {
  46.                if (vtry <= vlocum[ih])
  47.                   {vlocum[ih] = vtry; pen(DOWN,ih,INTERP,dir,vlocum);}
  48.                else
  49.                   pen(UP,ih,INTERP,dir,vlocum);
  50.             }
  51.             ih += dir;
  52.          }
  53.       }
  54.       else {
  55.          /*** SPECIAL CASE: (NEARLY) VERTICAL LINE SEGMENT ***/
  56.          if (abs(idh) == 2) {
  57.             if (!pass2) {
  58.                if ((vtry=vlast+idv/2) >= vhicum[(ih=hlast+dir)]) {
  59.                   pen(DOWN,hlast,DATA,0,vhicum);
  60.                   if (!vhicum[ih]) vlocum[ih] = vtry-1;
  61.                   vhicum[ih] = vtry; pen(DOWN,ih,DATA,0,vhicum);
  62.                }
  63.             }
  64.             else {
  65.                if ((vtry=vlast+idv/2) <= vlocum[(ih=hlast+dir)]) {
  66.                   pen(DOWN,hlast,DATA,0,vlocum);
  67.                   vlocum[ih] = vtry; pen(DOWN,ih,DATA,0,vlocum);
  68.                }
  69.             }
  70.          }
  71.          else {
  72.             if (!pass2)
  73.                {if (vthis >= vhicum[hthis]) pen(DOWN,hlast,DATA,0,vhicum);}
  74.             else
  75.                {if (vthis <= vlocum[hthis]) pen(DOWN,hlast,DATA,0,vlocum);}
  76.          }
  77.       }
  78.  
  79.       /*** FINISH A LINE SEGMENT ***/
  80.       if (!pass2) {
  81.          if (vthis >= vhicum[hthis]) {
  82.             if (!vhicum[hthis]) vlocum[hthis] = vthis-1;
  83.             vhicum[hthis] = vthis; pen(DOWN,hthis,DATA,dir,vhicum);
  84.          }
  85.          else
  86.             pen(UP,ih,DATA,dir,vhicum);
  87.       }
  88.       else {
  89.          if (vthis <= vlocum[hthis])
  90.             {vlocum[hthis] = vthis; pen(DOWN,hthis,DATA,dir,vlocum);}
  91.          else
  92.             pen(UP,ih,DATA,dir,vlocum);
  93.       }
  94.  
  95.       hlast = hthis; vlast = vthis;
  96.    }
  97. }
  98.  
  99.