~ubuntu-branches/ubuntu/utopic/libmath-geometry-voronoi-perl/utopic-proposed

« back to all changes in this revision

Viewing changes to output.c

  • Committer: Package Import Robot
  • Author(s): Florian Schlichting
  • Date: 2013-05-23 21:40:53 UTC
  • Revision ID: package-import@ubuntu.com-20130523214053-1reukv29881hn1o4
Tags: upstream-1.3
ImportĀ upstreamĀ versionĀ 1.3

Show diffs side-by-side

added added

removed removed

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