Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /*** MAIN.C ***/ |
2 | |||
3 | #include <stdio.h> |
||
4 | #include <stdlib.h> /* realloc(), qsort() */ |
||
5 | |||
6 | #include <strings.h> |
||
7 | |||
8 | #include "vdefs.h" |
||
9 | |||
10 | Site * nextone(void) ; |
||
11 | void readsites(void) ; |
||
12 | |||
13 | int sorted, triangulate, plot, debug, nsites, siteidx ; |
||
14 | float xmin, xmax, ymin, ymax ; |
||
15 | Site * sites ; |
||
16 | Freelist sfl ; |
||
17 | |||
18 | int |
||
19 | main(int argc, char *argv[]) |
||
20 | { |
||
21 | int c ; |
||
22 | Site *(*next)() ; |
||
23 | |||
24 | sorted = plot = debug = 0 ; |
||
25 | triangulate = 0; |
||
26 | |||
27 | freeinit(&sfl, sizeof(Site)) ; |
||
28 | readsites() ; |
||
29 | next = nextone ; |
||
30 | siteidx = 0 ; |
||
31 | geominit() ; |
||
32 | if (plot) |
||
33 | { |
||
34 | plotinit() ; |
||
35 | } |
||
36 | voronoi(next) ; |
||
37 | return (0) ; |
||
38 | } |
||
39 | |||
40 | /*** sort sites on y, then x, coord ***/ |
||
41 | |||
42 | int |
||
43 | scomp(const void * vs1, const void * vs2) |
||
44 | { |
||
45 | Point * s1 = (Point *)vs1 ; |
||
46 | Point * s2 = (Point *)vs2 ; |
||
47 | |||
48 | if (s1->y < s2->y) |
||
49 | { |
||
50 | return (-1) ; |
||
51 | } |
||
52 | if (s1->y > s2->y) |
||
53 | { |
||
54 | return (1) ; |
||
55 | } |
||
56 | if (s1->x < s2->x) |
||
57 | { |
||
58 | return (-1) ; |
||
59 | } |
||
60 | if (s1->x > s2->x) |
||
61 | { |
||
62 | return (1) ; |
||
63 | } |
||
64 | return (0) ; |
||
65 | } |
||
66 | |||
67 | /*** return a single in-storage site ***/ |
||
68 | |||
69 | Site * |
||
70 | nextone(void) |
||
71 | { |
||
72 | Site * s ; |
||
73 | |||
74 | if (siteidx < nsites) |
||
75 | { |
||
76 | s = &sites[siteidx++]; |
||
77 | return (s) ; |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | return ((Site *)NULL) ; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | /*** read all sites, sort, and compute xmin, xmax, ymin, ymax ***/ |
||
86 | |||
87 | void |
||
88 | readsites(void) |
||
89 | { |
||
90 | int i ; |
||
91 | char *s = getenv("wims_exec_parm"); |
||
92 | |||
93 | if (!s || !*s) exit(0); /* nothing to do */ |
||
94 | |||
95 | while (isspace(*s)) s++; |
||
96 | if (*s == '-' && s[1] == 't') |
||
97 | { |
||
98 | s += 2; triangulate = 1; |
||
99 | while (isspace(*s)) s++; |
||
100 | } |
||
101 | |||
102 | nsites = 0 ; |
||
103 | sites = (Site *) myalloc(4000 * sizeof(Site)); |
||
104 | while (sscanf(s, "%f %f", &sites[nsites].coord.x, |
||
105 | &sites[nsites].coord.y) !=EOF) |
||
106 | { |
||
107 | sites[nsites].sitenbr = nsites ; |
||
108 | sites[nsites++].refcnt = 0 ; |
||
109 | if (nsites % 4000 == 0) |
||
110 | sites = (Site *) |
||
111 | realloc(sites,(nsites+4000)*sizeof(Site)); |
||
112 | s = strchr(s, '\n'); |
||
113 | if (!s++) break; |
||
114 | } |
||
115 | |||
116 | qsort((void *)sites, nsites, sizeof(Site), scomp) ; |
||
117 | xmin = sites[0].coord.x ; |
||
118 | xmax = sites[0].coord.x ; |
||
119 | for (i = 1 ; i < nsites ; ++i) |
||
120 | { |
||
121 | if(sites[i].coord.x < xmin) |
||
122 | { |
||
123 | xmin = sites[i].coord.x ; |
||
124 | } |
||
125 | if (sites[i].coord.x > xmax) |
||
126 | { |
||
127 | xmax = sites[i].coord.x ; |
||
128 | } |
||
129 | } |
||
130 | ymin = sites[0].coord.y ; |
||
131 | ymax = sites[nsites-1].coord.y ; |
||
132 | } |