1 | |
---|
2 | /*** OUTPUT.C ***/ |
---|
3 | |
---|
4 | |
---|
5 | #include <stdio.h> |
---|
6 | |
---|
7 | #include "vdefs.h" |
---|
8 | |
---|
9 | extern int triangulate, plot, debug ; |
---|
10 | extern float ymax, ymin, xmax, xmin ; |
---|
11 | |
---|
12 | float pxmin, pxmax, pymin, pymax, cradius; |
---|
13 | |
---|
14 | void |
---|
15 | openpl(void) |
---|
16 | { |
---|
17 | } |
---|
18 | |
---|
19 | #pragma argsused |
---|
20 | void |
---|
21 | line(float ax, float ay, float bx, float by) |
---|
22 | { |
---|
23 | } |
---|
24 | |
---|
25 | #pragma argsused |
---|
26 | void |
---|
27 | circle(float ax, float ay, float radius) |
---|
28 | { |
---|
29 | } |
---|
30 | |
---|
31 | #pragma argsused |
---|
32 | void |
---|
33 | range(float pxmin, float pxmax, float pymin, float pymax) |
---|
34 | { |
---|
35 | } |
---|
36 | |
---|
37 | void |
---|
38 | out_bisector(Edge * e) |
---|
39 | { |
---|
40 | if (triangulate && plot && !debug) |
---|
41 | { |
---|
42 | line(e->reg[0]->coord.x, e->reg[0]->coord.y, |
---|
43 | e->reg[1]->coord.x, e->reg[1]->coord.y) ; |
---|
44 | } |
---|
45 | if (!triangulate && !plot && !debug) |
---|
46 | { |
---|
47 | printf("l %f %f %f\n", e->a, e->b, e->c) ; |
---|
48 | } |
---|
49 | if (debug) |
---|
50 | { |
---|
51 | printf("line(%d) %gx+%gy=%g, bisecting %d %d\n", e->edgenbr, |
---|
52 | e->a, e->b, e->c, e->reg[le]->sitenbr, e->reg[re]->sitenbr) ; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | out_ep(Edge * e) |
---|
58 | { |
---|
59 | if (!triangulate && plot) |
---|
60 | { |
---|
61 | clip_line(e) ; |
---|
62 | } |
---|
63 | if (!triangulate && !plot) |
---|
64 | { |
---|
65 | printf("e %d", e->edgenbr); |
---|
66 | printf(" %d ", e->ep[le] != (Site *)NULL ? e->ep[le]->sitenbr : -1) ; |
---|
67 | printf("%d\n", e->ep[re] != (Site *)NULL ? e->ep[re]->sitenbr : -1) ; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | void |
---|
72 | out_vertex(Site * v) |
---|
73 | { |
---|
74 | if (!triangulate && !plot && !debug) |
---|
75 | { |
---|
76 | printf ("v %f %f\n", v->coord.x, v->coord.y) ; |
---|
77 | } |
---|
78 | if (debug) |
---|
79 | { |
---|
80 | printf("vertex(%d) at %f %f\n", v->sitenbr, v->coord.x, v->coord.y) ; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | void |
---|
85 | out_site(Site * s) |
---|
86 | { |
---|
87 | if (!triangulate && plot && !debug) |
---|
88 | { |
---|
89 | circle (s->coord.x, s->coord.y, cradius) ; |
---|
90 | } |
---|
91 | if (!triangulate && !plot && !debug) |
---|
92 | { |
---|
93 | printf("s %f %f\n", s->coord.x, s->coord.y) ; |
---|
94 | } |
---|
95 | if (debug) |
---|
96 | { |
---|
97 | printf("site (%d) at %f %f\n", s->sitenbr, s->coord.x, s->coord.y) ; |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | void |
---|
102 | out_triple(Site * s1, Site * s2, Site * s3) |
---|
103 | { |
---|
104 | if (triangulate && !plot && !debug) |
---|
105 | { |
---|
106 | printf("%d %d %d\n", s1->sitenbr, s2->sitenbr, s3->sitenbr) ; |
---|
107 | } |
---|
108 | if (debug) |
---|
109 | { |
---|
110 | printf("circle through left=%d right=%d bottom=%d\n", |
---|
111 | s1->sitenbr, s2->sitenbr, s3->sitenbr) ; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | plotinit(void) |
---|
117 | { |
---|
118 | float dx, dy, d ; |
---|
119 | |
---|
120 | dy = ymax - ymin ; |
---|
121 | dx = xmax - xmin ; |
---|
122 | d = ( dx > dy ? dx : dy) * 1.1 ; |
---|
123 | pxmin = xmin - (d-dx) / 2.0 ; |
---|
124 | pxmax = xmax + (d-dx) / 2.0 ; |
---|
125 | pymin = ymin - (d-dy) / 2.0 ; |
---|
126 | pymax = ymax + (d-dy) / 2.0 ; |
---|
127 | cradius = (pxmax - pxmin) / 350.0 ; |
---|
128 | openpl() ; |
---|
129 | range(pxmin, pymin, pxmax, pymax) ; |
---|
130 | } |
---|
131 | |
---|
132 | void |
---|
133 | clip_line(Edge * e) |
---|
134 | { |
---|
135 | Site * s1, * s2 ; |
---|
136 | float x1, x2, y1, y2 ; |
---|
137 | |
---|
138 | if (e->a == 1.0 && e->b >= 0.0) |
---|
139 | { |
---|
140 | s1 = e->ep[1] ; |
---|
141 | s2 = e->ep[0] ; |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | s1 = e->ep[0] ; |
---|
146 | s2 = e->ep[1] ; |
---|
147 | } |
---|
148 | if (e->a == 1.0) |
---|
149 | { |
---|
150 | y1 = pymin ; |
---|
151 | if (s1 != (Site *)NULL && s1->coord.y > pymin) |
---|
152 | { |
---|
153 | y1 = s1->coord.y ; |
---|
154 | } |
---|
155 | if (y1 > pymax) |
---|
156 | { |
---|
157 | return ; |
---|
158 | } |
---|
159 | x1 = e->c - e->b * y1 ; |
---|
160 | y2 = pymax ; |
---|
161 | if (s2 != (Site *)NULL && s2->coord.y < pymax) |
---|
162 | { |
---|
163 | y2 = s2->coord.y ; |
---|
164 | } |
---|
165 | if (y2 < pymin) |
---|
166 | { |
---|
167 | return ; |
---|
168 | } |
---|
169 | x2 = e->c - e->b * y2 ; |
---|
170 | if (((x1 > pxmax) && (x2 > pxmax)) || ((x1 < pxmin) && (x2 < pxmin))) |
---|
171 | { |
---|
172 | return ; |
---|
173 | } |
---|
174 | if (x1 > pxmax) |
---|
175 | { |
---|
176 | x1 = pxmax ; |
---|
177 | y1 = (e->c - x1) / e->b ; |
---|
178 | } |
---|
179 | if (x1 < pxmin) |
---|
180 | { |
---|
181 | x1 = pxmin ; |
---|
182 | y1 = (e->c - x1) / e->b ; |
---|
183 | } |
---|
184 | if (x2 > pxmax) |
---|
185 | { |
---|
186 | x2 = pxmax ; |
---|
187 | y2 = (e->c - x2) / e->b ; |
---|
188 | } |
---|
189 | if (x2 < pxmin) |
---|
190 | { |
---|
191 | x2 = pxmin ; |
---|
192 | y2 = (e->c - x2) / e->b ; |
---|
193 | } |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | x1 = pxmin ; |
---|
198 | if (s1 != (Site *)NULL && s1->coord.x > pxmin) |
---|
199 | { |
---|
200 | x1 = s1->coord.x ; |
---|
201 | } |
---|
202 | if (x1 > pxmax) |
---|
203 | { |
---|
204 | return ; |
---|
205 | } |
---|
206 | y1 = e->c - e->a * x1 ; |
---|
207 | x2 = pxmax ; |
---|
208 | if (s2 != (Site *)NULL && s2->coord.x < pxmax) |
---|
209 | { |
---|
210 | x2 = s2->coord.x ; |
---|
211 | } |
---|
212 | if (x2 < pxmin) |
---|
213 | { |
---|
214 | return ; |
---|
215 | } |
---|
216 | y2 = e->c - e->a * x2 ; |
---|
217 | if (((y1 > pymax) && (y2 > pymax)) || ((y1 < pymin) && (y2 <pymin))) |
---|
218 | { |
---|
219 | return ; |
---|
220 | } |
---|
221 | if (y1> pymax) |
---|
222 | { |
---|
223 | y1 = pymax ; |
---|
224 | x1 = (e->c - y1) / e->a ; |
---|
225 | } |
---|
226 | if (y1 < pymin) |
---|
227 | { |
---|
228 | y1 = pymin ; |
---|
229 | x1 = (e->c - y1) / e->a ; |
---|
230 | } |
---|
231 | if (y2 > pymax) |
---|
232 | { |
---|
233 | y2 = pymax ; |
---|
234 | x2 = (e->c - y2) / e->a ; |
---|
235 | } |
---|
236 | if (y2 < pymin) |
---|
237 | { |
---|
238 | y2 = pymin ; |
---|
239 | x2 = (e->c - y2) / e->a ; |
---|
240 | } |
---|
241 | } |
---|
242 | line(x1,y1,x2,y2); |
---|
243 | } |
---|
244 | |
---|