10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
#include <math.h> |
13 |
+ |
#include "random.h" |
14 |
|
#include "mgflib/parser.h" |
15 |
|
|
16 |
|
#define MX(v) (int)(((1<<14)-1)*(v)[(proj_axis+1)%3]) |
19 |
|
int r_face(); |
20 |
|
int proj_axis; |
21 |
|
double limit[3][2]; |
22 |
+ |
int layer; |
23 |
|
|
24 |
|
extern int mg_nqcdivs; |
25 |
|
|
46 |
|
if (argc == 8) { /* convert stdin */ |
47 |
|
if (mg_load(NULL) != MG_OK) |
48 |
|
exit(1); |
47 |
– |
mendpage(); |
49 |
|
} else /* convert each file */ |
50 |
|
for (i = 8; i < argc; i++) { |
51 |
|
if (mg_load(argv[i]) != MG_OK) |
52 |
|
exit(1); |
53 |
< |
mendpage(); |
53 |
> |
newlayer(); |
54 |
|
} |
55 |
+ |
mendpage(); /* print page */ |
56 |
|
mdone(); /* close output */ |
57 |
|
exit(0); |
58 |
|
userr: |
71 |
|
register int i, j; |
72 |
|
register C_VERTEX *cv; |
73 |
|
FVECT v1, v2, vo; |
72 |
– |
int newline = 1; |
74 |
|
|
75 |
|
if (ac < 4) |
76 |
|
return(MG_EARGC); |
88 |
|
v2[j] = (v2[j] - limit[j][0])/(limit[j][1]-limit[j][0]); |
89 |
|
VCOPY(v1, vo); |
90 |
|
VCOPY(vo, v2); |
91 |
< |
if (clip(v1, v2, bbmin, bbmax)) { |
92 |
< |
mline(MX(v1), MY(v1), 0, 0, 0); |
92 |
< |
mdraw(MX(v2), MY(v2)); |
93 |
< |
} |
91 |
> |
if (clip(v1, v2, bbmin, bbmax)) |
92 |
> |
doline(MX(v1), MY(v1), MX(v2), MY(v2)); |
93 |
|
} |
94 |
|
return(MG_OK); |
95 |
+ |
} |
96 |
+ |
|
97 |
+ |
|
98 |
+ |
#define HTBLSIZ 16381 /* prime hash table size */ |
99 |
+ |
|
100 |
+ |
short hshtab[HTBLSIZ][4]; /* done line segments */ |
101 |
+ |
|
102 |
+ |
#define hash(mx1,my1,mx2,my2) ((long)(mx1)<<15 ^ (long)(my1)<<10 ^ \ |
103 |
+ |
(long)(mx2)<<5 ^ (long)(my2)) |
104 |
+ |
|
105 |
+ |
#define RANDMASK ((1L<<14)-1) |
106 |
+ |
|
107 |
+ |
|
108 |
+ |
newlayer() /* start a new layer */ |
109 |
+ |
{ |
110 |
+ |
#ifdef BSD |
111 |
+ |
bzero((char *)hshtab, sizeof(hshtab)); |
112 |
+ |
#else |
113 |
+ |
(void)memset((char *)hshtab, 0, sizeof(hshtab)); |
114 |
+ |
#endif |
115 |
+ |
if (++layer >= 16) { |
116 |
+ |
mendpage(); |
117 |
+ |
layer = 0; |
118 |
+ |
} |
119 |
+ |
} |
120 |
+ |
|
121 |
+ |
|
122 |
+ |
int |
123 |
+ |
doline(v1x, v1y, v2x, v2y) /* draw line conditionally */ |
124 |
+ |
int v1x, v1y, v2x, v2y; |
125 |
+ |
{ |
126 |
+ |
register int h; |
127 |
+ |
|
128 |
+ |
if (v1x > v2x || (v1x == v2x && v1y > v2y)) { /* sort endpoints */ |
129 |
+ |
h=v1x; v1x=v2x; v2x=h; |
130 |
+ |
h=v1y; v1y=v2y; v2y=h; |
131 |
+ |
} |
132 |
+ |
h = hash(v1x, v1y, v2x, v2y) % HTBLSIZ; |
133 |
+ |
if (hshtab[h][0] == v1x && hshtab[h][1] == v1y && |
134 |
+ |
hshtab[h][2] == v2x && hshtab[h][3] == v2y) |
135 |
+ |
return(0); |
136 |
+ |
hshtab[h][0] = v1x; hshtab[h][1] = v1y; |
137 |
+ |
hshtab[h][2] = v2x; hshtab[h][3] = v2y; |
138 |
+ |
if ((long)(v2x-v1x)*(v2x-v1x) + (long)(v2y-v1y)*(v2y-v1y) |
139 |
+ |
<= (random()&RANDMASK)) |
140 |
+ |
return(0); |
141 |
+ |
mline(v1x, v1y, layer/4, 0, layer%4); |
142 |
+ |
mdraw(v2x, v2y); |
143 |
+ |
return(1); |
144 |
|
} |