1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 1989 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate /* 34*7c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 35*7c478bd9Sstevel@tonic-gate * The Regents of the University of California 36*7c478bd9Sstevel@tonic-gate * All Rights Reserved 37*7c478bd9Sstevel@tonic-gate * 38*7c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 39*7c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 40*7c478bd9Sstevel@tonic-gate * contributors. 41*7c478bd9Sstevel@tonic-gate */ 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate #include <stdio.h> 44*7c478bd9Sstevel@tonic-gate #include <math.h> 45*7c478bd9Sstevel@tonic-gate #define PI 3.141592654 46*7c478bd9Sstevel@tonic-gate #define hmot(n) hpos += n 47*7c478bd9Sstevel@tonic-gate #define hgoto(n) hpos = n 48*7c478bd9Sstevel@tonic-gate #define vmot(n) vgoto(vpos + n) 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate extern int hpos; 51*7c478bd9Sstevel@tonic-gate extern int vpos; 52*7c478bd9Sstevel@tonic-gate extern int size; 53*7c478bd9Sstevel@tonic-gate extern short *pstab; 54*7c478bd9Sstevel@tonic-gate extern int DX; /* step size in x */ 55*7c478bd9Sstevel@tonic-gate extern int DY; /* step size in y */ 56*7c478bd9Sstevel@tonic-gate extern int drawdot; /* character to use when drawing */ 57*7c478bd9Sstevel@tonic-gate extern int drawsize; /* shrink point size by this facter */ 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate int maxdots = 32000; /* maximum number of dots in an object */ 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate #define sgn(n) ((n > 0) ? 1 : ((n < 0) ? -1 : 0)) 62*7c478bd9Sstevel@tonic-gate #define abs(n) ((n) >= 0 ? (n) : -(n)) 63*7c478bd9Sstevel@tonic-gate #define max(x,y) ((x) > (y) ? (x) : (y)) 64*7c478bd9Sstevel@tonic-gate #define min(x,y) ((x) < (y) ? (x) : (y)) 65*7c478bd9Sstevel@tonic-gate #define arcmove(x,y) { hgoto(x); vmot(-vpos-(y)); } 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate drawline(dx, dy, s) /* draw line from here to dx, dy using s */ 68*7c478bd9Sstevel@tonic-gate int dx, dy; 69*7c478bd9Sstevel@tonic-gate char *s; 70*7c478bd9Sstevel@tonic-gate { 71*7c478bd9Sstevel@tonic-gate int xd, yd; 72*7c478bd9Sstevel@tonic-gate float val, slope; 73*7c478bd9Sstevel@tonic-gate int i, numdots; 74*7c478bd9Sstevel@tonic-gate int dirmot, perp; 75*7c478bd9Sstevel@tonic-gate int motincr, perpincr; 76*7c478bd9Sstevel@tonic-gate int ohpos, ovpos, osize, ofont; 77*7c478bd9Sstevel@tonic-gate float incrway; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate int itemp; /*temp. storage for value returned byint function sgn*/ 80*7c478bd9Sstevel@tonic-gate osize = size; 81*7c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize)); 82*7c478bd9Sstevel@tonic-gate ohpos = hpos; 83*7c478bd9Sstevel@tonic-gate ovpos = vpos; 84*7c478bd9Sstevel@tonic-gate xd = dx / DX; 85*7c478bd9Sstevel@tonic-gate yd = dy / DX; 86*7c478bd9Sstevel@tonic-gate if (xd == 0) { 87*7c478bd9Sstevel@tonic-gate numdots = abs (yd); 88*7c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots); 89*7c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd); 90*7c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) { 91*7c478bd9Sstevel@tonic-gate vmot(motincr); 92*7c478bd9Sstevel@tonic-gate put1(drawdot); 93*7c478bd9Sstevel@tonic-gate } 94*7c478bd9Sstevel@tonic-gate vgoto(ovpos + dy); 95*7c478bd9Sstevel@tonic-gate setsize(osize); 96*7c478bd9Sstevel@tonic-gate return; 97*7c478bd9Sstevel@tonic-gate } 98*7c478bd9Sstevel@tonic-gate if (yd == 0) { 99*7c478bd9Sstevel@tonic-gate numdots = abs (xd); 100*7c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd); 101*7c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) { 102*7c478bd9Sstevel@tonic-gate hmot(motincr); 103*7c478bd9Sstevel@tonic-gate put1(drawdot); 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate hgoto(ohpos + dx); 106*7c478bd9Sstevel@tonic-gate setsize(osize); 107*7c478bd9Sstevel@tonic-gate return; 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate if (abs (xd) > abs (yd)) { 110*7c478bd9Sstevel@tonic-gate val = slope = (float) xd/yd; 111*7c478bd9Sstevel@tonic-gate numdots = abs (xd); 112*7c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots); 113*7c478bd9Sstevel@tonic-gate dirmot = 'h'; 114*7c478bd9Sstevel@tonic-gate perp = 'v'; 115*7c478bd9Sstevel@tonic-gate motincr = DX * sgn (xd); 116*7c478bd9Sstevel@tonic-gate perpincr = DX * sgn (yd); 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate else { 119*7c478bd9Sstevel@tonic-gate val = slope = (float) yd/xd; 120*7c478bd9Sstevel@tonic-gate numdots = abs (yd); 121*7c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots); 122*7c478bd9Sstevel@tonic-gate dirmot = 'v'; 123*7c478bd9Sstevel@tonic-gate perp = 'h'; 124*7c478bd9Sstevel@tonic-gate motincr = DX * sgn (yd); 125*7c478bd9Sstevel@tonic-gate perpincr = DX * sgn (xd); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate incrway = itemp = sgn ((int) slope); 128*7c478bd9Sstevel@tonic-gate for (i = 0; i < numdots; i++) { 129*7c478bd9Sstevel@tonic-gate val -= incrway; 130*7c478bd9Sstevel@tonic-gate if (dirmot == 'h') 131*7c478bd9Sstevel@tonic-gate hmot(motincr); 132*7c478bd9Sstevel@tonic-gate else 133*7c478bd9Sstevel@tonic-gate vmot(motincr); 134*7c478bd9Sstevel@tonic-gate if (val * slope < 0) { 135*7c478bd9Sstevel@tonic-gate if (perp == 'h') 136*7c478bd9Sstevel@tonic-gate hmot(perpincr); 137*7c478bd9Sstevel@tonic-gate else 138*7c478bd9Sstevel@tonic-gate vmot(perpincr); 139*7c478bd9Sstevel@tonic-gate val += slope; 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate put1(drawdot); 142*7c478bd9Sstevel@tonic-gate } 143*7c478bd9Sstevel@tonic-gate hgoto(ohpos + dx); 144*7c478bd9Sstevel@tonic-gate vgoto(ovpos + dy); 145*7c478bd9Sstevel@tonic-gate setsize(osize); 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate drawwig(s) /* draw wiggly line */ 149*7c478bd9Sstevel@tonic-gate char *s; 150*7c478bd9Sstevel@tonic-gate { 151*7c478bd9Sstevel@tonic-gate int x[50], y[50], xp, yp, pxp, pyp; 152*7c478bd9Sstevel@tonic-gate float t1, t2, t3, w; 153*7c478bd9Sstevel@tonic-gate int i, j, numdots, N; 154*7c478bd9Sstevel@tonic-gate int osize, ofont; 155*7c478bd9Sstevel@tonic-gate char temp[50], *p, *getstr(); 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate osize = size; 158*7c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize)); 159*7c478bd9Sstevel@tonic-gate p = s; 160*7c478bd9Sstevel@tonic-gate for (N = 2; (p=getstr(p,temp)) != NULL && N < sizeof(x)/sizeof(x[0]); N++) { 161*7c478bd9Sstevel@tonic-gate x[N] = atoi(temp); 162*7c478bd9Sstevel@tonic-gate p = getstr(p, temp); 163*7c478bd9Sstevel@tonic-gate y[N] = atoi(temp); 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate x[0] = x[1] = hpos; 166*7c478bd9Sstevel@tonic-gate y[0] = y[1] = vpos; 167*7c478bd9Sstevel@tonic-gate for (i = 1; i < N; i++) { 168*7c478bd9Sstevel@tonic-gate x[i+1] += x[i]; 169*7c478bd9Sstevel@tonic-gate y[i+1] += y[i]; 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate x[N] = x[N-1]; 172*7c478bd9Sstevel@tonic-gate y[N] = y[N-1]; 173*7c478bd9Sstevel@tonic-gate pxp = pyp = -9999; 174*7c478bd9Sstevel@tonic-gate for (i = 0; i < N-1; i++) { /* interval */ 175*7c478bd9Sstevel@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; 176*7c478bd9Sstevel@tonic-gate numdots /= DX; 177*7c478bd9Sstevel@tonic-gate numdots = min(numdots, maxdots); 178*7c478bd9Sstevel@tonic-gate for (j = 0; j < numdots; j++) { /* points within */ 179*7c478bd9Sstevel@tonic-gate w = (float) j / numdots; 180*7c478bd9Sstevel@tonic-gate t1 = 0.5 * w * w; 181*7c478bd9Sstevel@tonic-gate w = w - 0.5; 182*7c478bd9Sstevel@tonic-gate t2 = 0.75 - w * w; 183*7c478bd9Sstevel@tonic-gate w = w - 0.5; 184*7c478bd9Sstevel@tonic-gate t3 = 0.5 * w * w; 185*7c478bd9Sstevel@tonic-gate xp = t1 * x[i+2] + t2 * x[i+1] + t3 * x[i] + 0.5; 186*7c478bd9Sstevel@tonic-gate yp = t1 * y[i+2] + t2 * y[i+1] + t3 * y[i] + 0.5; 187*7c478bd9Sstevel@tonic-gate if (xp != pxp || yp != pyp) { 188*7c478bd9Sstevel@tonic-gate hgoto(xp); 189*7c478bd9Sstevel@tonic-gate vgoto(yp); 190*7c478bd9Sstevel@tonic-gate put1(drawdot); 191*7c478bd9Sstevel@tonic-gate pxp = xp; 192*7c478bd9Sstevel@tonic-gate pyp = yp; 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate } 196*7c478bd9Sstevel@tonic-gate setsize(osize); 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate char *getstr(p, temp) /* copy next non-blank string from p to temp, update p */ 200*7c478bd9Sstevel@tonic-gate char *p, *temp; 201*7c478bd9Sstevel@tonic-gate { 202*7c478bd9Sstevel@tonic-gate while (*p == ' ' || *p == '\t' || *p == '\n') 203*7c478bd9Sstevel@tonic-gate p++; 204*7c478bd9Sstevel@tonic-gate if (*p == '\0') { 205*7c478bd9Sstevel@tonic-gate temp[0] = 0; 206*7c478bd9Sstevel@tonic-gate return(NULL); 207*7c478bd9Sstevel@tonic-gate } 208*7c478bd9Sstevel@tonic-gate while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0') 209*7c478bd9Sstevel@tonic-gate *temp++ = *p++; 210*7c478bd9Sstevel@tonic-gate *temp = '\0'; 211*7c478bd9Sstevel@tonic-gate return(p); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate drawcirc(d) 215*7c478bd9Sstevel@tonic-gate { 216*7c478bd9Sstevel@tonic-gate int xc, yc; 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate xc = hpos; 219*7c478bd9Sstevel@tonic-gate yc = vpos; 220*7c478bd9Sstevel@tonic-gate conicarc(hpos + d/2, -vpos, hpos, -vpos, hpos, -vpos, d/2, d/2); 221*7c478bd9Sstevel@tonic-gate hgoto(xc + d); /* circle goes to right side */ 222*7c478bd9Sstevel@tonic-gate vgoto(yc); 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate dist(x1, y1, x2, y2) /* integer distance from x1,y1 to x2,y2 */ 226*7c478bd9Sstevel@tonic-gate { 227*7c478bd9Sstevel@tonic-gate float dx, dy; 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate dx = x2 - x1; 230*7c478bd9Sstevel@tonic-gate dy = y2 - y1; 231*7c478bd9Sstevel@tonic-gate return sqrt(dx*dx + dy*dy) + 0.5; 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate drawarc(dx1, dy1, dx2, dy2) 235*7c478bd9Sstevel@tonic-gate { 236*7c478bd9Sstevel@tonic-gate int x0, y0, x2, y2, r; 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate x0 = hpos + dx1; /* center */ 239*7c478bd9Sstevel@tonic-gate y0 = vpos + dy1; 240*7c478bd9Sstevel@tonic-gate x2 = x0 + dx2; /* "to" */ 241*7c478bd9Sstevel@tonic-gate y2 = y0 + dy2; 242*7c478bd9Sstevel@tonic-gate r = sqrt((float) dx1 * dx1 + (float) dy1 * dy1) + 0.5; 243*7c478bd9Sstevel@tonic-gate conicarc(x0, -y0, hpos, -vpos, x2, -y2, r, r); 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate 246*7c478bd9Sstevel@tonic-gate drawellip(a, b) 247*7c478bd9Sstevel@tonic-gate { 248*7c478bd9Sstevel@tonic-gate int xc, yc; 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate xc = hpos; 251*7c478bd9Sstevel@tonic-gate yc = vpos; 252*7c478bd9Sstevel@tonic-gate conicarc(hpos + a/2, -vpos, hpos, -vpos, hpos, -vpos, a/2, b/2); 253*7c478bd9Sstevel@tonic-gate hgoto(xc + a); 254*7c478bd9Sstevel@tonic-gate vgoto(yc); 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate #define sqr(x) (long int)(x)*(x) 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate conicarc(x, y, x0, y0, x1, y1, a, b) 260*7c478bd9Sstevel@tonic-gate { 261*7c478bd9Sstevel@tonic-gate /* based on Bresenham, CACM, Feb 77, pp 102-3 */ 262*7c478bd9Sstevel@tonic-gate /* by Chris Van Wyk */ 263*7c478bd9Sstevel@tonic-gate /* capitalized vars are an internal reference frame */ 264*7c478bd9Sstevel@tonic-gate long dotcount = 0; 265*7c478bd9Sstevel@tonic-gate int osize, ofont; 266*7c478bd9Sstevel@tonic-gate int xs, ys, xt, yt, Xs, Ys, qs, Xt, Yt, qt, 267*7c478bd9Sstevel@tonic-gate M1x, M1y, M2x, M2y, M3x, M3y, 268*7c478bd9Sstevel@tonic-gate Q, move, Xc, Yc; 269*7c478bd9Sstevel@tonic-gate int ox1, oy1; 270*7c478bd9Sstevel@tonic-gate long delta; 271*7c478bd9Sstevel@tonic-gate float xc, yc; 272*7c478bd9Sstevel@tonic-gate float radius, slope; 273*7c478bd9Sstevel@tonic-gate float xstep, ystep; 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate osize = size; 276*7c478bd9Sstevel@tonic-gate setsize(t_size(pstab[osize-1] / drawsize)); 277*7c478bd9Sstevel@tonic-gate ox1 = x1; 278*7c478bd9Sstevel@tonic-gate oy1 = y1; 279*7c478bd9Sstevel@tonic-gate if (a != b) /* an arc of an ellipse; internally, will still think of circle */ 280*7c478bd9Sstevel@tonic-gate if (a > b) { 281*7c478bd9Sstevel@tonic-gate xstep = (float)a / b; 282*7c478bd9Sstevel@tonic-gate ystep = 1; 283*7c478bd9Sstevel@tonic-gate radius = b; 284*7c478bd9Sstevel@tonic-gate } else { 285*7c478bd9Sstevel@tonic-gate xstep = 1; 286*7c478bd9Sstevel@tonic-gate ystep = (float)b / a; 287*7c478bd9Sstevel@tonic-gate radius = a; 288*7c478bd9Sstevel@tonic-gate } 289*7c478bd9Sstevel@tonic-gate else { /* a circular arc; radius is computed from center and first point */ 290*7c478bd9Sstevel@tonic-gate xstep = ystep = 1; 291*7c478bd9Sstevel@tonic-gate radius = sqrt((float)(sqr(x0 - x) + sqr(y0 - y))); 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate 295*7c478bd9Sstevel@tonic-gate xc = x0; 296*7c478bd9Sstevel@tonic-gate yc = y0; 297*7c478bd9Sstevel@tonic-gate /* now, use start and end point locations to figure out 298*7c478bd9Sstevel@tonic-gate the angle at which start and end happen; use these 299*7c478bd9Sstevel@tonic-gate angles with known radius to figure out where start 300*7c478bd9Sstevel@tonic-gate and end should be 301*7c478bd9Sstevel@tonic-gate */ 302*7c478bd9Sstevel@tonic-gate slope = atan2((double)(y0 - y), (double)(x0 - x) ); 303*7c478bd9Sstevel@tonic-gate if (slope == 0.0 && x0 < x) 304*7c478bd9Sstevel@tonic-gate slope = 3.14159265; 305*7c478bd9Sstevel@tonic-gate x0 = x + radius * cos(slope) + 0.5; 306*7c478bd9Sstevel@tonic-gate y0 = y + radius * sin(slope) + 0.5; 307*7c478bd9Sstevel@tonic-gate slope = atan2((double)(y1 - y), (double)(x1 - x)); 308*7c478bd9Sstevel@tonic-gate if (slope == 0.0 && x1 < x) 309*7c478bd9Sstevel@tonic-gate slope = 3.14159265; 310*7c478bd9Sstevel@tonic-gate x1 = x + radius * cos(slope) + 0.5; 311*7c478bd9Sstevel@tonic-gate y1 = y + radius * sin(slope) + 0.5; 312*7c478bd9Sstevel@tonic-gate /* step 2: translate to zero-centered circle */ 313*7c478bd9Sstevel@tonic-gate xs = x0 - x; 314*7c478bd9Sstevel@tonic-gate ys = y0 - y; 315*7c478bd9Sstevel@tonic-gate xt = x1 - x; 316*7c478bd9Sstevel@tonic-gate yt = y1 - y; 317*7c478bd9Sstevel@tonic-gate /* step 3: normalize to first quadrant */ 318*7c478bd9Sstevel@tonic-gate if (xs < 0) 319*7c478bd9Sstevel@tonic-gate if (ys < 0) { 320*7c478bd9Sstevel@tonic-gate Xs = abs(ys); 321*7c478bd9Sstevel@tonic-gate Ys = abs(xs); 322*7c478bd9Sstevel@tonic-gate qs = 3; 323*7c478bd9Sstevel@tonic-gate M1x = 0; 324*7c478bd9Sstevel@tonic-gate M1y = -1; 325*7c478bd9Sstevel@tonic-gate M2x = 1; 326*7c478bd9Sstevel@tonic-gate M2y = -1; 327*7c478bd9Sstevel@tonic-gate M3x = 1; 328*7c478bd9Sstevel@tonic-gate M3y = 0; 329*7c478bd9Sstevel@tonic-gate } else { 330*7c478bd9Sstevel@tonic-gate Xs = abs(xs); 331*7c478bd9Sstevel@tonic-gate Ys = abs(ys); 332*7c478bd9Sstevel@tonic-gate qs = 2; 333*7c478bd9Sstevel@tonic-gate M1x = -1; 334*7c478bd9Sstevel@tonic-gate M1y = 0; 335*7c478bd9Sstevel@tonic-gate M2x = -1; 336*7c478bd9Sstevel@tonic-gate M2y = -1; 337*7c478bd9Sstevel@tonic-gate M3x = 0; 338*7c478bd9Sstevel@tonic-gate M3y = -1; 339*7c478bd9Sstevel@tonic-gate } 340*7c478bd9Sstevel@tonic-gate else if (ys < 0) { 341*7c478bd9Sstevel@tonic-gate Xs = abs(xs); 342*7c478bd9Sstevel@tonic-gate Ys = abs(ys); 343*7c478bd9Sstevel@tonic-gate qs = 0; 344*7c478bd9Sstevel@tonic-gate M1x = 1; 345*7c478bd9Sstevel@tonic-gate M1y = 0; 346*7c478bd9Sstevel@tonic-gate M2x = 1; 347*7c478bd9Sstevel@tonic-gate M2y = 1; 348*7c478bd9Sstevel@tonic-gate M3x = 0; 349*7c478bd9Sstevel@tonic-gate M3y = 1; 350*7c478bd9Sstevel@tonic-gate } else { 351*7c478bd9Sstevel@tonic-gate Xs = abs(ys); 352*7c478bd9Sstevel@tonic-gate Ys = abs(xs); 353*7c478bd9Sstevel@tonic-gate qs = 1; 354*7c478bd9Sstevel@tonic-gate M1x = 0; 355*7c478bd9Sstevel@tonic-gate M1y = 1; 356*7c478bd9Sstevel@tonic-gate M2x = -1; 357*7c478bd9Sstevel@tonic-gate M2y = 1; 358*7c478bd9Sstevel@tonic-gate M3x = -1; 359*7c478bd9Sstevel@tonic-gate M3y = 0; 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate Xc = Xs; 364*7c478bd9Sstevel@tonic-gate Yc = Ys; 365*7c478bd9Sstevel@tonic-gate if (xt < 0) 366*7c478bd9Sstevel@tonic-gate if (yt < 0) { 367*7c478bd9Sstevel@tonic-gate Xt = abs(yt); 368*7c478bd9Sstevel@tonic-gate Yt = abs(xt); 369*7c478bd9Sstevel@tonic-gate qt = 3; 370*7c478bd9Sstevel@tonic-gate } else { 371*7c478bd9Sstevel@tonic-gate Xt = abs(xt); 372*7c478bd9Sstevel@tonic-gate Yt = abs(yt); 373*7c478bd9Sstevel@tonic-gate qt = 2; 374*7c478bd9Sstevel@tonic-gate } 375*7c478bd9Sstevel@tonic-gate else if (yt < 0) { 376*7c478bd9Sstevel@tonic-gate Xt = abs(xt); 377*7c478bd9Sstevel@tonic-gate Yt = abs(yt); 378*7c478bd9Sstevel@tonic-gate qt = 0; 379*7c478bd9Sstevel@tonic-gate } else { 380*7c478bd9Sstevel@tonic-gate Xt = abs(yt); 381*7c478bd9Sstevel@tonic-gate Yt = abs(xt); 382*7c478bd9Sstevel@tonic-gate qt = 1; 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate /* step 4: calculate number of quadrant crossings */ 387*7c478bd9Sstevel@tonic-gate if (((4 + qt - qs) 388*7c478bd9Sstevel@tonic-gate % 4 == 0) 389*7c478bd9Sstevel@tonic-gate && (Xt <= Xs) 390*7c478bd9Sstevel@tonic-gate && (Yt >= Ys) 391*7c478bd9Sstevel@tonic-gate ) 392*7c478bd9Sstevel@tonic-gate Q = 3; 393*7c478bd9Sstevel@tonic-gate else 394*7c478bd9Sstevel@tonic-gate Q = (4 + qt - qs) % 4 - 1; 395*7c478bd9Sstevel@tonic-gate /* step 5: calculate initial decision difference */ 396*7c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1) 397*7c478bd9Sstevel@tonic-gate + sqr(Ys - 1) 398*7c478bd9Sstevel@tonic-gate -sqr(xs) 399*7c478bd9Sstevel@tonic-gate -sqr(ys); 400*7c478bd9Sstevel@tonic-gate /* here begins the work of drawing 401*7c478bd9Sstevel@tonic-gate we hope it ends here too */ 402*7c478bd9Sstevel@tonic-gate while ((Q >= 0) 403*7c478bd9Sstevel@tonic-gate || ((Q > -2) 404*7c478bd9Sstevel@tonic-gate && ((Xt > Xc) 405*7c478bd9Sstevel@tonic-gate && (Yt < Yc) 406*7c478bd9Sstevel@tonic-gate ) 407*7c478bd9Sstevel@tonic-gate ) 408*7c478bd9Sstevel@tonic-gate ) { 409*7c478bd9Sstevel@tonic-gate if (dotcount++ % DX == 0) 410*7c478bd9Sstevel@tonic-gate putdot((int)xc, (int)yc); 411*7c478bd9Sstevel@tonic-gate if (Yc < 0.5) { 412*7c478bd9Sstevel@tonic-gate /* reinitialize */ 413*7c478bd9Sstevel@tonic-gate Xs = Xc = 0; 414*7c478bd9Sstevel@tonic-gate Ys = Yc = sqrt((float)(sqr(xs) + sqr(ys))); 415*7c478bd9Sstevel@tonic-gate delta = sqr(Xs + 1) + sqr(Ys - 1) - sqr(xs) - sqr(ys); 416*7c478bd9Sstevel@tonic-gate Q--; 417*7c478bd9Sstevel@tonic-gate M1x = M3x; 418*7c478bd9Sstevel@tonic-gate M1y = M3y; 419*7c478bd9Sstevel@tonic-gate { 420*7c478bd9Sstevel@tonic-gate int T; 421*7c478bd9Sstevel@tonic-gate T = M2y; 422*7c478bd9Sstevel@tonic-gate M2y = M2x; 423*7c478bd9Sstevel@tonic-gate M2x = -T; 424*7c478bd9Sstevel@tonic-gate T = M3y; 425*7c478bd9Sstevel@tonic-gate M3y = M3x; 426*7c478bd9Sstevel@tonic-gate M3x = -T; 427*7c478bd9Sstevel@tonic-gate } 428*7c478bd9Sstevel@tonic-gate } else { 429*7c478bd9Sstevel@tonic-gate if (delta <= 0) 430*7c478bd9Sstevel@tonic-gate if (2 * delta + 2 * Yc - 1 <= 0) 431*7c478bd9Sstevel@tonic-gate move = 1; 432*7c478bd9Sstevel@tonic-gate else 433*7c478bd9Sstevel@tonic-gate move = 2; 434*7c478bd9Sstevel@tonic-gate else if (2 * delta - 2 * Xc - 1 <= 0) 435*7c478bd9Sstevel@tonic-gate move = 2; 436*7c478bd9Sstevel@tonic-gate else 437*7c478bd9Sstevel@tonic-gate move = 3; 438*7c478bd9Sstevel@tonic-gate switch (move) { 439*7c478bd9Sstevel@tonic-gate case 1: 440*7c478bd9Sstevel@tonic-gate Xc++; 441*7c478bd9Sstevel@tonic-gate delta += 2 * Xc + 1; 442*7c478bd9Sstevel@tonic-gate xc += M1x * xstep; 443*7c478bd9Sstevel@tonic-gate yc += M1y * ystep; 444*7c478bd9Sstevel@tonic-gate break; 445*7c478bd9Sstevel@tonic-gate case 2: 446*7c478bd9Sstevel@tonic-gate Xc++; 447*7c478bd9Sstevel@tonic-gate Yc--; 448*7c478bd9Sstevel@tonic-gate delta += 2 * Xc - 2 * Yc + 2; 449*7c478bd9Sstevel@tonic-gate xc += M2x * xstep; 450*7c478bd9Sstevel@tonic-gate yc += M2y * ystep; 451*7c478bd9Sstevel@tonic-gate break; 452*7c478bd9Sstevel@tonic-gate case 3: 453*7c478bd9Sstevel@tonic-gate Yc--; 454*7c478bd9Sstevel@tonic-gate delta -= 2 * Yc + 1; 455*7c478bd9Sstevel@tonic-gate xc += M3x * xstep; 456*7c478bd9Sstevel@tonic-gate yc += M3y * ystep; 457*7c478bd9Sstevel@tonic-gate break; 458*7c478bd9Sstevel@tonic-gate } 459*7c478bd9Sstevel@tonic-gate } 460*7c478bd9Sstevel@tonic-gate } 461*7c478bd9Sstevel@tonic-gate 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate setsize(osize); 464*7c478bd9Sstevel@tonic-gate drawline((int)xc-ox1,(int)yc-oy1,"."); 465*7c478bd9Sstevel@tonic-gate } 466*7c478bd9Sstevel@tonic-gate 467*7c478bd9Sstevel@tonic-gate putdot(x, y) 468*7c478bd9Sstevel@tonic-gate { 469*7c478bd9Sstevel@tonic-gate arcmove(x, y); 470*7c478bd9Sstevel@tonic-gate put1(drawdot); 471*7c478bd9Sstevel@tonic-gate } 472