home *** CD-ROM | disk | FTP | other *** search
- /**
- ** GENARC.C
- **
- ** Copyright (C) 1992, Csaba Biegl
- ** 820 Stirrup Dr, Nashville, TN, 37221
- ** csaba@vuse.vanderbilt.edu
- **
- ** This file is distributed under the terms listed in the document
- ** "copying.cb", available from the author at the address above.
- ** A copy of "copying.cb" should accompany this file; if not, a copy
- ** should be available from where this file was obtained. This file
- ** may not be distributed without a verbatim copy of "copying.cb".
- ** You should also have received a copy of the GNU General Public
- ** License along with this program (it is in the file "copying");
- ** if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- ** Cambridge, MA 02139, USA.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **/
-
- #include "grx.h"
- #include "libgrx.h"
- #include <string.h>
-
- int _GrGenerateEllipseArc(int pt[][2],int cx,int cy,int rx,int ry,int start,int end)
- {
- #define ulong unsigned long
- #define interp(p1,f1,p2,f2,div) \
- (int)((((long)(p1) * (long)(f1)) + ((long)(p2) * (long)(f2))) / (long)(div))
-
- int tmp[MAX_ELLIPSE_PTS+1][2];
- int nfinal,nn = _GrGenerateEllipse(tmp,cx,cy,rx,ry);
- int angle1,angle2;
- int index1,index2;
- int fract1,fract2;
- int x1,y1,x2,y2;
-
- if((angle1 = start % 3600) < 0) angle1 += 3600;
- if((angle2 = end % 3600) < 0) angle2 += 3600;
- index1 = (int)(((ulong)angle1 * (ulong)nn) / 3600UL);
- fract1 = (int)(((ulong)angle1 * (ulong)nn) % 3600UL);
- index2 = (int)(((ulong)angle2 * (ulong)nn) / 3600UL);
- fract2 = (int)(((ulong)angle2 * (ulong)nn) % 3600UL);
- x1 = tmp[index1][0];
- y1 = tmp[index1][1];
- x2 = tmp[index2][0];
- y2 = tmp[index2][1];
- if(fract1 != 0) {
- x1 = interp(x1,(3600 - fract1),tmp[index1+1][0],fract1,3600);
- y1 = interp(y1,(3600 - fract1),tmp[index1+1][1],fract1,3600);
- }
- if(fract2 != 0) {
- x2 = interp(x2,(3600 - fract2),tmp[index2+1][0],fract2,3600);
- y2 = interp(y2,(3600 - fract2),tmp[index2+1][1],fract2,3600);
- index2++;
- }
- if((x1 == x2) && (y1 == y2)) {
- if(start == end) {
- pt[0][0] = x1;
- pt[0][1] = y1;
- return(1);
- }
- memcpy(pt,tmp,(sizeof(int[2]) * nn));
- return(-nn);
- }
- if(angle2 >= angle1) {
- nfinal = index2 - index1 + 1;
- memcpy(pt,&tmp[index1],(sizeof(int[2]) * nfinal));
- }
- else {
- nfinal = index2 + nn - index1 + 1;
- start = nn - index1;
- end = index2 + 1;
- memcpy(pt,&tmp[index1],(sizeof(int[2]) * start));
- memcpy(&pt[start],tmp,(sizeof(int[2]) * end));
- }
- pt[0][0] = x1;
- pt[0][1] = y1;
- pt[nfinal-1][0] = x2;
- pt[nfinal-1][1] = y2;
- return(nfinal);
- }
-