home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_200 / 286_01 / arcsupp.c < prev    next >
Text File  |  1989-05-25  |  3KB  |  110 lines

  1. #include <stdio.h>
  2. #include <gds.h>
  3.  
  4. /*==============================================================*
  5.  *                                                              *
  6.  *  This file contain 2 routines for Arc2 and Earc2 use only    *
  7.  *                                                              *
  8.  *==============================================================*/
  9.  
  10. /* p2 is in degree between 0 and 90, returns p1*sin(p2) in integer */
  11. #define gdssin(p1,p2) (int)((long)p1*SINVAL[p2]+16384>>15)
  12.  
  13. extern int ARCSTTX, ARCSTTY, ARCENDX, ARCENDY, ARCSTTR, ARCENDR;
  14.  
  15. struct cpoint {
  16.     int point,state,region;
  17. };
  18.  
  19. int arcreg[] = {
  20.       0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00
  21. };
  22. int regbit[] = {
  23.       0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
  24. };
  25.  
  26. extern unsigned int SINVAL[];
  27.  
  28. setpnt(pnt1,pnt2,reg,odd,even,major,minor,deg1,deg2)
  29. register struct cpoint *pnt1, *pnt2;
  30. int odd, even, major, minor, deg1, deg2;
  31. {
  32.     struct cpoint tmppnt;
  33.  
  34.     tmppnt.region=regbit[reg];
  35.     if (reg & 0x01) {
  36.         tmppnt.point=gdssin(minor,deg1);
  37.         if ((reg == 3) || (reg == 7)) {
  38.             pnt2->point=major;
  39.             pnt2->region=0x8000;      /* indicate this struct is not used */
  40.             pnt1->state=odd;
  41.             pnt1->point=tmppnt.point;
  42.             pnt1->region=tmppnt.region;
  43.         } else {
  44.             pnt1->point=major;
  45.             pnt1->region=0x8000;      /* indicate this struct is not used */
  46.             pnt2->state=odd;
  47.             pnt2->point=tmppnt.point;
  48.             pnt2->region=tmppnt.region;
  49.         }
  50.     } else {
  51.         tmppnt.point=gdssin(major,deg2);
  52.         if ((reg == 0) || (reg == 4)) {
  53.             pnt2->point=minor;
  54.             pnt2->region=0x8000;
  55.             pnt1->state=even;
  56.             pnt1->point=tmppnt.point;
  57.             pnt1->region=tmppnt.region;
  58.         } else {
  59.             pnt1->point=minor;
  60.             pnt1->region=0x8000;
  61.             pnt2->state=even;
  62.             pnt2->point=tmppnt.point;
  63.             pnt2->region=tmppnt.region;
  64.         }
  65.     }
  66.  
  67. /* special cases handling for Arc2 and Earc2 */
  68. adjpnt(arcp,pnt1,pnt2,shortarc,rotreg)
  69. int *arcp, shortarc, rotreg;
  70. register struct cpoint *pnt1, *pnt2;
  71. {
  72.     *arcp |= pnt1->region | pnt2->region;
  73.     if ((pnt1->region == pnt2->region) && (pnt1->region & 0xff)) {
  74.       /* if starting and ending point in the same region
  75.          and they are used, then requires special check */
  76.       if (shortarc)
  77.           *arcp ^= pnt1->region;
  78.       if (pnt1->point==pnt2->point) {
  79. label1:
  80.         if (shortarc) {
  81.             if (rotreg & 0x01)
  82.                 pnt1->point++;
  83.             else
  84.                 pnt2->point++;
  85.         } else {
  86.             if (!(rotreg & 0x01)) {
  87.                 pnt1->point++;
  88.             }
  89.         }
  90.       } else {
  91.         if (pnt1->state) pnt1->point++;
  92.         if (pnt2->state) pnt2->point++;
  93.         if (pnt1->point == pnt2->point) goto label1;
  94.       }
  95.     } else {
  96.         if (!pnt1->state) *arcp ^= pnt1->region; else pnt1->point++;
  97.         if (!pnt2->state) *arcp ^= pnt2->region; else pnt2->point++;
  98.     }
  99.     if (!pnt1->point--) {
  100.         *arcp |= pnt1->region;
  101.         if (pnt1->state) *arcp ^= pnt1->region;
  102.     }
  103.     if (!pnt2->point--) {
  104.         *arcp |= pnt2->region;
  105.         if (pnt2->state) *arcp ^= pnt2->region;
  106.     }
  107. }
  108.  
  109.