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 /* 42*0Sstevel@tonic-gate * local definitions for quad 43*0Sstevel@tonic-gate * legacy code 44*0Sstevel@tonic-gate */ 45*0Sstevel@tonic-gate static short 46*0Sstevel@tonic-gate quad_l(short x, short y, short xp, short yp) 47*0Sstevel@tonic-gate { 48*0Sstevel@tonic-gate if (x < xp) 49*0Sstevel@tonic-gate if (y <= yp) 50*0Sstevel@tonic-gate return (1); 51*0Sstevel@tonic-gate else return (4); 52*0Sstevel@tonic-gate else if (x > xp) 53*0Sstevel@tonic-gate if (y < yp) 54*0Sstevel@tonic-gate return (2); 55*0Sstevel@tonic-gate else return (3); 56*0Sstevel@tonic-gate else if (y < yp) 57*0Sstevel@tonic-gate return (2); 58*0Sstevel@tonic-gate else return (4); 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate static void 62*0Sstevel@tonic-gate step(int d) 63*0Sstevel@tonic-gate { 64*0Sstevel@tonic-gate del = d; 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 double sqrt(double); 72*0Sstevel@tonic-gate int flg, m, qs, qf, qt, qtctr = 0; 73*0Sstevel@tonic-gate int m0, m1; 74*0Sstevel@tonic-gate short xs, ys, xc, yc; 75*0Sstevel@tonic-gate float dx, dy, r; 76*0Sstevel@tonic-gate char use; 77*0Sstevel@tonic-gate dx = x - x0; 78*0Sstevel@tonic-gate dy = y - y0; 79*0Sstevel@tonic-gate r = dx * dx + dy * dy; 80*0Sstevel@tonic-gate pc = r; 81*0Sstevel@tonic-gate pc = sqrt(pc); 82*0Sstevel@tonic-gate flg = (int)(pc / 4); 83*0Sstevel@tonic-gate if (flg == 0) 84*0Sstevel@tonic-gate step(1); 85*0Sstevel@tonic-gate else if (flg < del) 86*0Sstevel@tonic-gate step(flg); 87*0Sstevel@tonic-gate xc = xs = x0; 88*0Sstevel@tonic-gate yc = ys = y0; 89*0Sstevel@tonic-gate move(xs, ys); 90*0Sstevel@tonic-gate if ((x0 == x1) && (y0 == y1)) 91*0Sstevel@tonic-gate flg = 0; 92*0Sstevel@tonic-gate else flg = 1; 93*0Sstevel@tonic-gate qs = quad_l(x, y, x0, y0); 94*0Sstevel@tonic-gate qf = quad_l(x, y, x1, y1); 95*0Sstevel@tonic-gate if (abs(x - x1) < abs(y - y1)) { 96*0Sstevel@tonic-gate use = 'x'; 97*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 98*0Sstevel@tonic-gate m = -1; 99*0Sstevel@tonic-gate else m = 1; 100*0Sstevel@tonic-gate } else { 101*0Sstevel@tonic-gate use = 'y'; 102*0Sstevel@tonic-gate if (qs > 2) 103*0Sstevel@tonic-gate m = -1; 104*0Sstevel@tonic-gate else m = 1; 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate if (qs == qf) { 107*0Sstevel@tonic-gate m0 = (y0 - y) / (x0 - x); 108*0Sstevel@tonic-gate m1 = (y1 - y) / (x1 - x); 109*0Sstevel@tonic-gate if (m0 >= m1) 110*0Sstevel@tonic-gate qt = 4; 111*0Sstevel@tonic-gate else qt = 0; 112*0Sstevel@tonic-gate } else if ((qt = qf - qs) < 0) 113*0Sstevel@tonic-gate qt += 4; 114*0Sstevel@tonic-gate /* LINTED */ 115*0Sstevel@tonic-gate while (1) { 116*0Sstevel@tonic-gate switch (use) { 117*0Sstevel@tonic-gate case 'x': 118*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 119*0Sstevel@tonic-gate yc -= del; 120*0Sstevel@tonic-gate else yc += del; 121*0Sstevel@tonic-gate dy = yc - y; 122*0Sstevel@tonic-gate pc = r - dy * dy; 123*0Sstevel@tonic-gate xc = (int)(m * sqrt(pc) + x); 124*0Sstevel@tonic-gate if (((x < xs) && (x >= xc)) || 125*0Sstevel@tonic-gate ((x > xs) && (x <= xc)) || 126*0Sstevel@tonic-gate ((y < ys) && (y >= yc)) || 127*0Sstevel@tonic-gate ((y > ys) && (y <= yc))) { 128*0Sstevel@tonic-gate if (++qtctr > qt) 129*0Sstevel@tonic-gate return; 130*0Sstevel@tonic-gate if (++qs > 4) 131*0Sstevel@tonic-gate qs = 1; 132*0Sstevel@tonic-gate if ((qs == 2) || (qs == 3)) 133*0Sstevel@tonic-gate m = -1; 134*0Sstevel@tonic-gate else m = 1; 135*0Sstevel@tonic-gate flg = 1; 136*0Sstevel@tonic-gate } 137*0Sstevel@tonic-gate cont(xc, yc); 138*0Sstevel@tonic-gate xs = xc; 139*0Sstevel@tonic-gate ys = yc; 140*0Sstevel@tonic-gate if ((qs == qf) && (flg == 1)) 141*0Sstevel@tonic-gate switch (qf) { 142*0Sstevel@tonic-gate case 3: 143*0Sstevel@tonic-gate case 4: 144*0Sstevel@tonic-gate if (xs >= x1) 145*0Sstevel@tonic-gate return; 146*0Sstevel@tonic-gate continue; 147*0Sstevel@tonic-gate case 1: 148*0Sstevel@tonic-gate case 2: 149*0Sstevel@tonic-gate if (xs <= x1) 150*0Sstevel@tonic-gate return; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate continue; 153*0Sstevel@tonic-gate case 'y': 154*0Sstevel@tonic-gate if (qs > 2) 155*0Sstevel@tonic-gate xc += del; 156*0Sstevel@tonic-gate else xc -= del; 157*0Sstevel@tonic-gate dx = xc - x; 158*0Sstevel@tonic-gate pc = r - dx * dx; 159*0Sstevel@tonic-gate yc = (int)(m * sqrt(pc) + y); 160*0Sstevel@tonic-gate if (((x < xs) && (x >= xc)) || 161*0Sstevel@tonic-gate ((x > xs) && (x <= xc)) || 162*0Sstevel@tonic-gate ((y < ys) && (y >= yc)) || 163*0Sstevel@tonic-gate ((y > ys) && (y <= yc))) { 164*0Sstevel@tonic-gate if (++qtctr > qt) 165*0Sstevel@tonic-gate return; 166*0Sstevel@tonic-gate if (++qs > 4) 167*0Sstevel@tonic-gate qs = 1; 168*0Sstevel@tonic-gate if (qs > 2) 169*0Sstevel@tonic-gate m = -1; 170*0Sstevel@tonic-gate else m = 1; 171*0Sstevel@tonic-gate flg = 1; 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate cont(xc, yc); 174*0Sstevel@tonic-gate xs = xc; 175*0Sstevel@tonic-gate ys = yc; 176*0Sstevel@tonic-gate if ((qs == qf) && (flg == 1)) 177*0Sstevel@tonic-gate switch (qs) { 178*0Sstevel@tonic-gate case 1: 179*0Sstevel@tonic-gate case 4: 180*0Sstevel@tonic-gate if (ys >= y1) 181*0Sstevel@tonic-gate return; 182*0Sstevel@tonic-gate continue; 183*0Sstevel@tonic-gate case 2: 184*0Sstevel@tonic-gate case 3: 185*0Sstevel@tonic-gate if (ys <= y1) 186*0Sstevel@tonic-gate return; 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate } 189*0Sstevel@tonic-gate } 190*0Sstevel@tonic-gate } 191