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