home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume10 / tek / poly.c < prev    next >
C/C++ Source or Header  |  1990-02-20  |  1KB  |  59 lines

  1. /*
  2.  *    poly.c 
  3.  *    copyright 1988 Ronald Florence
  4.  */
  5.  
  6. #include        <stdio.h>
  7.  
  8. #define    int    short        /* for CGI functions    */
  9. #define Maxpts  1000
  10. #define Vdimax  32000
  11. #define Tekx    4096.0
  12. #define Teky    3120.0
  13.  
  14. extern int    dev;        /* device id */
  15.  
  16. static double  xscale = Vdimax / Tekx,
  17.                yscale = Vdimax / Teky;
  18.  
  19.  
  20. do_poly (infile, scaled)
  21.      FILE  *infile;
  22.      int   scaled;
  23. {
  24.   double  ix, iy, txlo, txhi, tylo, tyhi;
  25.   int  ptc = 0, pts [Maxpts], xadd = 0, yadd = 0;
  26.  
  27.   if (scaled) {
  28.                 /* read and check the scaling points */
  29.     if ( fscanf(infile, "%lf%lf%lf%lf", &txlo, &tylo, &txhi, &tyhi ) == EOF 
  30.     || txlo >= txhi
  31.     || tylo >= tyhi )
  32.       err ("data");
  33.                 /* rescale */
  34.     xscale = Vdimax / (txhi - txlo);
  35.     yscale = Vdimax / (tyhi - tylo);
  36.     xadd = -txlo * xscale;
  37.     yadd = -tylo * yscale;
  38.   }
  39.                 /* read one xy point at a time */
  40.   while ( fscanf(infile, "%lf%lf", &ix, &iy) != EOF )  {
  41.                 /* put them out when we have Maxpts / 2 */
  42.     if ( ptc >= Maxpts )  {
  43.     if (v_pline (dev, (ptc / 2), pts) < 0 )  
  44.       err ("v_pline");
  45.                 /* copy the last points to the first */
  46.     pts [0] = pts [ptc -2];
  47.     pts [1] = pts [ptc -1];
  48.                 /* and set counter to start over */
  49.     ptc = 2;
  50.     }
  51.                 /* scale the points for the array */
  52.     pts [ptc++] = ix * xscale + xadd;
  53.     pts [ptc++] = iy * yscale + yadd;
  54.   }
  55.                 /* make sure we get the tail end */
  56.   if ( ptc > 2 && v_pline (dev, (ptc / 2), pts) < 0 )  
  57.     err ("v_pline");
  58. }
  59.