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