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 */
28*e0dcd577SToomas Soome /* 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
407c478bd9Sstevel@tonic-gate #include <stdio.h>
417c478bd9Sstevel@tonic-gate #include <math.h>
427c478bd9Sstevel@tonic-gate #define PI 3.141592654
437c478bd9Sstevel@tonic-gate #define hmot(n) hpos += n
447c478bd9Sstevel@tonic-gate #define hgoto(n) hpos = n
457c478bd9Sstevel@tonic-gate #define vmot(n) vgoto(vpos + n)
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate extern int hpos;
487c478bd9Sstevel@tonic-gate extern int vpos;
497c478bd9Sstevel@tonic-gate extern int size;
507c478bd9Sstevel@tonic-gate extern short *pstab;
517c478bd9Sstevel@tonic-gate extern int DX; /* step size in x */
527c478bd9Sstevel@tonic-gate extern int DY; /* step size in y */
537c478bd9Sstevel@tonic-gate extern int drawdot; /* character to use when drawing */
547c478bd9Sstevel@tonic-gate extern int drawsize; /* shrink point size by this facter */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate int maxdots = 32000; /* maximum number of dots in an object */
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate #define sgn(n) ((n > 0) ? 1 : ((n < 0) ? -1 : 0))
597c478bd9Sstevel@tonic-gate #define abs(n) ((n) >= 0 ? (n) : -(n))
607c478bd9Sstevel@tonic-gate #define max(x,y) ((x) > (y) ? (x) : (y))
617c478bd9Sstevel@tonic-gate #define min(x,y) ((x) < (y) ? (x) : (y))
627c478bd9Sstevel@tonic-gate #define arcmove(x,y) { hgoto(x); vmot(-vpos-(y)); }
637c478bd9Sstevel@tonic-gate
64*e0dcd577SToomas Soome /* draw line from here to dx, dy using s */
65e5190c10Smuffin int
drawline(int dx,int dy,char * s)66*e0dcd577SToomas Soome drawline(int dx, int dy, char *s)
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate int xd, yd;
697c478bd9Sstevel@tonic-gate float val, slope;
707c478bd9Sstevel@tonic-gate int i, numdots;
717c478bd9Sstevel@tonic-gate int dirmot, perp;
727c478bd9Sstevel@tonic-gate int motincr, perpincr;
737c478bd9Sstevel@tonic-gate int ohpos, ovpos, osize, ofont;
747c478bd9Sstevel@tonic-gate float incrway;
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate int itemp; /*temp. storage for value returned byint function sgn*/
777c478bd9Sstevel@tonic-gate osize = size;
787c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
797c478bd9Sstevel@tonic-gate ohpos = hpos;
807c478bd9Sstevel@tonic-gate ovpos = vpos;
817c478bd9Sstevel@tonic-gate xd = dx / DX;
827c478bd9Sstevel@tonic-gate yd = dy / DX;
837c478bd9Sstevel@tonic-gate if (xd == 0) {
847c478bd9Sstevel@tonic-gate numdots = abs (yd);
857c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
867c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd);
877c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
887c478bd9Sstevel@tonic-gate vmot(motincr);
897c478bd9Sstevel@tonic-gate put1(drawdot);
907c478bd9Sstevel@tonic-gate }
917c478bd9Sstevel@tonic-gate vgoto(ovpos + dy);
927c478bd9Sstevel@tonic-gate setsize(osize);
93e5190c10Smuffin return (0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate if (yd == 0) {
967c478bd9Sstevel@tonic-gate numdots = abs (xd);
977c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd);
987c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
997c478bd9Sstevel@tonic-gate hmot(motincr);
1007c478bd9Sstevel@tonic-gate put1(drawdot);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate hgoto(ohpos + dx);
1037c478bd9Sstevel@tonic-gate setsize(osize);
104e5190c10Smuffin return (0);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate if (abs (xd) > abs (yd)) {
1077c478bd9Sstevel@tonic-gate val = slope = (float) xd/yd;
1087c478bd9Sstevel@tonic-gate numdots = abs (xd);
1097c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1107c478bd9Sstevel@tonic-gate dirmot = 'h';
1117c478bd9Sstevel@tonic-gate perp = 'v';
1127c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd);
1137c478bd9Sstevel@tonic-gate perpincr = DX * sgn (yd);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate else {
1167c478bd9Sstevel@tonic-gate val = slope = (float) yd/xd;
1177c478bd9Sstevel@tonic-gate numdots = abs (yd);
1187c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1197c478bd9Sstevel@tonic-gate dirmot = 'v';
1207c478bd9Sstevel@tonic-gate perp = 'h';
1217c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd);
1227c478bd9Sstevel@tonic-gate perpincr = DX * sgn (xd);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate incrway = itemp = sgn ((int) slope);
1257c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) {
1267c478bd9Sstevel@tonic-gate val -= incrway;
1277c478bd9Sstevel@tonic-gate if (dirmot == 'h')
1287c478bd9Sstevel@tonic-gate hmot(motincr);
1297c478bd9Sstevel@tonic-gate else
1307c478bd9Sstevel@tonic-gate vmot(motincr);
1317c478bd9Sstevel@tonic-gate if (val * slope < 0) {
1327c478bd9Sstevel@tonic-gate if (perp == 'h')
1337c478bd9Sstevel@tonic-gate hmot(perpincr);
1347c478bd9Sstevel@tonic-gate else
1357c478bd9Sstevel@tonic-gate vmot(perpincr);
1367c478bd9Sstevel@tonic-gate val += slope;
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate put1(drawdot);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate hgoto(ohpos + dx);
1417c478bd9Sstevel@tonic-gate vgoto(ovpos + dy);
1427c478bd9Sstevel@tonic-gate setsize(osize);
143e5190c10Smuffin
144e5190c10Smuffin return (0);
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate
147e5190c10Smuffin int
drawwig(char * s)148*e0dcd577SToomas Soome drawwig(char *s) /* draw wiggly line */
1497c478bd9Sstevel@tonic-gate {
1507c478bd9Sstevel@tonic-gate int x[50], y[50], xp, yp, pxp, pyp;
1517c478bd9Sstevel@tonic-gate float t1, t2, t3, w;
1527c478bd9Sstevel@tonic-gate int i, j, numdots, N;
1537c478bd9Sstevel@tonic-gate int osize, ofont;
1547c478bd9Sstevel@tonic-gate char temp[50], *p, *getstr();
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate osize = size;
1577c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
1587c478bd9Sstevel@tonic-gate p = s;
1597c478bd9Sstevel@tonic-gate for (N = 2; (p=getstr(p,temp)) != NULL && N < sizeof(x)/sizeof(x[0]); N++) {
1607c478bd9Sstevel@tonic-gate x[N] = atoi(temp);
1617c478bd9Sstevel@tonic-gate p = getstr(p, temp);
1627c478bd9Sstevel@tonic-gate y[N] = atoi(temp);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate x[0] = x[1] = hpos;
1657c478bd9Sstevel@tonic-gate y[0] = y[1] = vpos;
1667c478bd9Sstevel@tonic-gate for (i = 1; i < N; i++) {
1677c478bd9Sstevel@tonic-gate x[i+1] += x[i];
1687c478bd9Sstevel@tonic-gate y[i+1] += y[i];
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate x[N] = x[N-1];
1717c478bd9Sstevel@tonic-gate y[N] = y[N-1];
1727c478bd9Sstevel@tonic-gate pxp = pyp = -9999;
1737c478bd9Sstevel@tonic-gate for (i = 0; i < N-1; i++) { /* interval */
1747c478bd9Sstevel@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;
1757c478bd9Sstevel@tonic-gate numdots /= DX;
1767c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots);
1777c478bd9Sstevel@tonic-gate for (j = 0; j < numdots; j++) { /* points within */
1787c478bd9Sstevel@tonic-gate w = (float) j / numdots;
1797c478bd9Sstevel@tonic-gate t1 = 0.5 * w * w;
1807c478bd9Sstevel@tonic-gate w = w - 0.5;
1817c478bd9Sstevel@tonic-gate t2 = 0.75 - w * w;
1827c478bd9Sstevel@tonic-gate w = w - 0.5;
1837c478bd9Sstevel@tonic-gate t3 = 0.5 * w * w;
1847c478bd9Sstevel@tonic-gate xp = t1 * x[i+2] + t2 * x[i+1] + t3 * x[i] + 0.5;
1857c478bd9Sstevel@tonic-gate yp = t1 * y[i+2] + t2 * y[i+1] + t3 * y[i] + 0.5;
1867c478bd9Sstevel@tonic-gate if (xp != pxp || yp != pyp) {
1877c478bd9Sstevel@tonic-gate hgoto(xp);
1887c478bd9Sstevel@tonic-gate vgoto(yp);
1897c478bd9Sstevel@tonic-gate put1(drawdot);
1907c478bd9Sstevel@tonic-gate pxp = xp;
1917c478bd9Sstevel@tonic-gate pyp = yp;
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate }
1957c478bd9Sstevel@tonic-gate setsize(osize);
196e5190c10Smuffin
197e5190c10Smuffin return (0);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate
200*e0dcd577SToomas Soome /* copy next non-blank string from p to temp, update p */
getstr(char * p,char * temp)201*e0dcd577SToomas Soome char *getstr(char *p, char *temp)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate while (*p == ' ' || *p == '\t' || *p == '\n')
2047c478bd9Sstevel@tonic-gate p++;
2057c478bd9Sstevel@tonic-gate if (*p == '\0') {
2067c478bd9Sstevel@tonic-gate temp[0] = 0;
2077c478bd9Sstevel@tonic-gate return(NULL);
2087c478bd9Sstevel@tonic-gate }
2097c478bd9Sstevel@tonic-gate while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0')
2107c478bd9Sstevel@tonic-gate *temp++ = *p++;
2117c478bd9Sstevel@tonic-gate *temp = '\0';
2127c478bd9Sstevel@tonic-gate return(p);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate
215e5190c10Smuffin int
drawcirc(int d)216*e0dcd577SToomas Soome drawcirc(int d)
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate int xc, yc;
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate xc = hpos;
2217c478bd9Sstevel@tonic-gate yc = vpos;
2227c478bd9Sstevel@tonic-gate conicarc(hpos + d/2, -vpos, hpos, -vpos, hpos, -vpos, d/2, d/2);
2237c478bd9Sstevel@tonic-gate hgoto(xc + d); /* circle goes to right side */
2247c478bd9Sstevel@tonic-gate vgoto(yc);
225e5190c10Smuffin
226e5190c10Smuffin return (0);
2277c478bd9Sstevel@tonic-gate }
2287c478bd9Sstevel@tonic-gate
229*e0dcd577SToomas Soome /* integer distance from x1,y1 to x2,y2 */
230e5190c10Smuffin int
dist(int x1,int y1,int x2,int y2)231*e0dcd577SToomas Soome dist(int x1, int y1, int x2, int y2)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate float dx, dy;
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate dx = x2 - x1;
2367c478bd9Sstevel@tonic-gate dy = y2 - y1;
2377c478bd9Sstevel@tonic-gate return sqrt(dx*dx + dy*dy) + 0.5;
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate
240e5190c10Smuffin int
drawarc(int dx1,int dy1,int dx2,int dy2)241*e0dcd577SToomas Soome drawarc(int dx1, int dy1, int dx2, int dy2)
2427c478bd9Sstevel@tonic-gate {
2437c478bd9Sstevel@tonic-gate int x0, y0, x2, y2, r;
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate x0 = hpos + dx1; /* center */
2467c478bd9Sstevel@tonic-gate y0 = vpos + dy1;
2477c478bd9Sstevel@tonic-gate x2 = x0 + dx2; /* "to" */
2487c478bd9Sstevel@tonic-gate y2 = y0 + dy2;
2497c478bd9Sstevel@tonic-gate r = sqrt((float) dx1 * dx1 + (float) dy1 * dy1) + 0.5;
2507c478bd9Sstevel@tonic-gate conicarc(x0, -y0, hpos, -vpos, x2, -y2, r, r);
251e5190c10Smuffin
252e5190c10Smuffin return (0);
2537c478bd9Sstevel@tonic-gate }
2547c478bd9Sstevel@tonic-gate
255e5190c10Smuffin int
drawellip(int a,int b)256*e0dcd577SToomas Soome drawellip(int a, int b)
2577c478bd9Sstevel@tonic-gate {
2587c478bd9Sstevel@tonic-gate int xc, yc;
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate xc = hpos;
2617c478bd9Sstevel@tonic-gate yc = vpos;
2627c478bd9Sstevel@tonic-gate conicarc(hpos + a/2, -vpos, hpos, -vpos, hpos, -vpos, a/2, b/2);
2637c478bd9Sstevel@tonic-gate hgoto(xc + a);
2647c478bd9Sstevel@tonic-gate vgoto(yc);
265e5190c10Smuffin
266e5190c10Smuffin return (0);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate #define sqr(x) (long int)(x)*(x)
2707c478bd9Sstevel@tonic-gate
271e5190c10Smuffin int
conicarc(int x,int y,int x0,int y0,int x1,int y1,int a,int b)272*e0dcd577SToomas Soome conicarc(int x, int y, int x0, int y0, int x1, int y1, int a, int b)
2737c478bd9Sstevel@tonic-gate {
2747c478bd9Sstevel@tonic-gate /* based on Bresenham, CACM, Feb 77, pp 102-3 */
2757c478bd9Sstevel@tonic-gate /* by Chris Van Wyk */
2767c478bd9Sstevel@tonic-gate /* capitalized vars are an internal reference frame */
2777c478bd9Sstevel@tonic-gate long dotcount = 0;
2787c478bd9Sstevel@tonic-gate int osize, ofont;
2797c478bd9Sstevel@tonic-gate int xs, ys, xt, yt, Xs, Ys, qs, Xt, Yt, qt,
2807c478bd9Sstevel@tonic-gate M1x, M1y, M2x, M2y, M3x, M3y,
2817c478bd9Sstevel@tonic-gate Q, move, Xc, Yc;
2827c478bd9Sstevel@tonic-gate int ox1, oy1;
2837c478bd9Sstevel@tonic-gate long delta;
2847c478bd9Sstevel@tonic-gate float xc, yc;
2857c478bd9Sstevel@tonic-gate float radius, slope;
2867c478bd9Sstevel@tonic-gate float xstep, ystep;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate osize = size;
2897c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize));
2907c478bd9Sstevel@tonic-gate ox1 = x1;
2917c478bd9Sstevel@tonic-gate oy1 = y1;
2927c478bd9Sstevel@tonic-gate if (a != b) /* an arc of an ellipse; internally, will still think of circle */
2937c478bd9Sstevel@tonic-gate if (a > b) {
2947c478bd9Sstevel@tonic-gate xstep = (float)a / b;
2957c478bd9Sstevel@tonic-gate ystep = 1;
2967c478bd9Sstevel@tonic-gate radius = b;
2977c478bd9Sstevel@tonic-gate } else {
2987c478bd9Sstevel@tonic-gate xstep = 1;
2997c478bd9Sstevel@tonic-gate ystep = (float)b / a;
3007c478bd9Sstevel@tonic-gate radius = a;
3012a8bcb4eSToomas Soome }
3022a8bcb4eSToomas Soome else { /* a circular arc; radius is computed from center and first point */
3037c478bd9Sstevel@tonic-gate xstep = ystep = 1;
3047c478bd9Sstevel@tonic-gate radius = sqrt((float)(sqr(x0 - x) + sqr(y0 - y)));
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate xc = x0;
3097c478bd9Sstevel@tonic-gate yc = y0;
3107c478bd9Sstevel@tonic-gate /* now, use start and end point locations to figure out
3117c478bd9Sstevel@tonic-gate the angle at which start and end happen; use these
3127c478bd9Sstevel@tonic-gate angles with known radius to figure out where start
3137c478bd9Sstevel@tonic-gate and end should be
3147c478bd9Sstevel@tonic-gate */
3157c478bd9Sstevel@tonic-gate slope = atan2((double)(y0 - y), (double)(x0 - x) );
3167c478bd9Sstevel@tonic-gate if (slope == 0.0 && x0 < x)
3177c478bd9Sstevel@tonic-gate slope = 3.14159265;
3187c478bd9Sstevel@tonic-gate x0 = x + radius * cos(slope) + 0.5;
3197c478bd9Sstevel@tonic-gate y0 = y + radius * sin(slope) + 0.5;
3207c478bd9Sstevel@tonic-gate slope = atan2((double)(y1 - y), (double)(x1 - x));
3217c478bd9Sstevel@tonic-gate if (slope == 0.0 && x1 < x)
3227c478bd9Sstevel@tonic-gate slope = 3.14159265;
3237c478bd9Sstevel@tonic-gate x1 = x + radius * cos(slope) + 0.5;
3247c478bd9Sstevel@tonic-gate y1 = y + radius * sin(slope) + 0.5;
3257c478bd9Sstevel@tonic-gate /* step 2: translate to zero-centered circle */
3267c478bd9Sstevel@tonic-gate xs = x0 - x;
3277c478bd9Sstevel@tonic-gate ys = y0 - y;
3287c478bd9Sstevel@tonic-gate xt = x1 - x;
3297c478bd9Sstevel@tonic-gate yt = y1 - y;
3307c478bd9Sstevel@tonic-gate /* step 3: normalize to first quadrant */
3317c478bd9Sstevel@tonic-gate if (xs < 0)
3327c478bd9Sstevel@tonic-gate if (ys < 0) {
3337c478bd9Sstevel@tonic-gate Xs = abs(ys);
3347c478bd9Sstevel@tonic-gate Ys = abs(xs);
3357c478bd9Sstevel@tonic-gate qs = 3;
3367c478bd9Sstevel@tonic-gate M1x = 0;
3377c478bd9Sstevel@tonic-gate M1y = -1;
3387c478bd9Sstevel@tonic-gate M2x = 1;
3397c478bd9Sstevel@tonic-gate M2y = -1;
3407c478bd9Sstevel@tonic-gate M3x = 1;
3417c478bd9Sstevel@tonic-gate M3y = 0;
3427c478bd9Sstevel@tonic-gate } else {
3437c478bd9Sstevel@tonic-gate Xs = abs(xs);
3447c478bd9Sstevel@tonic-gate Ys = abs(ys);
3457c478bd9Sstevel@tonic-gate qs = 2;
3467c478bd9Sstevel@tonic-gate M1x = -1;
3477c478bd9Sstevel@tonic-gate M1y = 0;
3487c478bd9Sstevel@tonic-gate M2x = -1;
3497c478bd9Sstevel@tonic-gate M2y = -1;
3507c478bd9Sstevel@tonic-gate M3x = 0;
3517c478bd9Sstevel@tonic-gate M3y = -1;
3522a8bcb4eSToomas Soome }
3537c478bd9Sstevel@tonic-gate else if (ys < 0) {
3547c478bd9Sstevel@tonic-gate Xs = abs(xs);
3557c478bd9Sstevel@tonic-gate Ys = abs(ys);
3567c478bd9Sstevel@tonic-gate qs = 0;
3577c478bd9Sstevel@tonic-gate M1x = 1;
3587c478bd9Sstevel@tonic-gate M1y = 0;
3597c478bd9Sstevel@tonic-gate M2x = 1;
3607c478bd9Sstevel@tonic-gate M2y = 1;
3617c478bd9Sstevel@tonic-gate M3x = 0;
3627c478bd9Sstevel@tonic-gate M3y = 1;
3637c478bd9Sstevel@tonic-gate } else {
3647c478bd9Sstevel@tonic-gate Xs = abs(ys);
3657c478bd9Sstevel@tonic-gate Ys = abs(xs);
3667c478bd9Sstevel@tonic-gate qs = 1;
3677c478bd9Sstevel@tonic-gate M1x = 0;
3687c478bd9Sstevel@tonic-gate M1y = 1;
3697c478bd9Sstevel@tonic-gate M2x = -1;
3707c478bd9Sstevel@tonic-gate M2y = 1;
3717c478bd9Sstevel@tonic-gate M3x = -1;
3727c478bd9Sstevel@tonic-gate M3y = 0;
3737c478bd9Sstevel@tonic-gate }
3747c478bd9Sstevel@tonic-gate
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate Xc = Xs;
3777c478bd9Sstevel@tonic-gate Yc = Ys;
3787c478bd9Sstevel@tonic-gate if (xt < 0)
3797c478bd9Sstevel@tonic-gate if (yt < 0) {
3807c478bd9Sstevel@tonic-gate Xt = abs(yt);
3817c478bd9Sstevel@tonic-gate Yt = abs(xt);
3827c478bd9Sstevel@tonic-gate qt = 3;
3837c478bd9Sstevel@tonic-gate } else {
3847c478bd9Sstevel@tonic-gate Xt = abs(xt);
3857c478bd9Sstevel@tonic-gate Yt = abs(yt);
3867c478bd9Sstevel@tonic-gate qt = 2;
3872a8bcb4eSToomas Soome }
3887c478bd9Sstevel@tonic-gate else if (yt < 0) {
3897c478bd9Sstevel@tonic-gate Xt = abs(xt);
3907c478bd9Sstevel@tonic-gate Yt = abs(yt);
3917c478bd9Sstevel@tonic-gate qt = 0;
3927c478bd9Sstevel@tonic-gate } else {
3937c478bd9Sstevel@tonic-gate Xt = abs(yt);
3947c478bd9Sstevel@tonic-gate Yt = abs(xt);
3957c478bd9Sstevel@tonic-gate qt = 1;
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate
3997c478bd9Sstevel@tonic-gate /* step 4: calculate number of quadrant crossings */
4007c478bd9Sstevel@tonic-gate if (((4 + qt - qs)
4017c478bd9Sstevel@tonic-gate % 4 == 0)
4027c478bd9Sstevel@tonic-gate && (Xt <= Xs)
4037c478bd9Sstevel@tonic-gate && (Yt >= Ys)
4047c478bd9Sstevel@tonic-gate )
4057c478bd9Sstevel@tonic-gate Q = 3;
4067c478bd9Sstevel@tonic-gate else
4077c478bd9Sstevel@tonic-gate Q = (4 + qt - qs) % 4 - 1;
4087c478bd9Sstevel@tonic-gate /* step 5: calculate initial decision difference */
4097c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1)
4107c478bd9Sstevel@tonic-gate + sqr(Ys - 1)
4117c478bd9Sstevel@tonic-gate -sqr(xs)
4127c478bd9Sstevel@tonic-gate -sqr(ys);
4137c478bd9Sstevel@tonic-gate /* here begins the work of drawing
4147c478bd9Sstevel@tonic-gate we hope it ends here too */
4157c478bd9Sstevel@tonic-gate while ((Q >= 0)
4167c478bd9Sstevel@tonic-gate || ((Q > -2)
4177c478bd9Sstevel@tonic-gate && ((Xt > Xc)
4187c478bd9Sstevel@tonic-gate && (Yt < Yc)
4197c478bd9Sstevel@tonic-gate )
4207c478bd9Sstevel@tonic-gate )
4217c478bd9Sstevel@tonic-gate ) {
4227c478bd9Sstevel@tonic-gate if (dotcount++ % DX == 0)
4237c478bd9Sstevel@tonic-gate putdot((int)xc, (int)yc);
4247c478bd9Sstevel@tonic-gate if (Yc < 0.5) {
4257c478bd9Sstevel@tonic-gate /* reinitialize */
4267c478bd9Sstevel@tonic-gate Xs = Xc = 0;
4277c478bd9Sstevel@tonic-gate Ys = Yc = sqrt((float)(sqr(xs) + sqr(ys)));
4287c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1) + sqr(Ys - 1) - sqr(xs) - sqr(ys);
4297c478bd9Sstevel@tonic-gate Q--;
4307c478bd9Sstevel@tonic-gate M1x = M3x;
4317c478bd9Sstevel@tonic-gate M1y = M3y;
4327c478bd9Sstevel@tonic-gate {
4337c478bd9Sstevel@tonic-gate int T;
4347c478bd9Sstevel@tonic-gate T = M2y;
4357c478bd9Sstevel@tonic-gate M2y = M2x;
4367c478bd9Sstevel@tonic-gate M2x = -T;
4377c478bd9Sstevel@tonic-gate T = M3y;
4387c478bd9Sstevel@tonic-gate M3y = M3x;
4397c478bd9Sstevel@tonic-gate M3x = -T;
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate } else {
4427c478bd9Sstevel@tonic-gate if (delta <= 0)
4437c478bd9Sstevel@tonic-gate if (2 * delta + 2 * Yc - 1 <= 0)
4447c478bd9Sstevel@tonic-gate move = 1;
4457c478bd9Sstevel@tonic-gate else
4467c478bd9Sstevel@tonic-gate move = 2;
4477c478bd9Sstevel@tonic-gate else if (2 * delta - 2 * Xc - 1 <= 0)
4487c478bd9Sstevel@tonic-gate move = 2;
4497c478bd9Sstevel@tonic-gate else
4507c478bd9Sstevel@tonic-gate move = 3;
4517c478bd9Sstevel@tonic-gate switch (move) {
4527c478bd9Sstevel@tonic-gate case 1:
4537c478bd9Sstevel@tonic-gate Xc++;
4547c478bd9Sstevel@tonic-gate delta += 2 * Xc + 1;
4557c478bd9Sstevel@tonic-gate xc += M1x * xstep;
4567c478bd9Sstevel@tonic-gate yc += M1y * ystep;
4577c478bd9Sstevel@tonic-gate break;
4587c478bd9Sstevel@tonic-gate case 2:
4597c478bd9Sstevel@tonic-gate Xc++;
4607c478bd9Sstevel@tonic-gate Yc--;
4617c478bd9Sstevel@tonic-gate delta += 2 * Xc - 2 * Yc + 2;
4627c478bd9Sstevel@tonic-gate xc += M2x * xstep;
4637c478bd9Sstevel@tonic-gate yc += M2y * ystep;
4647c478bd9Sstevel@tonic-gate break;
4657c478bd9Sstevel@tonic-gate case 3:
4667c478bd9Sstevel@tonic-gate Yc--;
4677c478bd9Sstevel@tonic-gate delta -= 2 * Yc + 1;
4687c478bd9Sstevel@tonic-gate xc += M3x * xstep;
4697c478bd9Sstevel@tonic-gate yc += M3y * ystep;
4707c478bd9Sstevel@tonic-gate break;
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate }
4737c478bd9Sstevel@tonic-gate }
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate
4767c478bd9Sstevel@tonic-gate setsize(osize);
4777c478bd9Sstevel@tonic-gate drawline((int)xc-ox1,(int)yc-oy1,".");
478e5190c10Smuffin
479e5190c10Smuffin return (0);
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate
482e5190c10Smuffin int
putdot(int x,int y)483*e0dcd577SToomas Soome putdot(int x, int y)
4847c478bd9Sstevel@tonic-gate {
4857c478bd9Sstevel@tonic-gate arcmove(x, y);
4867c478bd9Sstevel@tonic-gate put1(drawdot);
487e5190c10Smuffin
488e5190c10Smuffin return (0);
4897c478bd9Sstevel@tonic-gate }
490