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.2 */
32
33 #include <stdlib.h>
34 #include <math.h>
35 #include <plot.h>
36 #include "con.h"
37
38 static void
iline(int cx0,int cy0,int cx1,int cy1)39 iline(int cx0, int cy0, int cx1, int cy1)
40 {
41 int maxp, tt, j;
42 char chx, chy;
43 float xd, yd;
44 movep(cx0, cy0);
45 maxp = (int)(sqrt(dist2(cx0, cy0, cx1, cy1)) / 2.);
46 xd = cx1 - cx0;
47 yd = cy1 - cy0;
48 if (xd >= 0)
49 chx = RIGHT;
50 else chx = LEFT;
51 if (yd >= 0)
52 chy = UP;
53 else chy = DOWN;
54 if (maxp == 0) {
55 xd = 0;
56 yd = 0;
57 } else {
58 xd /= maxp;
59 yd /= maxp;
60 }
61 inplot();
62 for (tt = 0; tt <= maxp; tt++) {
63 j = (int)(cx0 + xd * tt - xnow);
64 xnow += j;
65 j = abs(j);
66 while (j-- > 0)
67 spew(chx);
68 j = (int)(cy0 + yd * tt - ynow);
69 ynow += j;
70 j = abs(j);
71 while (j-- > 0)
72 spew(chy);
73 spew('.');
74 }
75 outplot();
76 }
77
78 void
line(short x0,short y0,short x1,short y1)79 line(short x0, short y0, short x1, short y1)
80 {
81 iline(xconv(xsc(x0)), yconv(ysc(y0)),
82 xconv(xsc(x1)), yconv(ysc(y1)));
83 }
84
85 void
cont(short x0,short y0)86 cont(short x0, short y0)
87 {
88 iline(xnow, ynow, xconv(xsc(x0)), yconv(ysc(y0)));
89 }
90