17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate * The Regents of the University of California
337c478bd9Sstevel@tonic-gate * All Rights Reserved
347c478bd9Sstevel@tonic-gate *
357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate * contributors.
387c478bd9Sstevel@tonic-gate */
397c478bd9Sstevel@tonic-gate
40*e5190c10Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
41*e5190c10Smuffin
427c478bd9Sstevel@tonic-gate #include <stdio.h>
437c478bd9Sstevel@tonic-gate #include <math.h>
447c478bd9Sstevel@tonic-gate #define PI 3.141592654
457c478bd9Sstevel@tonic-gate #define hmot(n) hpos += n
467c478bd9Sstevel@tonic-gate #define hgoto(n) hpos = n
477c478bd9Sstevel@tonic-gate #define vmot(n) vgoto(vpos + n)
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate extern int hpos;
507c478bd9Sstevel@tonic-gate extern int vpos;
517c478bd9Sstevel@tonic-gate extern int size;
527c478bd9Sstevel@tonic-gate extern short *pstab;
537c478bd9Sstevel@tonic-gate extern int DX; /* step size in x */
547c478bd9Sstevel@tonic-gate extern int DY; /* step size in y */
557c478bd9Sstevel@tonic-gate extern int drawdot; /* character to use when drawing */
567c478bd9Sstevel@tonic-gate extern int drawsize; /* shrink point size by this facter */
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate int maxdots = 32000; /* maximum number of dots in an object */
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #define sgn(n) ((n > 0) ? 1 : ((n < 0) ? -1 : 0))
617c478bd9Sstevel@tonic-gate #define abs(n) ((n) >= 0 ? (n) : -(n))
627c478bd9Sstevel@tonic-gate #define max(x,y) ((x) > (y) ? (x) : (y))
637c478bd9Sstevel@tonic-gate #define min(x,y) ((x) < (y) ? (x) : (y))
647c478bd9Sstevel@tonic-gate #define arcmove(x,y) { hgoto(x); vmot(-vpos-(y)); }
657c478bd9Sstevel@tonic-gate
66*e5190c10Smuffin int
drawline(dx,dy,s)677c478bd9Sstevel@tonic-gate drawline(dx, dy, s) /* draw line from here to dx, dy using s */
687c478bd9Sstevel@tonic-gate int dx, dy;
697c478bd9Sstevel@tonic-gate char *s;
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate int xd, yd;
727c478bd9Sstevel@tonic-gate float val, slope;
737c478bd9Sstevel@tonic-gate int i, numdots;
747c478bd9Sstevel@tonic-gate int dirmot, perp;
757c478bd9Sstevel@tonic-gate int motincr, perpincr;
767c478bd9Sstevel@tonic-gate int ohpos, ovpos, osize, ofont;
777c478bd9Sstevel@tonic-gate float incrway;
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate int itemp; /*temp. storage for value returned byint function sgn*/
807c478bd9Sstevel@tonic-gate osize = size;
817c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
827c478bd9Sstevel@tonic-gate ohpos = hpos;
837c478bd9Sstevel@tonic-gate ovpos = vpos;
847c478bd9Sstevel@tonic-gate xd = dx / DX;
857c478bd9Sstevel@tonic-gate yd = dy / DX;
867c478bd9Sstevel@tonic-gate if (xd == 0) {
877c478bd9Sstevel@tonic-gate numdots = abs (yd);
887c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
897c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd);
907c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
917c478bd9Sstevel@tonic-gate vmot(motincr);
927c478bd9Sstevel@tonic-gate put1(drawdot);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate vgoto(ovpos + dy);
957c478bd9Sstevel@tonic-gate setsize(osize);
96*e5190c10Smuffin return (0);
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate if (yd == 0) {
997c478bd9Sstevel@tonic-gate numdots = abs (xd);
1007c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd);
1017c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
1027c478bd9Sstevel@tonic-gate hmot(motincr);
1037c478bd9Sstevel@tonic-gate put1(drawdot);
1047c478bd9Sstevel@tonic-gate }
1057c478bd9Sstevel@tonic-gate hgoto(ohpos + dx);
1067c478bd9Sstevel@tonic-gate setsize(osize);
107*e5190c10Smuffin return (0);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate if (abs (xd) > abs (yd)) {
1107c478bd9Sstevel@tonic-gate val = slope = (float) xd/yd;
1117c478bd9Sstevel@tonic-gate numdots = abs (xd);
1127c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1137c478bd9Sstevel@tonic-gate dirmot = 'h';
1147c478bd9Sstevel@tonic-gate perp = 'v';
1157c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd);
1167c478bd9Sstevel@tonic-gate perpincr = DX * sgn (yd);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate else {
1197c478bd9Sstevel@tonic-gate val = slope = (float) yd/xd;
1207c478bd9Sstevel@tonic-gate numdots = abs (yd);
1217c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1227c478bd9Sstevel@tonic-gate dirmot = 'v';
1237c478bd9Sstevel@tonic-gate perp = 'h';
1247c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd);
1257c478bd9Sstevel@tonic-gate perpincr = DX * sgn (xd);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate incrway = itemp = sgn ((int) slope);
1287c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
1297c478bd9Sstevel@tonic-gate val -= incrway;
1307c478bd9Sstevel@tonic-gate if (dirmot == 'h')
1317c478bd9Sstevel@tonic-gate hmot(motincr);
1327c478bd9Sstevel@tonic-gate else
1337c478bd9Sstevel@tonic-gate vmot(motincr);
1347c478bd9Sstevel@tonic-gate if (val * slope < 0) {
1357c478bd9Sstevel@tonic-gate if (perp == 'h')
1367c478bd9Sstevel@tonic-gate hmot(perpincr);
1377c478bd9Sstevel@tonic-gate else
1387c478bd9Sstevel@tonic-gate vmot(perpincr);
1397c478bd9Sstevel@tonic-gate val += slope;
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate put1(drawdot);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate hgoto(ohpos + dx);
1447c478bd9Sstevel@tonic-gate vgoto(ovpos + dy);
1457c478bd9Sstevel@tonic-gate setsize(osize);
146*e5190c10Smuffin
147*e5190c10Smuffin return (0);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate
150*e5190c10Smuffin int
drawwig(s)1517c478bd9Sstevel@tonic-gate drawwig(s) /* draw wiggly line */
1527c478bd9Sstevel@tonic-gate char *s;
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate int x[50], y[50], xp, yp, pxp, pyp;
1557c478bd9Sstevel@tonic-gate float t1, t2, t3, w;
1567c478bd9Sstevel@tonic-gate int i, j, numdots, N;
1577c478bd9Sstevel@tonic-gate int osize, ofont;
1587c478bd9Sstevel@tonic-gate char temp[50], *p, *getstr();
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate osize = size;
1617c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
1627c478bd9Sstevel@tonic-gate p = s;
1637c478bd9Sstevel@tonic-gate for (N = 2; (p=getstr(p,temp)) != NULL && N < sizeof(x)/sizeof(x[0]); N++) {
1647c478bd9Sstevel@tonic-gate x[N] = atoi(temp);
1657c478bd9Sstevel@tonic-gate p = getstr(p, temp);
1667c478bd9Sstevel@tonic-gate y[N] = atoi(temp);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate x[0] = x[1] = hpos;
1697c478bd9Sstevel@tonic-gate y[0] = y[1] = vpos;
1707c478bd9Sstevel@tonic-gate for (i = 1; i < N; i++) {
1717c478bd9Sstevel@tonic-gate x[i+1] += x[i];
1727c478bd9Sstevel@tonic-gate y[i+1] += y[i];
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate x[N] = x[N-1];
1757c478bd9Sstevel@tonic-gate y[N] = y[N-1];
1767c478bd9Sstevel@tonic-gate pxp = pyp = -9999;
1777c478bd9Sstevel@tonic-gate for (i = 0; i < N-1; i++) { /* interval */
1787c478bd9Sstevel@tonic-gate numdots = (dist(x[i],y[i], x[i+1],y[i+1]) + dist(x[i+1],y[i+1], x[i+2],y[i+2])) / 2;
1797c478bd9Sstevel@tonic-gate numdots /= DX;
1807c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1817c478bd9Sstevel@tonic-gate for (j = 0; j < numdots; j++) { /* points within */
1827c478bd9Sstevel@tonic-gate w = (float) j / numdots;
1837c478bd9Sstevel@tonic-gate t1 = 0.5 * w * w;
1847c478bd9Sstevel@tonic-gate w = w - 0.5;
1857c478bd9Sstevel@tonic-gate t2 = 0.75 - w * w;
1867c478bd9Sstevel@tonic-gate w = w - 0.5;
1877c478bd9Sstevel@tonic-gate t3 = 0.5 * w * w;
1887c478bd9Sstevel@tonic-gate xp = t1 * x[i+2] + t2 * x[i+1] + t3 * x[i] + 0.5;
1897c478bd9Sstevel@tonic-gate yp = t1 * y[i+2] + t2 * y[i+1] + t3 * y[i] + 0.5;
1907c478bd9Sstevel@tonic-gate if (xp != pxp || yp != pyp) {
1917c478bd9Sstevel@tonic-gate hgoto(xp);
1927c478bd9Sstevel@tonic-gate vgoto(yp);
1937c478bd9Sstevel@tonic-gate put1(drawdot);
1947c478bd9Sstevel@tonic-gate pxp = xp;
1957c478bd9Sstevel@tonic-gate pyp = yp;
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate setsize(osize);
200*e5190c10Smuffin
201*e5190c10Smuffin return (0);
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
getstr(p,temp)2047c478bd9Sstevel@tonic-gate char *getstr(p, temp) /* copy next non-blank string from p to temp, update p */
2057c478bd9Sstevel@tonic-gate char *p, *temp;
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate while (*p == ' ' || *p == '\t' || *p == '\n')
2087c478bd9Sstevel@tonic-gate p++;
2097c478bd9Sstevel@tonic-gate if (*p == '\0') {
2107c478bd9Sstevel@tonic-gate temp[0] = 0;
2117c478bd9Sstevel@tonic-gate return(NULL);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0')
2147c478bd9Sstevel@tonic-gate *temp++ = *p++;
2157c478bd9Sstevel@tonic-gate *temp = '\0';
2167c478bd9Sstevel@tonic-gate return(p);
2177c478bd9Sstevel@tonic-gate }
2187c478bd9Sstevel@tonic-gate
219*e5190c10Smuffin int
drawcirc(d)2207c478bd9Sstevel@tonic-gate drawcirc(d)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate int xc, yc;
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate xc = hpos;
2257c478bd9Sstevel@tonic-gate yc = vpos;
2267c478bd9Sstevel@tonic-gate conicarc(hpos + d/2, -vpos, hpos, -vpos, hpos, -vpos, d/2, d/2);
2277c478bd9Sstevel@tonic-gate hgoto(xc + d); /* circle goes to right side */
2287c478bd9Sstevel@tonic-gate vgoto(yc);
229*e5190c10Smuffin
230*e5190c10Smuffin return (0);
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate
233*e5190c10Smuffin int
dist(x1,y1,x2,y2)2347c478bd9Sstevel@tonic-gate dist(x1, y1, x2, y2) /* integer distance from x1,y1 to x2,y2 */
2357c478bd9Sstevel@tonic-gate {
2367c478bd9Sstevel@tonic-gate float dx, dy;
2377c478bd9Sstevel@tonic-gate
2387c478bd9Sstevel@tonic-gate dx = x2 - x1;
2397c478bd9Sstevel@tonic-gate dy = y2 - y1;
2407c478bd9Sstevel@tonic-gate return sqrt(dx*dx + dy*dy) + 0.5;
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate
243*e5190c10Smuffin int
drawarc(dx1,dy1,dx2,dy2)2447c478bd9Sstevel@tonic-gate drawarc(dx1, dy1, dx2, dy2)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate int x0, y0, x2, y2, r;
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate x0 = hpos + dx1; /* center */
2497c478bd9Sstevel@tonic-gate y0 = vpos + dy1;
2507c478bd9Sstevel@tonic-gate x2 = x0 + dx2; /* "to" */
2517c478bd9Sstevel@tonic-gate y2 = y0 + dy2;
2527c478bd9Sstevel@tonic-gate r = sqrt((float) dx1 * dx1 + (float) dy1 * dy1) + 0.5;
2537c478bd9Sstevel@tonic-gate conicarc(x0, -y0, hpos, -vpos, x2, -y2, r, r);
254*e5190c10Smuffin
255*e5190c10Smuffin return (0);
2567c478bd9Sstevel@tonic-gate }
2577c478bd9Sstevel@tonic-gate
258*e5190c10Smuffin int
drawellip(a,b)2597c478bd9Sstevel@tonic-gate drawellip(a, b)
2607c478bd9Sstevel@tonic-gate {
2617c478bd9Sstevel@tonic-gate int xc, yc;
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate xc = hpos;
2647c478bd9Sstevel@tonic-gate yc = vpos;
2657c478bd9Sstevel@tonic-gate conicarc(hpos + a/2, -vpos, hpos, -vpos, hpos, -vpos, a/2, b/2);
2667c478bd9Sstevel@tonic-gate hgoto(xc + a);
2677c478bd9Sstevel@tonic-gate vgoto(yc);
268*e5190c10Smuffin
269*e5190c10Smuffin return (0);
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate #define sqr(x) (long int)(x)*(x)
2737c478bd9Sstevel@tonic-gate
274*e5190c10Smuffin int
conicarc(x,y,x0,y0,x1,y1,a,b)2757c478bd9Sstevel@tonic-gate conicarc(x, y, x0, y0, x1, y1, a, b)
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate /* based on Bresenham, CACM, Feb 77, pp 102-3 */
2787c478bd9Sstevel@tonic-gate /* by Chris Van Wyk */
2797c478bd9Sstevel@tonic-gate /* capitalized vars are an internal reference frame */
2807c478bd9Sstevel@tonic-gate long dotcount = 0;
2817c478bd9Sstevel@tonic-gate int osize, ofont;
2827c478bd9Sstevel@tonic-gate int xs, ys, xt, yt, Xs, Ys, qs, Xt, Yt, qt,
2837c478bd9Sstevel@tonic-gate M1x, M1y, M2x, M2y, M3x, M3y,
2847c478bd9Sstevel@tonic-gate Q, move, Xc, Yc;
2857c478bd9Sstevel@tonic-gate int ox1, oy1;
2867c478bd9Sstevel@tonic-gate long delta;
2877c478bd9Sstevel@tonic-gate float xc, yc;
2887c478bd9Sstevel@tonic-gate float radius, slope;
2897c478bd9Sstevel@tonic-gate float xstep, ystep;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate osize = size;
2927c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
2937c478bd9Sstevel@tonic-gate ox1 = x1;
2947c478bd9Sstevel@tonic-gate oy1 = y1;
2957c478bd9Sstevel@tonic-gate if (a != b) /* an arc of an ellipse; internally, will still think of circle */
2967c478bd9Sstevel@tonic-gate if (a > b) {
2977c478bd9Sstevel@tonic-gate xstep = (float)a / b;
2987c478bd9Sstevel@tonic-gate ystep = 1;
2997c478bd9Sstevel@tonic-gate radius = b;
3007c478bd9Sstevel@tonic-gate } else {
3017c478bd9Sstevel@tonic-gate xstep = 1;
3027c478bd9Sstevel@tonic-gate ystep = (float)b / a;
3037c478bd9Sstevel@tonic-gate radius = a;
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate else { /* a circular arc; radius is computed from center and first point */
3067c478bd9Sstevel@tonic-gate xstep = ystep = 1;
3077c478bd9Sstevel@tonic-gate radius = sqrt((float)(sqr(x0 - x) + sqr(y0 - y)));
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate
3117c478bd9Sstevel@tonic-gate xc = x0;
3127c478bd9Sstevel@tonic-gate yc = y0;
3137c478bd9Sstevel@tonic-gate /* now, use start and end point locations to figure out
3147c478bd9Sstevel@tonic-gate the angle at which start and end happen; use these
3157c478bd9Sstevel@tonic-gate angles with known radius to figure out where start
3167c478bd9Sstevel@tonic-gate and end should be
3177c478bd9Sstevel@tonic-gate */
3187c478bd9Sstevel@tonic-gate slope = atan2((double)(y0 - y), (double)(x0 - x) );
3197c478bd9Sstevel@tonic-gate if (slope == 0.0 && x0 < x)
3207c478bd9Sstevel@tonic-gate slope = 3.14159265;
3217c478bd9Sstevel@tonic-gate x0 = x + radius * cos(slope) + 0.5;
3227c478bd9Sstevel@tonic-gate y0 = y + radius * sin(slope) + 0.5;
3237c478bd9Sstevel@tonic-gate slope = atan2((double)(y1 - y), (double)(x1 - x));
3247c478bd9Sstevel@tonic-gate if (slope == 0.0 && x1 < x)
3257c478bd9Sstevel@tonic-gate slope = 3.14159265;
3267c478bd9Sstevel@tonic-gate x1 = x + radius * cos(slope) + 0.5;
3277c478bd9Sstevel@tonic-gate y1 = y + radius * sin(slope) + 0.5;
3287c478bd9Sstevel@tonic-gate /* step 2: translate to zero-centered circle */
3297c478bd9Sstevel@tonic-gate xs = x0 - x;
3307c478bd9Sstevel@tonic-gate ys = y0 - y;
3317c478bd9Sstevel@tonic-gate xt = x1 - x;
3327c478bd9Sstevel@tonic-gate yt = y1 - y;
3337c478bd9Sstevel@tonic-gate /* step 3: normalize to first quadrant */
3347c478bd9Sstevel@tonic-gate if (xs < 0)
3357c478bd9Sstevel@tonic-gate if (ys < 0) {
3367c478bd9Sstevel@tonic-gate Xs = abs(ys);
3377c478bd9Sstevel@tonic-gate Ys = abs(xs);
3387c478bd9Sstevel@tonic-gate qs = 3;
3397c478bd9Sstevel@tonic-gate M1x = 0;
3407c478bd9Sstevel@tonic-gate M1y = -1;
3417c478bd9Sstevel@tonic-gate M2x = 1;
3427c478bd9Sstevel@tonic-gate M2y = -1;
3437c478bd9Sstevel@tonic-gate M3x = 1;
3447c478bd9Sstevel@tonic-gate M3y = 0;
3457c478bd9Sstevel@tonic-gate } else {
3467c478bd9Sstevel@tonic-gate Xs = abs(xs);
3477c478bd9Sstevel@tonic-gate Ys = abs(ys);
3487c478bd9Sstevel@tonic-gate qs = 2;
3497c478bd9Sstevel@tonic-gate M1x = -1;
3507c478bd9Sstevel@tonic-gate M1y = 0;
3517c478bd9Sstevel@tonic-gate M2x = -1;
3527c478bd9Sstevel@tonic-gate M2y = -1;
3537c478bd9Sstevel@tonic-gate M3x = 0;
3547c478bd9Sstevel@tonic-gate M3y = -1;
3557c478bd9Sstevel@tonic-gate }
3567c478bd9Sstevel@tonic-gate else if (ys < 0) {
3577c478bd9Sstevel@tonic-gate Xs = abs(xs);
3587c478bd9Sstevel@tonic-gate Ys = abs(ys);
3597c478bd9Sstevel@tonic-gate qs = 0;
3607c478bd9Sstevel@tonic-gate M1x = 1;
3617c478bd9Sstevel@tonic-gate M1y = 0;
3627c478bd9Sstevel@tonic-gate M2x = 1;
3637c478bd9Sstevel@tonic-gate M2y = 1;
3647c478bd9Sstevel@tonic-gate M3x = 0;
3657c478bd9Sstevel@tonic-gate M3y = 1;
3667c478bd9Sstevel@tonic-gate } else {
3677c478bd9Sstevel@tonic-gate Xs = abs(ys);
3687c478bd9Sstevel@tonic-gate Ys = abs(xs);
3697c478bd9Sstevel@tonic-gate qs = 1;
3707c478bd9Sstevel@tonic-gate M1x = 0;
3717c478bd9Sstevel@tonic-gate M1y = 1;
3727c478bd9Sstevel@tonic-gate M2x = -1;
3737c478bd9Sstevel@tonic-gate M2y = 1;
3747c478bd9Sstevel@tonic-gate M3x = -1;
3757c478bd9Sstevel@tonic-gate M3y = 0;
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate Xc = Xs;
3807c478bd9Sstevel@tonic-gate Yc = Ys;
3817c478bd9Sstevel@tonic-gate if (xt < 0)
3827c478bd9Sstevel@tonic-gate if (yt < 0) {
3837c478bd9Sstevel@tonic-gate Xt = abs(yt);
3847c478bd9Sstevel@tonic-gate Yt = abs(xt);
3857c478bd9Sstevel@tonic-gate qt = 3;
3867c478bd9Sstevel@tonic-gate } else {
3877c478bd9Sstevel@tonic-gate Xt = abs(xt);
3887c478bd9Sstevel@tonic-gate Yt = abs(yt);
3897c478bd9Sstevel@tonic-gate qt = 2;
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate else if (yt < 0) {
3927c478bd9Sstevel@tonic-gate Xt = abs(xt);
3937c478bd9Sstevel@tonic-gate Yt = abs(yt);
3947c478bd9Sstevel@tonic-gate qt = 0;
3957c478bd9Sstevel@tonic-gate } else {
3967c478bd9Sstevel@tonic-gate Xt = abs(yt);
3977c478bd9Sstevel@tonic-gate Yt = abs(xt);
3987c478bd9Sstevel@tonic-gate qt = 1;
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate /* step 4: calculate number of quadrant crossings */
4037c478bd9Sstevel@tonic-gate if (((4 + qt - qs)
4047c478bd9Sstevel@tonic-gate % 4 == 0)
4057c478bd9Sstevel@tonic-gate && (Xt <= Xs)
4067c478bd9Sstevel@tonic-gate && (Yt >= Ys)
4077c478bd9Sstevel@tonic-gate )
4087c478bd9Sstevel@tonic-gate Q = 3;
4097c478bd9Sstevel@tonic-gate else
4107c478bd9Sstevel@tonic-gate Q = (4 + qt - qs) % 4 - 1;
4117c478bd9Sstevel@tonic-gate /* step 5: calculate initial decision difference */
4127c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1)
4137c478bd9Sstevel@tonic-gate + sqr(Ys - 1)
4147c478bd9Sstevel@tonic-gate -sqr(xs)
4157c478bd9Sstevel@tonic-gate -sqr(ys);
4167c478bd9Sstevel@tonic-gate /* here begins the work of drawing
4177c478bd9Sstevel@tonic-gate we hope it ends here too */
4187c478bd9Sstevel@tonic-gate while ((Q >= 0)
4197c478bd9Sstevel@tonic-gate || ((Q > -2)
4207c478bd9Sstevel@tonic-gate && ((Xt > Xc)
4217c478bd9Sstevel@tonic-gate && (Yt < Yc)
4227c478bd9Sstevel@tonic-gate )
4237c478bd9Sstevel@tonic-gate )
4247c478bd9Sstevel@tonic-gate ) {
4257c478bd9Sstevel@tonic-gate if (dotcount++ % DX == 0)
4267c478bd9Sstevel@tonic-gate putdot((int)xc, (int)yc);
4277c478bd9Sstevel@tonic-gate if (Yc < 0.5) {
4287c478bd9Sstevel@tonic-gate /* reinitialize */
4297c478bd9Sstevel@tonic-gate Xs = Xc = 0;
4307c478bd9Sstevel@tonic-gate Ys = Yc = sqrt((float)(sqr(xs) + sqr(ys)));
4317c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1) + sqr(Ys - 1) - sqr(xs) - sqr(ys);
4327c478bd9Sstevel@tonic-gate Q--;
4337c478bd9Sstevel@tonic-gate M1x = M3x;
4347c478bd9Sstevel@tonic-gate M1y = M3y;
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate int T;
4377c478bd9Sstevel@tonic-gate T = M2y;
4387c478bd9Sstevel@tonic-gate M2y = M2x;
4397c478bd9Sstevel@tonic-gate M2x = -T;
4407c478bd9Sstevel@tonic-gate T = M3y;
4417c478bd9Sstevel@tonic-gate M3y = M3x;
4427c478bd9Sstevel@tonic-gate M3x = -T;
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate } else {
4457c478bd9Sstevel@tonic-gate if (delta <= 0)
4467c478bd9Sstevel@tonic-gate if (2 * delta + 2 * Yc - 1 <= 0)
4477c478bd9Sstevel@tonic-gate move = 1;
4487c478bd9Sstevel@tonic-gate else
4497c478bd9Sstevel@tonic-gate move = 2;
4507c478bd9Sstevel@tonic-gate else if (2 * delta - 2 * Xc - 1 <= 0)
4517c478bd9Sstevel@tonic-gate move = 2;
4527c478bd9Sstevel@tonic-gate else
4537c478bd9Sstevel@tonic-gate move = 3;
4547c478bd9Sstevel@tonic-gate switch (move) {
4557c478bd9Sstevel@tonic-gate case 1:
4567c478bd9Sstevel@tonic-gate Xc++;
4577c478bd9Sstevel@tonic-gate delta += 2 * Xc + 1;
4587c478bd9Sstevel@tonic-gate xc += M1x * xstep;
4597c478bd9Sstevel@tonic-gate yc += M1y * ystep;
4607c478bd9Sstevel@tonic-gate break;
4617c478bd9Sstevel@tonic-gate case 2:
4627c478bd9Sstevel@tonic-gate Xc++;
4637c478bd9Sstevel@tonic-gate Yc--;
4647c478bd9Sstevel@tonic-gate delta += 2 * Xc - 2 * Yc + 2;
4657c478bd9Sstevel@tonic-gate xc += M2x * xstep;
4667c478bd9Sstevel@tonic-gate yc += M2y * ystep;
4677c478bd9Sstevel@tonic-gate break;
4687c478bd9Sstevel@tonic-gate case 3:
4697c478bd9Sstevel@tonic-gate Yc--;
4707c478bd9Sstevel@tonic-gate delta -= 2 * Yc + 1;
4717c478bd9Sstevel@tonic-gate xc += M3x * xstep;
4727c478bd9Sstevel@tonic-gate yc += M3y * ystep;
4737c478bd9Sstevel@tonic-gate break;
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate }
4767c478bd9Sstevel@tonic-gate }
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate setsize(osize);
4807c478bd9Sstevel@tonic-gate drawline((int)xc-ox1,(int)yc-oy1,".");
481*e5190c10Smuffin
482*e5190c10Smuffin return (0);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate
485*e5190c10Smuffin int
putdot(x,y)4867c478bd9Sstevel@tonic-gate putdot(x, y)
4877c478bd9Sstevel@tonic-gate {
4887c478bd9Sstevel@tonic-gate arcmove(x, y);
4897c478bd9Sstevel@tonic-gate put1(drawdot);
490*e5190c10Smuffin
491*e5190c10Smuffin return (0);
4927c478bd9Sstevel@tonic-gate }
493