13 |
|
#include "random.h" |
14 |
|
#include "mgflib/parser.h" |
15 |
|
|
16 |
< |
#define MX(v) (int)(((1<<14)-1)*(v)[(proj_axis+1)%3]) |
17 |
< |
#define MY(v) (int)(((1<<14)-1)*(v)[(proj_axis+2)%3]) |
16 |
> |
#define MSIZE ((1<<14)-1) |
17 |
> |
#define MX(v) (int)(MSIZE*(v)[(proj_axis+1)%3]) |
18 |
> |
#define MY(v) (int)(MSIZE*(v)[(proj_axis+2)%3]) |
19 |
|
|
20 |
+ |
#ifdef DCL_ATOF |
21 |
+ |
extern double atof(); |
22 |
+ |
#endif |
23 |
+ |
|
24 |
|
int r_face(); |
25 |
|
int proj_axis; |
26 |
|
double limit[3][2]; |
27 |
|
int layer; |
28 |
+ |
long rthresh = 1; |
29 |
|
|
30 |
|
extern int mg_nqcdivs; |
31 |
|
|
43 |
|
mg_nqcdivs = 3; /* reduce object subdivision */ |
44 |
|
mg_init(); /* initialize the parser */ |
45 |
|
/* get arguments */ |
46 |
+ |
if (argc > 9 && !strcmp(argv[1], "-t")) { |
47 |
+ |
rthresh = atof(argv[2])*MSIZE + 0.5; |
48 |
+ |
rthresh *= rthresh; |
49 |
+ |
argv += 2; |
50 |
+ |
argc -= 2; |
51 |
+ |
} |
52 |
|
if (argc < 8 || (proj_axis = argv[1][0]-'x') < 0 || proj_axis > 2) |
53 |
|
goto userr; |
54 |
|
limit[0][0] = atof(argv[2]); limit[0][1] = atof(argv[3]); |
68 |
|
mdone(); /* close output */ |
69 |
|
exit(0); |
70 |
|
userr: |
71 |
< |
fprintf(stderr, "Usage: %s {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n", |
72 |
< |
argv[0]); |
71 |
> |
fputs("Usage: mgf2meta [-t thresh] {x|y|z} xmin xmax ymin ymax zmin zmax [file.mgf] ..\n", |
72 |
> |
stderr); |
73 |
|
exit(1); |
74 |
|
} |
75 |
|
|
114 |
|
#define hash(mx1,my1,mx2,my2) ((long)(mx1)<<15 ^ (long)(my1)<<10 ^ \ |
115 |
|
(long)(mx2)<<5 ^ (long)(my2)) |
116 |
|
|
105 |
– |
#define RANDMASK ((1L<<14)-1) |
117 |
|
|
107 |
– |
|
118 |
|
newlayer() /* start a new layer */ |
119 |
|
{ |
120 |
|
#ifdef BSD |
146 |
|
hshtab[h][0] = v1x; hshtab[h][1] = v1y; |
147 |
|
hshtab[h][2] = v2x; hshtab[h][3] = v2y; |
148 |
|
if ((long)(v2x-v1x)*(v2x-v1x) + (long)(v2y-v1y)*(v2y-v1y) |
149 |
< |
<= (random()&RANDMASK)) |
149 |
> |
<= random() % rthresh) |
150 |
|
return(0); |
151 |
|
mline(v1x, v1y, layer/4, 0, layer%4); |
152 |
|
mdraw(v2x, v2y); |