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