File: info.c

package info (click to toggle)
graphviz 2.8-3%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 20,480 kB
  • ctags: 22,071
  • sloc: ansic: 163,260; cpp: 36,565; sh: 25,024; yacc: 2,358; tcl: 1,808; makefile: 1,745; cs: 805; perl: 801; ml: 649; awk: 160; lex: 153; python: 105; ruby: 32; php: 6
file content (210 lines) | stat: -rw-r--r-- 4,306 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* $Id: info.c,v 1.1.1.1 2004/12/23 04:05:12 ellson Exp $ $Revision: 1.1.1.1 $ */
/* vim:set shiftwidth=4 ts=8: */

/**********************************************************
*      This software is part of the graphviz package      *
*                http://www.graphviz.org/                 *
*                                                         *
*            Copyright (c) 1994-2004 AT&T Corp.           *
*                and is licensed under the                *
*            Common Public License, Version 1.0           *
*                      by AT&T Corp.                      *
*                                                         *
*        Information and Software Systems Research        *
*              AT&T Research, Florham Park NJ             *
**********************************************************/

#include "neato.h"
#include <stdio.h>
#include "mem.h"
#include "info.h"


Info_t *nodeInfo;		/* Array of node info */
static Freelist pfl;

void infoinit()
{
    freeinit(&pfl, sizeof(PtItem));
}

/* compare:
 * returns -1 if p < q
 *          0 if p = q
 *          1 if p > q
 * if q if NULL, returns -1
 * Ordering is by angle from -pi/2 to 3pi/4.
 * For equal angles (which should not happen in our context)
 * ordering is by closeness to origin.
 */
static int compare(Point * o, PtItem * p, PtItem * q)
{
    double x0;
    double y0;
    double x1;
    double y1;
    double a, b;

    if (q == NULL)
	return -1;
    if ((p->p.x == q->p.x) && (p->p.y == q->p.y))
	return 0;

    x0 = ((double) (p->p.x)) - ((double) (o->x));
    y0 = ((double) (p->p.y)) - ((double) (o->y));
    x1 = ((double) (q->p.x)) - ((double) (o->x));
    y1 = ((double) (q->p.y)) - ((double) (o->y));
    if (x0 >= 0.0) {
	if (x1 < 0.0)
	    return -1;
	else if (x0 > 0.0) {
	    if (x1 > 0.0) {
		a = y1 / x1;
		b = y0 / x0;
		if (b < a)
		    return -1;
		else if (b > a)
		    return 1;
		else if (x0 < x1)
		    return -1;
		else
		    return 1;
	    } else {		/* x1 == 0.0 */
		if (y1 > 0.0)
		    return -1;
		else
		    return 1;
	    }
	} else {		/* x0 == 0.0 */
	    if (x1 > 0.0) {
		if (y0 <= 0.0)
		    return -1;
		else
		    return 1;
	    } else {		/* x1 == 0.0 */
		if (y0 < y1) {
		    if (y1 <= 0.0)
			return 1;
		    else
			return -1;
		} else {
		    if (y0 <= 0.0)
			return -1;
		    else
			return 1;
		}
	    }
	}
    } else {
	if (x1 >= 0.0)
	    return 1;
	else {
	    a = y1 / x1;
	    b = y0 / x0;
	    if (b < a)
		return -1;
	    else if (b > a)
		return 1;
	    else if (x0 > x1)
		return -1;
	    else
		return 1;
	}
    }
}

#if 0				/* not used */
static void printV(PtItem * vp)
{
    if (vp == NULL) {
	fprintf(stderr, "<empty>\n");
	return;
    }

    while (vp != NULL) {
	fprintf(stderr, "(%.16f,%.16f)\n", vp->p.x, vp->p.y);
	vp = vp->next;
    }
}

static void error(Info_t * ip, Site * s, double x, double y)
{
    fprintf(stderr,
	    "Unsorted vertex list for site %d (%.16f,%.16f), pt (%f,%f)\n",
	    s->sitenbr, s->coord.x, s->coord.y, x, y);
    printV(ip->verts);
}
#endif

#if 0				/* not used */
static int sorted(Point * origin, PtItem * vp)
{
    PtItem *next;

    if (vp == NULL)
	return 1;
    next = vp->next;

    while (next != NULL) {
	if (compare(origin, vp, next) <= 0) {
	    vp = next;
	    next = next->next;
	} else {
	    fprintf(stderr, "(%.16f,%.16f) > (%.16f,%.16f)\n",
		    vp->p.x, vp->p.y, next->p.x, next->p.y);
	    return 0;
	}
    }

    return 1;

}
#endif

void addVertex(Site * s, double x, double y)
{
    Info_t *ip;
    PtItem *p;
    PtItem *curr;
    PtItem *prev;
    Point *origin = &(s->coord);
    PtItem tmp;
    int cmp;

    ip = nodeInfo + (s->sitenbr);
    curr = ip->verts;

    tmp.p.x = x;
    tmp.p.y = y;

    cmp = compare(origin, &tmp, curr);
    if (cmp == 0)
	return;
    else if (cmp < 0) {
	p = (PtItem *) getfree(&pfl);
	p->p.x = x;
	p->p.y = y;
	p->next = curr;
	ip->verts = p;
	return;
    }

    prev = curr;
    curr = curr->next;
    while ((cmp = compare(origin, &tmp, curr)) > 0) {
	prev = curr;
	curr = curr->next;
    }
    if (cmp == 0)
	return;
    p = (PtItem *) getfree(&pfl);
    p->p.x = x;
    p->p.y = y;
    prev->next = p;
    p->next = curr;

    /* This test should be unnecessary */
    /* if (!sorted(origin,ip->verts))  */
    /* error (ip,s,x,y); */

}