-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleylines-cli.js
More file actions
executable file
·208 lines (194 loc) · 5.29 KB
/
leylines-cli.js
File metadata and controls
executable file
·208 lines (194 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/env node
// import modules
import yargs from 'yargs';
import { points, grid, fibonacci } from 'leylines-geodesy';
import { geogrid } from 'leylines-geodesy';
import { greatcircles, circle } from 'leylines-geodesy';
import { calculatePlatonic } from 'leylines-geodesy';
import { createCzmlHeader } from 'leylines-geodesy';
import fs from 'fs';
import Table from 'table';
const table = Table.table;
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const allpoints = require('./points.json');
// parse command line arguments
const argv = yargs
.command('points', 'calculations with all points')
.command('fiboncci', 'calculations of grid with fibonacci')
.command('grid', 'calculation of a grid', {
grid: {
alias: 'g',
description: 'grid in degrees',
demand: true
}
})
.command('geogrid', 'calculation of a grid', {
grid: {
alias: 'g',
description: 'grid in degrees',
demand: true
}
})
.command('beckerhagens', 'calculate beckerhagens')
.command('cube', 'calculate cube')
.command('dodecahedron', 'calculate dodecahedron')
.command('icosahedron', 'calculate icosahedron')
.command('octahedron', 'calculate octahedron')
.command('tetrahedron', 'calculate tetrahedron')
.command('greatcircles', 'calculate big circles')
.command('circle', 'calculate circle of 3 points', {
midpoint: {
alias: 'mp',
description: 'midpoint',
demand: true
},
mode: {
description: 'mode',
demand: true,
default: "ellipsoidal"
},
showcalc: {
alias: 'sc',
description: 'show calculation',
demand: false
}
})
.options({
startpoint: {
description: 'startpoint of calculation',
alias: 'sp',
demandOption: true
},
destinationpoint: {
description: 'destinationpoint of calculation',
alias: 'dp',
},
bearing: {
description: 'bearing',
alias: 'b',
},
distanceconditions: {
description: 'show grids depending on distance to camera',
alias: 'dc',
type: 'boolean',
default: false,
}
})
.usage('Usage: $0 <command> [options]')
.help('h')
.alias('help', 'h')
.demand(1, "You must provide a valid command")
.argv;
var command = process.argv[2]
var args = process.argv.slice(3);
var sp = argv.startpoint;
var dp = argv.destinationpoint;
var mp = argv.midpoint;
var calc = argv.showcalc;
var mode = argv.mode;
var b = argv.bearing;
var g = argv.grid;
var dc = argv.distanceconditions;
if (!dp && !b) {
console.log("Either destinaionpoint or rhumblebearing must be defined");
process.exit(1)
} else if (dp && b && command != "geogrid") {
console.log("destinaionpoint and bearing are defined");
console.log("taking destinaionpoint for calculations");
}
// set variables
var path = process.cwd();
var czml = [];
var filename;
czml.push(createCzmlHeader());
if (['geogrid'].includes(command)) {
filename = "geodesic-" + command + "-" + sp + "-" + dp;
if (b) {
filename += "-" + b;
}
switch(command) {
case 'geogrid':
filename += "-" + g
var result = geogrid(allpoints, sp, dp, b, g, dc);
czml = czml.concat(result);
break;
}
filename += ".czml";
} else if (['points', 'grid', 'fibonacci'].includes(command)) {
filename = "loxodrome-" + command + "-" + sp;
if (!b) {
filename += "-" + dp
} else {
filename += "-" + b;
}
switch(command) {
case 'point':
var result = points(allpoints, sp, dp, b);
czml = czml.concat(result);
break;
case 'grid':
filename += "-" + g
var result = grid(allpoints, sp, dp, b, g, dc);
czml = czml.concat(result);
break;
case 'fibonacci':
var result = fibonacci(allpoints, sp, dp, b, g, dc);
czml = czml.concat(result);
break;
}
filename += ".czml";
} else if (['greatcircles', 'circle'].includes(command)) {
filename = command + "-" + sp;
if (!b) {
filename += "-" + dp
} else {
filename += "-" + b;
}
switch(command) {
case 'greatcircles':
var result = greatcircles(allpoints, sp, dp);
czml = czml.concat(result);
break;
case 'circle':
filename += "-" + mp;
if (mode == "ellipsoidal") {
filename += "-ellipsoidal";
} else {
filename += "-spherical";
}
var result = circle(allpoints, sp, dp, mp, mode, calc);
czml = czml.concat(result);
break;
}
filename += ".czml";
} else if (['cube', 'dodecahedron', 'beckerhagens', 'icosahedron', 'tetrahedron', 'octahedron'].includes(command)) {
filename = "platonic-" + command + "-" + sp;
if (!b) {
filename += "-" + dp
} else {
filename += "-" + b;
}
var result = calculatePlatonic(allpoints, sp, dp, command);
czml = czml.concat(result);
filename += ".czml";
} else {
yargs.showHelp();
process.exit(1)
}
/*
var tabledata = [
[ "Command", command ],
[ "Startpoint", sp + " (" + allpoints[sp]['coords'] + ")" ],
[ "Endpoint", dp + " (" + allpoints[dp]['coords'] + ")" ],
[ "Bearing", b ],
[ "Grid", g ],
[ "Show Distance Conditions", dc ],
[ "Filename", filename ]
];
var output = table(tabledata);
console.log(output);
*/
fs.writeFile(path + "/results/" + filename, JSON.stringify(czml), function(err){
if (err) throw err;
});