Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
info.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <neatogen/neato.h>
12#include <stdio.h>
13#include <neatogen/mem.h>
14#include <neatogen/info.h>
15
16
17Info_t *nodeInfo; /* Array of node info */
19
20void infoinit(void)
21{
22 freeinit(&pfl, sizeof(PtItem));
23}
24
25/* compare:
26 * returns -1 if p < q
27 * 0 if p = q
28 * 1 if p > q
29 * if q if NULL, returns -1
30 * Ordering is by angle from -pi/2 to 3pi/4.
31 * For equal angles (which should not happen in our context)
32 * ordering is by closeness to origin.
33 */
34static int compare(Point * o, PtItem * p, PtItem * q)
35{
36 double x0;
37 double y0;
38 double x1;
39 double y1;
40 double a, b;
41
42 if (q == NULL)
43 return -1;
44 if (p->p.x == q->p.x && p->p.y == q->p.y)
45 return 0;
46
47 x0 = (double)p->p.x - (double)o->x;
48 y0 = (double)p->p.y - (double)o->y;
49 x1 = (double)q->p.x - (double)o->x;
50 y1 = (double)q->p.y - (double)o->y;
51 if (x0 >= 0.0) {
52 if (x1 < 0.0)
53 return -1;
54 else if (x0 > 0.0) {
55 if (x1 > 0.0) {
56 a = y1 / x1;
57 b = y0 / x0;
58 if (b < a)
59 return -1;
60 else if (b > a)
61 return 1;
62 else if (x0 < x1)
63 return -1;
64 else
65 return 1;
66 } else { /* x1 == 0.0 */
67 if (y1 > 0.0)
68 return -1;
69 else
70 return 1;
71 }
72 } else { /* x0 == 0.0 */
73 if (x1 > 0.0) {
74 if (y0 <= 0.0)
75 return -1;
76 else
77 return 1;
78 } else { /* x1 == 0.0 */
79 if (y0 < y1) {
80 if (y1 <= 0.0)
81 return 1;
82 else
83 return -1;
84 } else {
85 if (y0 <= 0.0)
86 return -1;
87 else
88 return 1;
89 }
90 }
91 }
92 } else {
93 if (x1 >= 0.0)
94 return 1;
95 else {
96 a = y1 / x1;
97 b = y0 / x0;
98 if (b < a)
99 return -1;
100 else if (b > a)
101 return 1;
102 else if (x0 > x1)
103 return -1;
104 else
105 return 1;
106 }
107 }
108}
109
110void addVertex(Site * s, double x, double y)
111{
112 Info_t *ip;
113 PtItem *p;
114 PtItem *curr;
115 PtItem *prev;
116 Point *origin_point = &s->coord;
117 PtItem tmp;
118 int cmp;
119
120 ip = nodeInfo + s->sitenbr;
121 curr = ip->verts;
122
123 tmp.p.x = x;
124 tmp.p.y = y;
125
126 cmp = compare(origin_point, &tmp, curr);
127 if (cmp == 0)
128 return;
129 else if (cmp < 0) {
130 p = getfree(&pfl);
131 p->p.x = x;
132 p->p.y = y;
133 p->next = curr;
134 ip->verts = p;
135 return;
136 }
137
138 prev = curr;
139 curr = curr->next;
140 while ((cmp = compare(origin_point, &tmp, curr)) > 0) {
141 prev = curr;
142 curr = curr->next;
143 }
144 if (cmp == 0)
145 return;
146 p = getfree(&pfl);
147 p->p.x = x;
148 p->p.y = y;
149 prev->next = p;
150 p->next = curr;
151}
static int cmp(const void *x, const void *y)
Definition ccomps.c:458
node NULL
Definition grammar.y:149
$2 u p prev
Definition htmlparse.y:495
Info_t * nodeInfo
Definition info.c:17
void addVertex(Site *s, double x, double y)
Definition info.c:110
static Freelist pfl
Definition info.c:18
static int compare(Point *o, PtItem *p, PtItem *q)
Definition info.c:34
void infoinit(void)
Definition info.c:20
void * getfree(Freelist *)
Definition memory.c:60
void freeinit(Freelist *, int)
Definition memory.c:41
Definition info.h:25
PtItem * verts
Definition info.h:30
double x
Definition geometry.h:23
double y
Definition geometry.h:23
Definition site.h:22
Definition mem.h:21
Definition info.h:20
struct ptitem * next
Definition info.h:21
Point p
Definition info.h:22
Definition grammar.c:93