home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / SRC / GENARC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  2.8 KB  |  87 lines

  1. /**
  2.  ** GENARC.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "grx.h"
  25. #include "libgrx.h"
  26. #include <string.h>
  27.  
  28. int _GrGenerateEllipseArc(int pt[][2],int cx,int cy,int rx,int ry,int start,int end)
  29. {
  30. #define ulong  unsigned long
  31. #define interp(p1,f1,p2,f2,div) \
  32.     (int)((((long)(p1) * (long)(f1)) + ((long)(p2) * (long)(f2))) / (long)(div))
  33.  
  34.     int tmp[MAX_ELLIPSE_PTS+1][2];
  35.     int nfinal,nn = _GrGenerateEllipse(tmp,cx,cy,rx,ry);
  36.     int angle1,angle2;
  37.     int index1,index2;
  38.     int fract1,fract2;
  39.     int x1,y1,x2,y2;
  40.  
  41.     if((angle1 = start % 3600) < 0) angle1 += 3600;
  42.     if((angle2 = end   % 3600) < 0) angle2 += 3600;
  43.     index1 = (int)(((ulong)angle1 * (ulong)nn) / 3600UL);
  44.     fract1 = (int)(((ulong)angle1 * (ulong)nn) % 3600UL);
  45.     index2 = (int)(((ulong)angle2 * (ulong)nn) / 3600UL);
  46.     fract2 = (int)(((ulong)angle2 * (ulong)nn) % 3600UL);
  47.     x1 = tmp[index1][0];
  48.     y1 = tmp[index1][1];
  49.     x2 = tmp[index2][0];
  50.     y2 = tmp[index2][1];
  51.     if(fract1 != 0) {
  52.         x1 = interp(x1,(3600 - fract1),tmp[index1+1][0],fract1,3600);
  53.         y1 = interp(y1,(3600 - fract1),tmp[index1+1][1],fract1,3600);
  54.     }
  55.     if(fract2 != 0) {
  56.         x2 = interp(x2,(3600 - fract2),tmp[index2+1][0],fract2,3600);
  57.         y2 = interp(y2,(3600 - fract2),tmp[index2+1][1],fract2,3600);
  58.         index2++;
  59.     }
  60.     if((x1 == x2) && (y1 == y2)) {
  61.         if(start == end) {
  62.         pt[0][0] = x1;
  63.         pt[0][1] = y1;
  64.         return(1);
  65.         }
  66.         memcpy(pt,tmp,(sizeof(int[2]) * nn));
  67.         return(-nn);
  68.     }
  69.     if(angle2 >= angle1) {
  70.         nfinal = index2 - index1 + 1;
  71.         memcpy(pt,&tmp[index1],(sizeof(int[2]) * nfinal));
  72.     }
  73.     else {
  74.         nfinal = index2 + nn - index1 + 1;
  75.         start = nn - index1;
  76.         end      = index2 + 1;
  77.         memcpy(pt,&tmp[index1],(sizeof(int[2]) * start));
  78.         memcpy(&pt[start],tmp,(sizeof(int[2]) * end));
  79.     }
  80.     pt[0][0] = x1;
  81.     pt[0][1] = y1;
  82.     pt[nfinal-1][0] = x2;
  83.     pt[nfinal-1][1] = y2;
  84.     return(nfinal);
  85. }
  86.  
  87.