head 1.2; access ; symbols ; locks ; comment @ * @; 1.2 date 89.03.23.13.23.09; author pkern; state Exp; branches ; next 1.1; 1.1 date 89.03.15.16.20.39; author pkern; state Exp; branches ; next ; desc @graphics routines from MGR @ 1.2 log @boundary checking added, routines renamed. @ text @/* * gfx_m.c: more graphics routines * * The following routines were copied from MGR's src/graph_subs.c */ static char rcsid[] = "$Header: gfx_m.c,v 1.1 89/03/15 16:20:39 pkern Exp $"; #define uchar unsigned char extern int gmax_x, gmax_y; #define BONK(a,b,A) \ if (0 <= (a) && (a) < gmax_x \ && 0 <= (b) && (b) < gmax_y) \ boink((a), (b), (A)) /* Copyright (c) 1987 Bellcore * All Rights Reserved * Permission is granted to copy or use this program, EXCEPT that it * may not be sold for profit, the copyright notice must be reproduced * on copies, and credit should be given to Bellcore where it is due. * BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM. */ /* * %Header: graph_subs.c,v 4.1 88/06/21 13:33:53 bianchi Exp % * %Source: /tmp/mgrsrc/src/RCS/graph_subs.c,v % */ static char RCSid_[] = "%Source: /tmp/mgrsrc/src/RCS/graph_subs.c,v %%Revision: 4.1 %"; /* * circle of radius r centered at x1,y1 */ mgr_circle(x1,y1,r,f) int x1; register int y1; int r; uchar f; { register err = 0; /* x^2 + y^2 - r^2 */ register dxsq = 1; /* (x+dx)^2-x^2*/ register dysq = 1 - 2*r; register exy; int x0 = x1; register y0 = y1 - r; y1 += r; while (y1 > y0) { BONK(x0,y0,f); BONK(x0,y1,f); BONK(x1,y0,f); BONK(x1,y1,f); exy = err + dxsq + dysq; if (-exy <= err+dxsq) { y1--; y0++; err += dysq; dysq += 2; } if (exy <= -err) { x1++; x0--; err += dxsq; dxsq += 2; } } BONK(x0,y0,f); BONK(x1,y0,f); } #define labs(x,y) if ((x=y)<0) x= -x #define BIG 0x7fff #define HUGE 0x3fffffffL /* * calculate b*b*x*x + a*a*y*y - a*a*b*b avoiding ovfl */ static long resid(a,b,x,y) register a,b; int x,y; { long result = 0; long u = b*((long)a*a - (long)x*x); long v = (long)a*y*y; register q = u>BIG? HUGE/u: BIG; register r = v>BIG? HUGE/v: BIG; while (a || b) { if (result>=0 && b) { if (q>b) q = b; result -= q*u; b -= q; } else { if (r>a) r = a; result += r*v; a -= r; } } return(result); } /* * draw an ellipse centered at x,y with half-axes a,b */ mgr_ellipse(x, y, a, b, f) int x, y; int a, b; uchar f; { int z; int x0=x, y0=y, x1=0, y1=b, x2=0, y2=b; int dx = y1>0? 1: (y1<0? -1: (x1>0? -1: 1)); int dy = x1>0? -1: (x1<0? 1: (y1>0? -1: 1)); long a2 = (long)a*a; long b2 = (long)b*b; register long dex = b2*(2*dx*x1+1); register long e; register long dey = a2*(2*dy*y1+1); register long ex, ey, exy; if (a==0 || b==0) { bline(x-a, y-b, x+a, y+b, f); return; } /* * clockwise ellipse centered at x0,y0 with half-axes a,b. * boink each point from x1,y1 to x2,y2 */ e = resid(a, b, x1, y1); a2 *= 2; b2 *= 2; do { labs(ex, e+dex); labs(ey, e+dey); labs(exy, e+dex+dey); if (exy<=ex || ey0? -1: 1; for ( ; ; eps=exy, x2+=dx, y2+=dy) { if (abs(y2) > abs(x2)) { dy = d*sgn(y2); dx = 0; } else { dy = 0; dx = d*sgn(x2); if (dx==0) dx = 1; } exy = eps + (2*x2+dx)*dx + (2*y2+dy)*dy; if (Labs(eps) <= Labs(exy)) break; } *rx = x2; *ry = y2; return(0); } @ 1.1 log @Initial revision @ text @d4 1 a4 1 * The following code was obtained from MGR's src/graph_subs.c d6 1 a6 1 static char rcsid[] = "$Header:$"; d8 7 d31 1 a31 1 m_circle(x1,y1,r,f) d34 2 a35 1 int r, f; d46 4 a49 4 boink(x0,y0,f); boink(x0,y1,f); boink(x1,y0,f); boink(x1,y1,f); d64 2 a65 2 boink(x0,y0,f); boink(x1,y0,f); d104 1 a104 1 m_ellipse(x, y, a, b, f) d109 2 a110 2 int x0, y0, z; int x1=0, y1=b, x2=0, y2=b; d146 1 a146 1 boink(x0+x1, y0+y1, f); d153 1 a153 1 boink(x0+z, y0+y1, f); d184 1 a184 1 m_arc(x0,y0, x2,y2, x1,y1, f) d227 1 a227 1 boink(x0+x1, y0+y1,f); @