2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A/*
2N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */
2N/A/*LINTLIBRARY*/
2N/A
2N/A#include <stdlib.h>
2N/A#include <plot.h>
2N/A#include <math.h>
2N/A#include "con.h"
2N/A
2N/Astatic int quad_l(short, short, short, short);
2N/Astatic int del = 20;
2N/A
2N/Astatic void
2N/Astep(int d)
2N/A{
2N/A del = d;
2N/A}
2N/A
2N/Avoid
2N/Aarc(short x, short y, short x0, short y0, short x1, short y1)
2N/A{
2N/A double pc;
2N/A short flg, m, xc, yc, xs, ys, qs, qf, qt, qtctr = 0;
2N/A short m0, m1;
2N/A float dx, dy, r;
2N/A char use;
2N/A dx = x - x0;
2N/A dy = y - y0;
2N/A r = (dx * dx) + (dy * dy);
2N/A pc = r;
2N/A pc = sqrt(pc);
2N/A flg = (short)(pc / 4);
2N/A if (flg == 0)
2N/A step(1);
2N/A else if (flg < del)
2N/A step(flg);
2N/A xc = xs = x0;
2N/A yc = ys = y0;
2N/A move(xs, ys);
2N/A if ((x0 == x1) && (y0 == y1))
2N/A flg = 0;
2N/A else flg = 1;
2N/A qs = quad_l(x, y, x0, y0);
2N/A qf = quad_l(x, y, x1, y1);
2N/A if ((abs(x - x1)) < (abs(y - y1))) {
2N/A use = 'x';
2N/A if ((qs == 2) || (qs == 3))
2N/A m = -1;
2N/A else m = 1;
2N/A } else {
2N/A use = 'y';
2N/A if (qs > 2)
2N/A m = -1;
2N/A else m = 1;
2N/A }
2N/A if (qs == qf) {
2N/A m0 = (y0 - y) / (x0 - x);
2N/A m1 = (y1 - y) / (x1 - x);
2N/A if (m0 >= m1)
2N/A qt = 4;
2N/A else qt = 0;
2N/A } else if ((qt = qf - qs) < 0)
2N/A qt += 4;
2N/A /* LINTED */
2N/A while (1) {
2N/A switch (use) {
2N/A case 'x':
2N/A if ((qs == 2) || (qs == 3))
2N/A yc -= del;
2N/A else yc += del;
2N/A dy = yc - y;
2N/A pc = r - dy * dy;
2N/A xc = (short)(m * sqrt(pc) + x);
2N/A if (((x < xs) && (x >= xc)) ||
2N/A ((x > xs) && (x <= xc)) ||
2N/A ((y < ys) && (y >= yc)) ||
2N/A ((y > ys) && (y <= yc))) {
2N/A if (++qtctr > qt)
2N/A return;
2N/A if (++qs > 4)
2N/A qs = 1;
2N/A if ((qs == 2) || (qs == 3))
2N/A m = -1;
2N/A else m = 1;
2N/A flg = 1;
2N/A }
2N/A cont(xc, yc);
2N/A xs = xc;
2N/A ys = yc;
2N/A if ((qs == qf) && (flg == 1))
2N/A switch (qf) {
2N/A case 3:
2N/A case 4:
2N/A if (xs >= x1)
2N/A return;
2N/A continue;
2N/A case 1:
2N/A case 2:
2N/A if (xs <= x1)
2N/A return;
2N/A }
2N/A continue;
2N/A case 'y':
2N/A if (qs > 2)
2N/A xc += del;
2N/A else xc -= del;
2N/A dx = xc - x;
2N/A pc = r - dx * dx;
2N/A yc = (short)(m * sqrt(pc) + y);
2N/A if (((x < xs) && (x >= xc)) ||
2N/A ((x > xs) && (x <= xc)) ||
2N/A ((y < ys) && (y >= yc)) ||
2N/A ((y > ys) && (y <= yc))) {
2N/A if (++qtctr > qt)
2N/A return;
2N/A if (++qs > 4)
2N/A qs = 1;
2N/A if (qs > 2)
2N/A m = -1;
2N/A else m = 1;
2N/A flg = 1;
2N/A }
2N/A cont(xc, yc);
2N/A xs = xc;
2N/A ys = yc;
2N/A if ((qs == qf) && (flg == 1))
2N/A switch (qs) {
2N/A case 1:
2N/A case 4:
2N/A if (ys >= y1)
2N/A return;
2N/A continue;
2N/A case 2:
2N/A case 3:
2N/A if (ys <= y1)
2N/A return;
2N/A }
2N/A }
2N/A }
2N/A}
2N/A
2N/A/*
2N/A * these is a local function not to be confused with the
2N/A * system wide quad
2N/A */
2N/Astatic int
2N/Aquad_l(short x, short y, short xp, short yp)
2N/A{
2N/A if (x < xp)
2N/A if (y <= yp)
2N/A return (1);
2N/A else return (4);
2N/A else if (x > xp)
2N/A if (y < yp)
2N/A return (2);
2N/A else return (3);
2N/A else if (y < yp)
2N/A return (2);
2N/A else return (4);
2N/A}