ballistics-engine 0.36.3 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +201 -0
- package/README.md +120 -1097
- package/ballistics_engine.d.ts +0 -70
- package/ballistics_engine.js +8 -753
- package/ballistics_engine_bg.js +655 -0
- package/ballistics_engine_bg.wasm +0 -0
- package/package.json +14 -6
package/ballistics_engine.js
CHANGED
|
@@ -1,754 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./ballistics_engine.d.ts" */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
obj.__wbg_ptr = ptr;
|
|
11
|
-
CalculatorFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
__destroy_into_raw() {
|
|
15
|
-
const ptr = this.__wbg_ptr;
|
|
16
|
-
this.__wbg_ptr = 0;
|
|
17
|
-
CalculatorFinalization.unregister(this);
|
|
18
|
-
return ptr;
|
|
19
|
-
}
|
|
20
|
-
free() {
|
|
21
|
-
const ptr = this.__destroy_into_raw();
|
|
22
|
-
wasm.__wbg_calculator_free(ptr, 0);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Add a downrange wind segment: `speed_mph` from `direction_deg`
|
|
26
|
-
* (wind-FROM: 0 = headwind, 90 = from the right) out to `until_yards`.
|
|
27
|
-
* Each segment applies from the previous boundary to `until_yards`; wind is
|
|
28
|
-
* zero beyond the last segment. When any segment is added it overrides the
|
|
29
|
-
* scalar `setWind` value. Repeatable.
|
|
30
|
-
* @param {number} speed_mph
|
|
31
|
-
* @param {number} direction_deg
|
|
32
|
-
* @param {number} until_yards
|
|
33
|
-
* @returns {Calculator}
|
|
34
|
-
*/
|
|
35
|
-
addWindSegment(speed_mph, direction_deg, until_yards) {
|
|
36
|
-
const ptr = this.__destroy_into_raw();
|
|
37
|
-
const ret = wasm.calculator_addWindSegment(ptr, speed_mph, direction_deg, until_yards);
|
|
38
|
-
return Calculator.__wrap(ret);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Calculate trajectory and return result as JavaScript object
|
|
42
|
-
* Returns: { range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }
|
|
43
|
-
* @param {number} range_yards
|
|
44
|
-
* @returns {any}
|
|
45
|
-
*/
|
|
46
|
-
calculateTrajectory(range_yards) {
|
|
47
|
-
const ret = wasm.calculator_calculateTrajectory(this.__wbg_ptr, range_yards);
|
|
48
|
-
if (ret[2]) {
|
|
49
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
50
|
-
}
|
|
51
|
-
return takeFromExternrefTable0(ret[0]);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Remove all downrange wind segments (reverts to the scalar `setWind`).
|
|
55
|
-
* @returns {Calculator}
|
|
56
|
-
*/
|
|
57
|
-
clearWindSegments() {
|
|
58
|
-
const ptr = this.__destroy_into_raw();
|
|
59
|
-
const ret = wasm.calculator_clearWindSegments(ptr);
|
|
60
|
-
return Calculator.__wrap(ret);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* @param {boolean} enabled
|
|
64
|
-
* @param {number | null} [latitude]
|
|
65
|
-
* @returns {Calculator}
|
|
66
|
-
*/
|
|
67
|
-
enableCoriolis(enabled, latitude) {
|
|
68
|
-
const ptr = this.__destroy_into_raw();
|
|
69
|
-
const ret = wasm.calculator_enableCoriolis(ptr, enabled, !isLikeNone(latitude), isLikeNone(latitude) ? 0 : latitude);
|
|
70
|
-
return Calculator.__wrap(ret);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* @param {boolean} enabled
|
|
74
|
-
* @param {number | null} [twist_rate]
|
|
75
|
-
* @returns {Calculator}
|
|
76
|
-
*/
|
|
77
|
-
enableSpinDrift(enabled, twist_rate) {
|
|
78
|
-
const ptr = this.__destroy_into_raw();
|
|
79
|
-
const ret = wasm.calculator_enableSpinDrift(ptr, enabled, !isLikeNone(twist_rate), isLikeNone(twist_rate) ? 0 : twist_rate);
|
|
80
|
-
return Calculator.__wrap(ret);
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get full trajectory table as array of points
|
|
84
|
-
* Returns array of: [{ range_yards, drop_inches, windage_inches, velocity_fps, energy_ftlb, time_sec }, ...]
|
|
85
|
-
* @returns {any}
|
|
86
|
-
*/
|
|
87
|
-
getFullTrajectory() {
|
|
88
|
-
const ret = wasm.calculator_getFullTrajectory(this.__wbg_ptr);
|
|
89
|
-
if (ret[2]) {
|
|
90
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
91
|
-
}
|
|
92
|
-
return takeFromExternrefTable0(ret[0]);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Solve all the way to the requested range instead of stopping at ground impact.
|
|
96
|
-
*
|
|
97
|
-
* Without this, `calculateTrajectory(range)` returns the closest point it actually
|
|
98
|
-
* solved, which for a typical .308 is around 516 yd — short of a 1000 yd request, and
|
|
99
|
-
* reported only by the `range_yards` field of the returned object.
|
|
100
|
-
* @param {boolean} ignore
|
|
101
|
-
* @returns {Calculator}
|
|
102
|
-
*/
|
|
103
|
-
ignoreGroundImpact(ignore) {
|
|
104
|
-
const ptr = this.__destroy_into_raw();
|
|
105
|
-
const ret = wasm.calculator_ignoreGroundImpact(ptr, ignore);
|
|
106
|
-
return Calculator.__wrap(ret);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Create a new calculator with default values
|
|
110
|
-
* Defaults: .308 Winchester 168gr at 2700 fps, standard atmosphere
|
|
111
|
-
*/
|
|
112
|
-
constructor() {
|
|
113
|
-
const ret = wasm.calculator_new();
|
|
114
|
-
this.__wbg_ptr = ret;
|
|
115
|
-
CalculatorFinalization.register(this, this.__wbg_ptr, this);
|
|
116
|
-
return this;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* @param {number} altitude_ft
|
|
120
|
-
* @returns {Calculator}
|
|
121
|
-
*/
|
|
122
|
-
setAltitude(altitude_ft) {
|
|
123
|
-
const ptr = this.__destroy_into_raw();
|
|
124
|
-
const ret = wasm.calculator_setAltitude(ptr, altitude_ft);
|
|
125
|
-
return Calculator.__wrap(ret);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* @param {number} bc
|
|
129
|
-
* @returns {Calculator}
|
|
130
|
-
*/
|
|
131
|
-
setBC(bc) {
|
|
132
|
-
const ptr = this.__destroy_into_raw();
|
|
133
|
-
const ret = wasm.calculator_setBC(ptr, bc);
|
|
134
|
-
return Calculator.__wrap(ret);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Height of the bore above the ground, in inches (default 60 = 5 ft). The solve stops
|
|
138
|
-
* when the projectile falls this far below the muzzle, so raising it pushes the
|
|
139
|
-
* ground-impact cutoff further downrange. Use [`Self::ignore_ground_impact`] to remove
|
|
140
|
-
* the cutoff entirely rather than setting an implausible height.
|
|
141
|
-
* @param {number} height_inches
|
|
142
|
-
* @returns {Calculator}
|
|
143
|
-
*/
|
|
144
|
-
setBoreHeight(height_inches) {
|
|
145
|
-
const ptr = this.__destroy_into_raw();
|
|
146
|
-
const ret = wasm.calculator_setBoreHeight(ptr, height_inches);
|
|
147
|
-
return Calculator.__wrap(ret);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* @param {number} diameter_inches
|
|
151
|
-
* @returns {Calculator}
|
|
152
|
-
*/
|
|
153
|
-
setDiameter(diameter_inches) {
|
|
154
|
-
const ptr = this.__destroy_into_raw();
|
|
155
|
-
const ret = wasm.calculator_setDiameter(ptr, diameter_inches);
|
|
156
|
-
return Calculator.__wrap(ret);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* @param {string} model
|
|
160
|
-
* @returns {Calculator}
|
|
161
|
-
*/
|
|
162
|
-
setDragModel(model) {
|
|
163
|
-
const ptr = this.__destroy_into_raw();
|
|
164
|
-
const ptr0 = passStringToWasm0(model, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
165
|
-
const len0 = WASM_VECTOR_LEN;
|
|
166
|
-
const ret = wasm.calculator_setDragModel(ptr, ptr0, len0);
|
|
167
|
-
return Calculator.__wrap(ret);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* @param {number} humidity
|
|
171
|
-
* @returns {Calculator}
|
|
172
|
-
*/
|
|
173
|
-
setHumidity(humidity) {
|
|
174
|
-
const ptr = this.__destroy_into_raw();
|
|
175
|
-
const ret = wasm.calculator_setHumidity(ptr, humidity);
|
|
176
|
-
return Calculator.__wrap(ret);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* @param {number} mass_grains
|
|
180
|
-
* @returns {Calculator}
|
|
181
|
-
*/
|
|
182
|
-
setMass(mass_grains) {
|
|
183
|
-
const ptr = this.__destroy_into_raw();
|
|
184
|
-
const ret = wasm.calculator_setMass(ptr, mass_grains);
|
|
185
|
-
return Calculator.__wrap(ret);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* @param {number} range_yards
|
|
189
|
-
* @returns {Calculator}
|
|
190
|
-
*/
|
|
191
|
-
setMaxRange(range_yards) {
|
|
192
|
-
const ptr = this.__destroy_into_raw();
|
|
193
|
-
const ret = wasm.calculator_setMaxRange(ptr, range_yards);
|
|
194
|
-
return Calculator.__wrap(ret);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* @param {number} pressure_inhg
|
|
198
|
-
* @returns {Calculator}
|
|
199
|
-
*/
|
|
200
|
-
setPressure(pressure_inhg) {
|
|
201
|
-
const ptr = this.__destroy_into_raw();
|
|
202
|
-
const ret = wasm.calculator_setPressure(ptr, pressure_inhg);
|
|
203
|
-
return Calculator.__wrap(ret);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* MBA-1368: compass bearing of the shot (degrees, 0 = north, 90 = east) —
|
|
207
|
-
* required by `setWindReference("compass")`; also feeds Coriolis when enabled.
|
|
208
|
-
* @param {number} bearing_deg
|
|
209
|
-
* @returns {Calculator}
|
|
210
|
-
*/
|
|
211
|
-
setShotDirection(bearing_deg) {
|
|
212
|
-
const ptr = this.__destroy_into_raw();
|
|
213
|
-
const ret = wasm.calculator_setShotDirection(ptr, bearing_deg);
|
|
214
|
-
return Calculator.__wrap(ret);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* @param {number} height_inches
|
|
218
|
-
* @returns {Calculator}
|
|
219
|
-
*/
|
|
220
|
-
setSightHeight(height_inches) {
|
|
221
|
-
const ptr = this.__destroy_into_raw();
|
|
222
|
-
const ret = wasm.calculator_setSightHeight(ptr, height_inches);
|
|
223
|
-
return Calculator.__wrap(ret);
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* @param {number} temp_f
|
|
227
|
-
* @returns {Calculator}
|
|
228
|
-
*/
|
|
229
|
-
setTemperature(temp_f) {
|
|
230
|
-
const ptr = this.__destroy_into_raw();
|
|
231
|
-
const ret = wasm.calculator_setTemperature(ptr, temp_f);
|
|
232
|
-
return Calculator.__wrap(ret);
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* @param {number} velocity_fps
|
|
236
|
-
* @returns {Calculator}
|
|
237
|
-
*/
|
|
238
|
-
setVelocity(velocity_fps) {
|
|
239
|
-
const ptr = this.__destroy_into_raw();
|
|
240
|
-
const ret = wasm.calculator_setVelocity(ptr, velocity_fps);
|
|
241
|
-
return Calculator.__wrap(ret);
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* @param {number} speed_mph
|
|
245
|
-
* @param {number} direction_deg
|
|
246
|
-
* @returns {Calculator}
|
|
247
|
-
*/
|
|
248
|
-
setWind(speed_mph, direction_deg) {
|
|
249
|
-
const ptr = this.__destroy_into_raw();
|
|
250
|
-
const ret = wasm.calculator_setWind(ptr, speed_mph, direction_deg);
|
|
251
|
-
return Calculator.__wrap(ret);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* MBA-1368: choose the wind entry frame — "shooter" (default; wind-FROM angles
|
|
255
|
-
* relative to the line of fire) or "compass" (earth-fixed bearings, 0 = north,
|
|
256
|
-
* covering `setWind` AND every `addWindSegment` direction, re-referenced against
|
|
257
|
-
* the shot azimuth at solve time). Compass mode requires `setShotDirection`;
|
|
258
|
-
* invalid values surface when the command runs. Additive method — no existing
|
|
259
|
-
* signature changed.
|
|
260
|
-
* @param {string} mode
|
|
261
|
-
* @returns {Calculator}
|
|
262
|
-
*/
|
|
263
|
-
setWindReference(mode) {
|
|
264
|
-
const ptr = this.__destroy_into_raw();
|
|
265
|
-
const ptr0 = passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
266
|
-
const len0 = WASM_VECTOR_LEN;
|
|
267
|
-
const ret = wasm.calculator_setWindReference(ptr, ptr0, len0);
|
|
268
|
-
return Calculator.__wrap(ret);
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* @param {number} range_yards
|
|
272
|
-
* @returns {Calculator}
|
|
273
|
-
*/
|
|
274
|
-
setZeroRange(range_yards) {
|
|
275
|
-
const ptr = this.__destroy_into_raw();
|
|
276
|
-
const ret = wasm.calculator_setZeroRange(ptr, range_yards);
|
|
277
|
-
return Calculator.__wrap(ret);
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (Symbol.dispose) Calculator.prototype[Symbol.dispose] = Calculator.prototype.free;
|
|
281
|
-
|
|
282
|
-
export class WasmBallistics {
|
|
283
|
-
__destroy_into_raw() {
|
|
284
|
-
const ptr = this.__wbg_ptr;
|
|
285
|
-
this.__wbg_ptr = 0;
|
|
286
|
-
WasmBallisticsFinalization.unregister(this);
|
|
287
|
-
return ptr;
|
|
288
|
-
}
|
|
289
|
-
free() {
|
|
290
|
-
const ptr = this.__destroy_into_raw();
|
|
291
|
-
wasm.__wbg_wasmballistics_free(ptr, 0);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Unload any custom drag table previously installed via [`Self::load_drag_table`],
|
|
295
|
-
* reverting every subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run to the
|
|
296
|
-
* standard G-model + BC drag (the `-b`/`--bc` value with the selected G1/G7 curve).
|
|
297
|
-
*
|
|
298
|
-
* The inverse of `loadDragTable`. It lets a single engine instance alternate between a
|
|
299
|
-
* measured-curve (CDM) solve and a plain G7-BC solve without constructing a second
|
|
300
|
-
* instance: `load → solve CDM → clear → solve G7`, with the G7 half uncontaminated —
|
|
301
|
-
* the same load/clear pattern `clearWindSegments` provides for segmented wind.
|
|
302
|
-
*
|
|
303
|
-
* Returns `true` if a table was loaded (and is now cleared), `false` if none was loaded
|
|
304
|
-
* (a harmless no-op). Idempotent.
|
|
305
|
-
* @returns {boolean}
|
|
306
|
-
*/
|
|
307
|
-
clearDragTable() {
|
|
308
|
-
const ret = wasm.wasmballistics_clearDragTable(this.__wbg_ptr);
|
|
309
|
-
return ret !== 0;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Report whether a BC5D table is currently loaded.
|
|
313
|
-
* @returns {boolean}
|
|
314
|
-
*/
|
|
315
|
-
hasBc5dTable() {
|
|
316
|
-
const ret = wasm.wasmballistics_hasBc5dTable(this.__wbg_ptr);
|
|
317
|
-
return ret !== 0;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Report whether a custom drag table is currently loaded.
|
|
321
|
-
* @returns {boolean}
|
|
322
|
-
*/
|
|
323
|
-
hasDragTable() {
|
|
324
|
-
const ret = wasm.wasmballistics_hasDragTable(this.__wbg_ptr);
|
|
325
|
-
return ret !== 0;
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Load a BC5D correction table from the raw bytes of a `bc5d_<caliber>.bin`
|
|
329
|
-
* file. The host (browser `fetch()` or Node `fs`/`fetch`) is responsible
|
|
330
|
-
* for retrieving the file — WASM has no filesystem or network — and passes
|
|
331
|
-
* the bytes here.
|
|
332
|
-
*
|
|
333
|
-
* Once loaded, any `trajectory` run that includes `--use-bc-segments` will
|
|
334
|
-
* apply velocity-dependent BC segments synthesized from this table. Load a
|
|
335
|
-
* table matching the bullet's caliber (e.g. `bc5d_308.bin` for a .308).
|
|
336
|
-
*
|
|
337
|
-
* Returns a short human-readable summary of the loaded table. Replaces any
|
|
338
|
-
* previously loaded table.
|
|
339
|
-
* @param {Uint8Array} bytes
|
|
340
|
-
* @returns {string}
|
|
341
|
-
*/
|
|
342
|
-
loadBc5dTable(bytes) {
|
|
343
|
-
let deferred3_0;
|
|
344
|
-
let deferred3_1;
|
|
345
|
-
try {
|
|
346
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
347
|
-
const len0 = WASM_VECTOR_LEN;
|
|
348
|
-
const ret = wasm.wasmballistics_loadBc5dTable(this.__wbg_ptr, ptr0, len0);
|
|
349
|
-
var ptr2 = ret[0];
|
|
350
|
-
var len2 = ret[1];
|
|
351
|
-
if (ret[3]) {
|
|
352
|
-
ptr2 = 0; len2 = 0;
|
|
353
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
354
|
-
}
|
|
355
|
-
deferred3_0 = ptr2;
|
|
356
|
-
deferred3_1 = len2;
|
|
357
|
-
return getStringFromWasm0(ptr2, len2);
|
|
358
|
-
} finally {
|
|
359
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Load a custom Mach:Cd drag table (MBA-1328) — a measured or manufacturer-published
|
|
364
|
-
* drag curve (Hornady CDM data, a Lapua/Doppler-radar-derived deck, or your own) — from
|
|
365
|
-
* the raw bytes of a CSV file. The host (browser `fetch()` or Node `fs`/`fetch`) is
|
|
366
|
-
* responsible for retrieving the file — WASM has no filesystem or network — and passes
|
|
367
|
-
* the bytes here, mirroring [`Self::load_bc5d_table`].
|
|
368
|
-
*
|
|
369
|
-
* The bytes must be valid UTF-8 CSV text; parsing is delegated to
|
|
370
|
-
* [`crate::drag::DragTable::from_csv_str`] — the SAME parser native `--drag-table`
|
|
371
|
-
* uses — so the accepted format is identical: two columns `mach,cd` per line, blank
|
|
372
|
-
* lines and `#` comments ignored, a single leading textual header row tolerated, Mach
|
|
373
|
-
* strictly ascending with at least 2 points, Cd finite and > 0.
|
|
374
|
-
*
|
|
375
|
-
* Once loaded, EVERY subsequent `trajectory`, `zero`, `lead`, and `monte-carlo` run
|
|
376
|
-
* applies the table automatically — no `--use-*` gate flag is needed (unlike a loaded
|
|
377
|
-
* BC5D table, which only takes effect with `--use-bc-segments`). A loaded table is a
|
|
378
|
-
* full physical substitute for the G-model + BC (see `calculate_drag_coefficient`):
|
|
379
|
-
* `-b`/`--bc` may still be supplied but is ignored for drag once a table is active
|
|
380
|
-
* (matching the native `--drag-table` CLI semantics documented in CLI_USAGE.md).
|
|
381
|
-
*
|
|
382
|
-
* Returns a short human-readable summary of the loaded table (point count + Mach
|
|
383
|
-
* range). Replaces any previously loaded table.
|
|
384
|
-
*
|
|
385
|
-
* MBA-1409: also accepts `.drg` vendor drag-curve text (the same format the native
|
|
386
|
-
* `--drag-table` CLI accepts by `.drg` file extension) as a fallback. WASM has no
|
|
387
|
-
* filesystem and thus no extension to dispatch on, so the bytes are tried as CSV first
|
|
388
|
-
* (exactly as before this change); only on CSV failure, if the text
|
|
389
|
-
* [`crate::drag_file::looks_like_drg`], it is retried through
|
|
390
|
-
* [`crate::drag_file::parse_drg`]. If both fail, the returned error names both formats.
|
|
391
|
-
* @param {Uint8Array} bytes
|
|
392
|
-
* @returns {string}
|
|
393
|
-
*/
|
|
394
|
-
loadDragTable(bytes) {
|
|
395
|
-
let deferred3_0;
|
|
396
|
-
let deferred3_1;
|
|
397
|
-
try {
|
|
398
|
-
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
399
|
-
const len0 = WASM_VECTOR_LEN;
|
|
400
|
-
const ret = wasm.wasmballistics_loadDragTable(this.__wbg_ptr, ptr0, len0);
|
|
401
|
-
var ptr2 = ret[0];
|
|
402
|
-
var len2 = ret[1];
|
|
403
|
-
if (ret[3]) {
|
|
404
|
-
ptr2 = 0; len2 = 0;
|
|
405
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
406
|
-
}
|
|
407
|
-
deferred3_0 = ptr2;
|
|
408
|
-
deferred3_1 = len2;
|
|
409
|
-
return getStringFromWasm0(ptr2, len2);
|
|
410
|
-
} finally {
|
|
411
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
constructor() {
|
|
415
|
-
const ret = wasm.wasmballistics_new();
|
|
416
|
-
this.__wbg_ptr = ret;
|
|
417
|
-
WasmBallisticsFinalization.register(this, this.__wbg_ptr, this);
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Run a command and return the output
|
|
422
|
-
* @param {string} command
|
|
423
|
-
* @returns {string}
|
|
424
|
-
*/
|
|
425
|
-
runCommand(command) {
|
|
426
|
-
let deferred3_0;
|
|
427
|
-
let deferred3_1;
|
|
428
|
-
try {
|
|
429
|
-
const ptr0 = passStringToWasm0(command, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
430
|
-
const len0 = WASM_VECTOR_LEN;
|
|
431
|
-
const ret = wasm.wasmballistics_runCommand(this.__wbg_ptr, ptr0, len0);
|
|
432
|
-
var ptr2 = ret[0];
|
|
433
|
-
var len2 = ret[1];
|
|
434
|
-
if (ret[3]) {
|
|
435
|
-
ptr2 = 0; len2 = 0;
|
|
436
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
437
|
-
}
|
|
438
|
-
deferred3_0 = ptr2;
|
|
439
|
-
deferred3_1 = len2;
|
|
440
|
-
return getStringFromWasm0(ptr2, len2);
|
|
441
|
-
} finally {
|
|
442
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
if (Symbol.dispose) WasmBallistics.prototype[Symbol.dispose] = WasmBallistics.prototype.free;
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* The engine's versioned JSON command bridge, as one JavaScript function.
|
|
450
|
-
*
|
|
451
|
-
* One request envelope in, one response envelope out, both as strings:
|
|
452
|
-
*
|
|
453
|
-
* ```text
|
|
454
|
-
* in: {"api_version":1,"command":"solve","request":{ … }}
|
|
455
|
-
* ok: {"ok":true,"api_version":1,"engine_version":"…","command":"solve","result":{ … }}
|
|
456
|
-
* err: {"ok":false,"api_version":1,"engine_version":"…","error":{"code":"…","message":"…"}}
|
|
457
|
-
* ```
|
|
458
|
-
*
|
|
459
|
-
* This is the module's programmatic surface, deliberately separate from the
|
|
460
|
-
* browser terminal above. The terminal's commands are per-feature gated because a
|
|
461
|
-
* stripped build is a smaller download; the bridge is not gateable that way — it
|
|
462
|
-
* is a single entry point onto every command the build actually contains, and it
|
|
463
|
-
* costs nothing but serde, which is already a core dependency.
|
|
464
|
-
*
|
|
465
|
-
* It is the ONLY route from JavaScript to `corrections.bc5d_table_path` and
|
|
466
|
-
* `atmosphere.pressure_reference`, and the only one that validates
|
|
467
|
-
* `effects.wind_shear_model` against a typed enum rather than silently resolving
|
|
468
|
-
* an unrecognised name to the power law.
|
|
469
|
-
*
|
|
470
|
-
* Failures arrive INSIDE the returned JSON — this never throws. Ask
|
|
471
|
-
* `meta.capabilities` for the command list, which depends on what this build
|
|
472
|
-
* compiled in rather than on what the bridge knows how to dispatch.
|
|
473
|
-
* @param {string} request_json
|
|
474
|
-
* @returns {string}
|
|
475
|
-
*/
|
|
476
|
-
export function bridgeCall(request_json) {
|
|
477
|
-
let deferred2_0;
|
|
478
|
-
let deferred2_1;
|
|
479
|
-
try {
|
|
480
|
-
const ptr0 = passStringToWasm0(request_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
481
|
-
const len0 = WASM_VECTOR_LEN;
|
|
482
|
-
const ret = wasm.bridgeCall(ptr0, len0);
|
|
483
|
-
deferred2_0 = ret[0];
|
|
484
|
-
deferred2_1 = ret[1];
|
|
485
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
486
|
-
} finally {
|
|
487
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
function __wbg_get_imports() {
|
|
491
|
-
const import0 = {
|
|
492
|
-
__proto__: null,
|
|
493
|
-
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
494
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
495
|
-
},
|
|
496
|
-
__wbg_getRandomValues_cc7f052a444bb2ce: function() { return handleError(function (arg0, arg1) {
|
|
497
|
-
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
498
|
-
}, arguments); },
|
|
499
|
-
__wbg_new_32b398fb48b6d94a: function() {
|
|
500
|
-
const ret = new Array();
|
|
501
|
-
return ret;
|
|
502
|
-
},
|
|
503
|
-
__wbg_new_da52cf8fe3429cb2: function() {
|
|
504
|
-
const ret = new Object();
|
|
505
|
-
return ret;
|
|
506
|
-
},
|
|
507
|
-
__wbg_push_d2ae3af0c1217ae6: function(arg0, arg1) {
|
|
508
|
-
const ret = arg0.push(arg1);
|
|
509
|
-
return ret;
|
|
510
|
-
},
|
|
511
|
-
__wbg_set_8535240470bf2500: function() { return handleError(function (arg0, arg1, arg2) {
|
|
512
|
-
const ret = Reflect.set(arg0, arg1, arg2);
|
|
513
|
-
return ret;
|
|
514
|
-
}, arguments); },
|
|
515
|
-
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
516
|
-
// Cast intrinsic for `F64 -> Externref`.
|
|
517
|
-
const ret = arg0;
|
|
518
|
-
return ret;
|
|
519
|
-
},
|
|
520
|
-
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
521
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
522
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
523
|
-
return ret;
|
|
524
|
-
},
|
|
525
|
-
__wbindgen_init_externref_table: function() {
|
|
526
|
-
const table = wasm.__wbindgen_externrefs;
|
|
527
|
-
const offset = table.grow(4);
|
|
528
|
-
table.set(0, undefined);
|
|
529
|
-
table.set(offset + 0, undefined);
|
|
530
|
-
table.set(offset + 1, null);
|
|
531
|
-
table.set(offset + 2, true);
|
|
532
|
-
table.set(offset + 3, false);
|
|
533
|
-
},
|
|
534
|
-
};
|
|
535
|
-
return {
|
|
536
|
-
__proto__: null,
|
|
537
|
-
"./ballistics_engine_bg.js": import0,
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
const CalculatorFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
542
|
-
? { register: () => {}, unregister: () => {} }
|
|
543
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_calculator_free(ptr, 1));
|
|
544
|
-
const WasmBallisticsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
545
|
-
? { register: () => {}, unregister: () => {} }
|
|
546
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_wasmballistics_free(ptr, 1));
|
|
547
|
-
|
|
548
|
-
function addToExternrefTable0(obj) {
|
|
549
|
-
const idx = wasm.__externref_table_alloc();
|
|
550
|
-
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
551
|
-
return idx;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
555
|
-
ptr = ptr >>> 0;
|
|
556
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function getStringFromWasm0(ptr, len) {
|
|
560
|
-
return decodeText(ptr >>> 0, len);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
let cachedUint8ArrayMemory0 = null;
|
|
564
|
-
function getUint8ArrayMemory0() {
|
|
565
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
566
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
567
|
-
}
|
|
568
|
-
return cachedUint8ArrayMemory0;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
function handleError(f, args) {
|
|
572
|
-
try {
|
|
573
|
-
return f.apply(this, args);
|
|
574
|
-
} catch (e) {
|
|
575
|
-
const idx = addToExternrefTable0(e);
|
|
576
|
-
wasm.__wbindgen_exn_store(idx);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
function isLikeNone(x) {
|
|
581
|
-
return x === undefined || x === null;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
585
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
586
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
587
|
-
WASM_VECTOR_LEN = arg.length;
|
|
588
|
-
return ptr;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
592
|
-
if (realloc === undefined) {
|
|
593
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
594
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
595
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
596
|
-
WASM_VECTOR_LEN = buf.length;
|
|
597
|
-
return ptr;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
let len = arg.length;
|
|
601
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
602
|
-
|
|
603
|
-
const mem = getUint8ArrayMemory0();
|
|
604
|
-
|
|
605
|
-
let offset = 0;
|
|
606
|
-
|
|
607
|
-
for (; offset < len; offset++) {
|
|
608
|
-
const code = arg.charCodeAt(offset);
|
|
609
|
-
if (code > 0x7F) break;
|
|
610
|
-
mem[ptr + offset] = code;
|
|
611
|
-
}
|
|
612
|
-
if (offset !== len) {
|
|
613
|
-
if (offset !== 0) {
|
|
614
|
-
arg = arg.slice(offset);
|
|
615
|
-
}
|
|
616
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
617
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
618
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
619
|
-
|
|
620
|
-
offset += ret.written;
|
|
621
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
WASM_VECTOR_LEN = offset;
|
|
625
|
-
return ptr;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function takeFromExternrefTable0(idx) {
|
|
629
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
630
|
-
wasm.__externref_table_dealloc(idx);
|
|
631
|
-
return value;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
635
|
-
cachedTextDecoder.decode();
|
|
636
|
-
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
637
|
-
let numBytesDecoded = 0;
|
|
638
|
-
function decodeText(ptr, len) {
|
|
639
|
-
numBytesDecoded += len;
|
|
640
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
641
|
-
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
642
|
-
cachedTextDecoder.decode();
|
|
643
|
-
numBytesDecoded = len;
|
|
644
|
-
}
|
|
645
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
const cachedTextEncoder = new TextEncoder();
|
|
649
|
-
|
|
650
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
651
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
652
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
653
|
-
view.set(buf);
|
|
654
|
-
return {
|
|
655
|
-
read: arg.length,
|
|
656
|
-
written: buf.length
|
|
657
|
-
};
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
let WASM_VECTOR_LEN = 0;
|
|
662
|
-
|
|
663
|
-
let wasmModule, wasmInstance, wasm;
|
|
664
|
-
function __wbg_finalize_init(instance, module) {
|
|
665
|
-
wasmInstance = instance;
|
|
666
|
-
wasm = instance.exports;
|
|
667
|
-
wasmModule = module;
|
|
668
|
-
cachedUint8ArrayMemory0 = null;
|
|
669
|
-
wasm.__wbindgen_start();
|
|
670
|
-
return wasm;
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
async function __wbg_load(module, imports) {
|
|
674
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
675
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
676
|
-
try {
|
|
677
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
678
|
-
} catch (e) {
|
|
679
|
-
const validResponse = module.ok && expectedResponseType(module.type);
|
|
680
|
-
|
|
681
|
-
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
682
|
-
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
683
|
-
|
|
684
|
-
} else { throw e; }
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
const bytes = await module.arrayBuffer();
|
|
689
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
690
|
-
} else {
|
|
691
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
692
|
-
|
|
693
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
694
|
-
return { instance, module };
|
|
695
|
-
} else {
|
|
696
|
-
return instance;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
function expectedResponseType(type) {
|
|
701
|
-
switch (type) {
|
|
702
|
-
case 'basic': case 'cors': case 'default': return true;
|
|
703
|
-
}
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
function initSync(module) {
|
|
709
|
-
if (wasm !== undefined) return wasm;
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
if (module !== undefined) {
|
|
713
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
714
|
-
({module} = module)
|
|
715
|
-
} else {
|
|
716
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
const imports = __wbg_get_imports();
|
|
721
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
722
|
-
module = new WebAssembly.Module(module);
|
|
723
|
-
}
|
|
724
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
725
|
-
return __wbg_finalize_init(instance, module);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
async function __wbg_init(module_or_path) {
|
|
729
|
-
if (wasm !== undefined) return wasm;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
if (module_or_path !== undefined) {
|
|
733
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
734
|
-
({module_or_path} = module_or_path)
|
|
735
|
-
} else {
|
|
736
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (module_or_path === undefined) {
|
|
741
|
-
module_or_path = new URL('ballistics_engine_bg.wasm', import.meta.url);
|
|
742
|
-
}
|
|
743
|
-
const imports = __wbg_get_imports();
|
|
744
|
-
|
|
745
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
746
|
-
module_or_path = fetch(module_or_path);
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
750
|
-
|
|
751
|
-
return __wbg_finalize_init(instance, module);
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
export { initSync, __wbg_init as default };
|
|
2
|
+
import * as wasm from "./ballistics_engine_bg.wasm";
|
|
3
|
+
import { __wbg_set_wasm } from "./ballistics_engine_bg.js";
|
|
4
|
+
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
6
|
+
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
Calculator, WasmBallistics, bridgeCall
|
|
9
|
+
} from "./ballistics_engine_bg.js";
|