1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*0Sstevel@tonic-gate /* All Rights Reserved */ 24*0Sstevel@tonic-gate 25*0Sstevel@tonic-gate 26*0Sstevel@tonic-gate /* 27*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 28*0Sstevel@tonic-gate * Use is subject to license terms. 29*0Sstevel@tonic-gate */ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */ 32*0Sstevel@tonic-gate /*LINTLIBRARY*/ 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gate #include <stdlib.h> 35*0Sstevel@tonic-gate #include <math.h> 36*0Sstevel@tonic-gate #include <plot.h> 37*0Sstevel@tonic-gate #include "con.h" 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate static int del = 20; 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate static void 42*0Sstevel@tonic-gate step(int d) 43*0Sstevel@tonic-gate { 44*0Sstevel@tonic-gate del = d; 45*0Sstevel@tonic-gate } 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate /* 48*0Sstevel@tonic-gate * local definition of quad 49*0Sstevel@tonic-gate * legacy code 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate static short 52*0Sstevel@tonic-gate quad_l(short x, short y, short xp, short yp) 53*0Sstevel@tonic-gate { 54*0Sstevel@tonic-gate if (x < xp) 55*0Sstevel@tonic-gate if (y <= yp) 56*0Sstevel@tonic-gate return (1); 57*0Sstevel@tonic-gate else return (4); 58*0Sstevel@tonic-gate else if (x > xp) 59*0Sstevel@tonic-gate if (y < yp) 60*0Sstevel@tonic-gate return (2); 61*0Sstevel@tonic-gate else return (3); 62*0Sstevel@tonic-gate else if (y < yp) 63*0Sstevel@tonic-gate return (2); 64*0Sstevel@tonic-gate else return (4); 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate void 68*0Sstevel@tonic-gate arc(short x, short y, short x0, short y0, short x1, short y1) 69*0Sstevel@tonic-gate { 70*0Sstevel@tonic-gate double pc; 71*0Sstevel@tonic-gate int flg, m, xc, yc, xs, ys, qs, qf, qt, qtctr = 0; 72*0Sstevel@tonic-gate int m0, m1; 73*0Sstevel@tonic-gate float dx, dy, r; 74*0Sstevel@tonic-gate char use; 75*0Sstevel@tonic-gate dx = x - x0; 76*0Sstevel@tonic-gate dy = y - y0; 77*0Sstevel@tonic-gate r = dx * dx + dy * dy; 78*0Sstevel@tonic-gate pc = r; 79*0Sstevel@tonic-gate pc = sqrt(pc); 80*0Sstevel@tonic-gate flg = (int)(pc / 4); 81*0Sstevel@tonic-gate if (flg == 0) 82*0Sstevel@tonic-gate step(1); 83*0Sstevel@tonic-gate else if (flg < del) 84*0Sstevel@tonic-gate step(flg); 85*0Sstevel@tonic-gate xc = xs = x0; 86*0Sstevel@tonic-gate yc = ys = y0; 87*0Sstevel@tonic-gate move((short)xs, (short)ys); 88*0Sstevel@tonic-gate if ((x0 == x1) && (y0 == y1)) 89*0Sstevel@tonic-gate flg = 0; 90*0Sstevel@tonic-gate else flg = 1; 91*0Sstevel@tonic-gate qs = quad_l(x, y, x0, y0); 92*0Sstevel@tonic-gate qf = quad_l(x, y, x1, y1); 93*0Sstevel@tonic-gate if (abs(x - x1) < abs(y - y1)) { 94*0Sstevel@tonic-gate use = 'x'; 95*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 96*0Sstevel@tonic-gate m = -1; 97*0Sstevel@tonic-gate else m = 1; 98*0Sstevel@tonic-gate } else { 99*0Sstevel@tonic-gate use = 'y'; 100*0Sstevel@tonic-gate if (qs > 2) 101*0Sstevel@tonic-gate m = -1; 102*0Sstevel@tonic-gate else m = 1; 103*0Sstevel@tonic-gate } 104*0Sstevel@tonic-gate if (qs == qf) { 105*0Sstevel@tonic-gate m0 = (y0 - y) / (x0 - x); 106*0Sstevel@tonic-gate m1 = (y1 - y) / (x1 - x); 107*0Sstevel@tonic-gate if (m0 >= m1) 108*0Sstevel@tonic-gate qt = 4; 109*0Sstevel@tonic-gate else qt = 0; 110*0Sstevel@tonic-gate } else if ((qt = qf - qs) < 0) 111*0Sstevel@tonic-gate qt += 4; 112*0Sstevel@tonic-gate /* LINTED */ 113*0Sstevel@tonic-gate while (1) { 114*0Sstevel@tonic-gate switch (use) { 115*0Sstevel@tonic-gate case 'x': 116*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 117*0Sstevel@tonic-gate yc -= del; 118*0Sstevel@tonic-gate else yc += del; 119*0Sstevel@tonic-gate dy = yc - y; 120*0Sstevel@tonic-gate pc = r - dy * dy; 121*0Sstevel@tonic-gate xc = (int)(m * sqrt(pc) + x); 122*0Sstevel@tonic-gate if (((x < xs) && (x >= xc)) || 123*0Sstevel@tonic-gate ((x > xs) && (x <= xc)) || 124*0Sstevel@tonic-gate ((y < ys) && (y >= yc)) || 125*0Sstevel@tonic-gate ((y > ys) && (y <= yc))) { 126*0Sstevel@tonic-gate if (++qtctr > qt) 127*0Sstevel@tonic-gate return; 128*0Sstevel@tonic-gate if (++qs > 4) 129*0Sstevel@tonic-gate qs = 1; 130*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 131*0Sstevel@tonic-gate m = -1; 132*0Sstevel@tonic-gate else m = 1; 133*0Sstevel@tonic-gate flg = 1; 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate cont((short)xc, (short)yc); 136*0Sstevel@tonic-gate xs = xc; 137*0Sstevel@tonic-gate ys = yc; 138*0Sstevel@tonic-gate if ((qs == qf) && (flg == 1)) 139*0Sstevel@tonic-gate switch (qf) { 140*0Sstevel@tonic-gate case 3: 141*0Sstevel@tonic-gate case 4: 142*0Sstevel@tonic-gate if (xs >= x1) 143*0Sstevel@tonic-gate return; 144*0Sstevel@tonic-gate continue; 145*0Sstevel@tonic-gate case 1: 146*0Sstevel@tonic-gate case 2: 147*0Sstevel@tonic-gate if (xs <= x1) 148*0Sstevel@tonic-gate return; 149*0Sstevel@tonic-gate } 150*0Sstevel@tonic-gate continue; 151*0Sstevel@tonic-gate case 'y': 152*0Sstevel@tonic-gate if (qs > 2) 153*0Sstevel@tonic-gate xc += del; 154*0Sstevel@tonic-gate else xc -= del; 155*0Sstevel@tonic-gate dx = xc - x; 156*0Sstevel@tonic-gate pc = r - dx * dx; 157*0Sstevel@tonic-gate yc = (int)(m * sqrt(pc) + y); 158*0Sstevel@tonic-gate if (((x < xs) && (x >= xc)) || 159*0Sstevel@tonic-gate ((x > xs) && (x <= xc)) || 160*0Sstevel@tonic-gate ((y < ys) && (y >= yc)) || 161*0Sstevel@tonic-gate ((y > ys) && (y <= yc))) { 162*0Sstevel@tonic-gate if (++qtctr > qt) 163*0Sstevel@tonic-gate return; 164*0Sstevel@tonic-gate if (++qs > 4) 165*0Sstevel@tonic-gate qs = 1; 166*0Sstevel@tonic-gate if (qs > 2) 167*0Sstevel@tonic-gate m = -1; 168*0Sstevel@tonic-gate else m = 1; 169*0Sstevel@tonic-gate flg = 1; 170*0Sstevel@tonic-gate } 171*0Sstevel@tonic-gate cont((short)xc, (short)yc); 172*0Sstevel@tonic-gate xs = xc; 173*0Sstevel@tonic-gate ys = yc; 174*0Sstevel@tonic-gate if ((qs == qf) && (flg == 1)) 175*0Sstevel@tonic-gate switch (qs) { 176*0Sstevel@tonic-gate case 1: 177*0Sstevel@tonic-gate case 4: 178*0Sstevel@tonic-gate if (ys >= y1) 179*0Sstevel@tonic-gate return; 180*0Sstevel@tonic-gate continue; 181*0Sstevel@tonic-gate case 2: 182*0Sstevel@tonic-gate case 3: 183*0Sstevel@tonic-gate if (ys <= y1) 184*0Sstevel@tonic-gate return; 185*0Sstevel@tonic-gate } 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate } 189